Search in sources :

Example 26 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class Def_Timer method checkArrayDuration.

private void checkArrayDuration(final CompilationTimeStamp timestamp, final IValue duration, final int startDimension) {
    final ArrayDimension dim = dimensions.get(startDimension);
    final boolean arraySizeKnown = !dim.getIsErroneous(timestamp);
    int arraySize = 0;
    if (arraySizeKnown) {
        arraySize = (int) dim.getSize();
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) duration.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (v.getIsErroneous(timestamp)) {
        // error
        return;
    }
    if (v.getValuetype() == Value_type.SEQUENCEOF_VALUE) {
        final SequenceOf_Value value = (SequenceOf_Value) v;
        final int nofComp = value.getNofComponents();
        // Value-list notation.
        if (!value.isIndexed()) {
            if (arraySizeKnown) {
                if (arraySize > nofComp) {
                    duration.getLocation().reportSemanticError("Too few elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                } else if (arraySize < nofComp) {
                    duration.getLocation().reportSemanticError("Too many elements in the default duration of timer array: " + arraySize + " was expected instead of " + nofComp);
                }
            }
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
            }
        } else {
            // Indexed-notation.
            final boolean last_dim = startDimension + 1 >= dimensions.size();
            final Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
            for (int i = 0; i < nofComp; ++i) {
                final IValue array_v = value.getValueByIndex(i);
                if (array_v.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                if (last_dim) {
                    checkSingleDuration(timestamp, array_v);
                } else {
                    checkArrayDuration(timestamp, array_v, startDimension + 1);
                }
                final IValue array_index = value.getIndexByIndex(i);
                dim.checkIndex(timestamp, array_index, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                final IValue tmp = array_index.getValueRefdLast(timestamp, referenceChain);
                if (tmp.getValuetype() == Value_type.INTEGER_VALUE) {
                    final BigInteger index = ((Integer_Value) tmp).getValueValue();
                    if (index.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
                        array_index.getLocation().reportSemanticError(MessageFormat.format("An integer value less than {0} was expected for indexing timer array instead of {1}", Integer.MAX_VALUE, index));
                        array_index.setIsErroneous(true);
                    } else {
                        final int IndexValue = index.intValue();
                        if (indexMap.containsKey(IndexValue)) {
                            array_index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value {0} for timer array elements {1} and {2}", index, i + 1, indexMap.get(IndexValue)));
                            array_index.setIsErroneous(true);
                        } else {
                            indexMap.put(IndexValue, i + 1);
                        }
                    }
                }
            }
            // It's not possible to have "indexMap.size() > arraySize", since we
            // add only correct constant-index values into the map.  It's possible
            // to create partially initialized timer arrays.
            indexMap.clear();
        }
    } else {
        if (arraySizeKnown) {
            duration.getLocation().reportSemanticError("An array value (with " + arraySize + " elements) was expected as default duration of timer array");
        } else {
            duration.getLocation().reportSemanticError("An array value was expected as default duration of timer array");
        }
        duration.setIsErroneous(true);
    }
}
Also used : BigInteger(java.math.BigInteger) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) BigInteger(java.math.BigInteger) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 27 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class Assignment_Statement method checkVarAssignment.

private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
    final IType varType = getType(timestamp, assignment);
    if (varType == null || value == null) {
        isErroneous = true;
        return;
    }
    final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (type == null) {
        isErroneous = true;
        return;
    }
    value.setMyGovernor(type);
    IValue lastValue = type.checkThisValueRef(timestamp, value);
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
        final ISubReference lastReference = reference.removeLastSubReference();
        if (lastReference == null || lastReference.getId() == null) {
            value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
            isErroneous = true;
            reference.addSubReference(lastReference);
            return;
        }
        final Identifier lastField = lastReference.getId();
        final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
        reference.addSubReference(lastReference);
        final Reference newReference = new TemporalReference(null, baseReference);
        newReference.clearStringElementReferencing();
        IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
        if (baseType == null) {
            isErroneous = true;
            return;
        }
        baseType = baseType.getTypeRefdLast(timestamp);
        if (baseType.getIsErroneous(timestamp)) {
            isErroneous = true;
            return;
        }
        CompField componentField;
        switch(baseType.getTypetype()) {
            case TYPE_TTCN3_SEQUENCE:
                componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SEQUENCE:
                componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_TTCN3_SET:
                componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            case TYPE_ASN1_SET:
                componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
                if (componentField != null && !componentField.isOptional()) {
                    value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
                    value.setIsErroneous(true);
                }
                break;
            default:
                // TODO:check this!!!
                value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
                value.setIsErroneous(true);
                isErroneous = true;
                break;
        }
    } else {
        final boolean isStringElement = reference.refersToStringElement();
        selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
        if (isStringElement) {
            // The length of the right hand side should be 1
            final IType lastType = type.getTypeRefdLast(timestamp);
            int stringLength = 1;
            switch(lastType.getTypetype()) {
                case TYPE_BITSTRING:
                case TYPE_BITSTRING_A:
                    if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Bitstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_HEXSTRING:
                    if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
                        lastValue = null;
                    } else {
                        stringLength = ((Hexstring_Value) lastValue).getValueLength();
                    }
                    break;
                case TYPE_OCTETSTRING:
                    if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Octetstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_CHARSTRING:
                case TYPE_NUMERICSTRING:
                case TYPE_PRINTABLESTRING:
                case TYPE_IA5STRING:
                case TYPE_VISIBLESTRING:
                case TYPE_UTCTIME:
                case TYPE_GENERALIZEDTIME:
                    if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        return;
                    }
                    stringLength = ((Charstring_Value) lastValue).getValueLength();
                    break;
                case TYPE_UCHARSTRING:
                case TYPE_UTF8STRING:
                case TYPE_TELETEXSTRING:
                case TYPE_VIDEOTEXSTRING:
                case TYPE_GRAPHICSTRING:
                case TYPE_GENERALSTRING:
                case TYPE_UNIVERSALSTRING:
                case TYPE_BMPSTRING:
                case TYPE_OBJECTDESCRIPTOR:
                    if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
                    } else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
                        stringLength = ((Charstring_Value) lastValue).getValueLength();
                    } else {
                        return;
                    }
                    break;
                default:
                    lastValue = null;
                    return;
            }
            if (stringLength != 1) {
                final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
                value.getLocation().reportSemanticError(message);
                value.setIsErroneous(true);
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Reference(org.eclipse.titan.designer.AST.Reference) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) IType(org.eclipse.titan.designer.AST.IType) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) TemporalReference(org.eclipse.titan.designer.AST.TemporalReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 28 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Altguard method generateCodeInvokeInstance.

/**
 * Generate code for an alt guard
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param expression the expression to generate the source to
 */
public void generateCodeInvokeInstance(final JavaGenData aData, final ExpressionStruct expression) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.ALTSTEP_REFERENCE_VALUE) {
        Def_Altstep altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
        expression.expression.append(MessageFormat.format("{0}_instance(", altstep.getGenNameFromScope(aData, expression.expression, myScope, "")));
        actualParameterList.generateCodeAlias(aData, expression);
    } else {
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".invoke(");
        IType governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        governor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        actualParameterList.generateCodeAlias(aData, expression);
    }
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Altstep_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Altstep_Reference_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) IType(org.eclipse.titan.designer.AST.IType)

Example 29 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class Done_Statement method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    aData.addBuiltinTypeImport("TitanComponent");
    if (componentreference != null) {
        if (doneMatch != null) {
            // value returning done
            // figure out what type the done() function belongs to
            IType t = doneMatch.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            if (t == null) {
                ErrorReporter.INTERNAL_ERROR("Encountered a done with unknown governor `" + getFullName() + "''");
                return;
            }
            while (t instanceof Referenced_Type && !t.hasDoneAttribute()) {
                final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                t = ((IReferencingType) t).getTypeRefd(CompilationTimeStamp.getBaseTimestamp(), refChain);
                refChain.release();
            }
            if (!t.hasDoneAttribute()) {
                ErrorReporter.INTERNAL_ERROR("Encountered a done return type without done attribute `" + getFullName() + "''");
                return;
            }
            // determine whether the done() function is in the same module
            final Module t_module = t.getMyScope().getModuleScope();
            if (t_module != myStatementBlock.getModuleScope()) {
                expression.expression.append(MessageFormat.format("{0}.", t_module.getIdentifier().getName()));
            }
            expression.expression.append("done(");
            componentreference.generateCodeExpression(aData, expression, true);
            expression.expression.append(", ");
            // FIXME handle decoded match
            doneMatch.generateCode(aData, expression, Restriction_type.TR_NONE);
        // expression.expression.append(", ");
        // FIXME handle value redirection
        } else {
            // simple done
            componentreference.generateCodeExpressionMandatory(aData, expression, true);
            expression.expression.append(".done(");
        }
        // FIXME handle index redirection
        expression.expression.append(')');
    } else if (isAny) {
        // any component.done
        expression.expression.append("TTCN_Runtime.component_done(TitanComponent.ANY_COMPREF)");
    } else {
        // all component.done
        expression.expression.append("TTCN_Runtime.component_done(TitanComponent.ALL_COMPREF)");
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 30 with IReferenceChain

use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Enumerated_Type method checkEnumItem.

/**
 * Helper function for checking a single enumeration item. Checks if the
 * name of the item is not a duplicate, and its value is in correct
 * order. Also for items after the ellipsis if the value is missing a
 * new one is assigned.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param item
 *                the enumeration item to work on.
 * @param afterEllipsis
 *                true if the enumeration item is after the ellipsis.
 * @param valueMap
 *                a value map so that the correctness of the item's
 *                value can be checked.
 */
private final void checkEnumItem(final CompilationTimeStamp timestamp, final EnumItem item, final boolean afterEllipsis, final Map<Integer, EnumItem> valueMap) {
    final Identifier itemID = item.getId();
    if (nameMap.containsKey(itemID.getName())) {
        nameMap.get(itemID.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, itemID.getDisplayName()));
        itemID.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATEDREPEATED, itemID.getDisplayName()));
    } else {
        nameMap.put(itemID.getName(), item);
    }
    if (!itemID.getHasValid(Identifier_type.ID_TTCN)) {
        itemID.getLocation().reportSemanticWarning(MessageFormat.format(ASN1Assignment.UNREACHABLE, itemID.getDisplayName()));
    }
    final Value value = item.getValue();
    if (!item.isOriginal()) {
        if (afterEllipsis) {
            while (valueMap.containsKey(firstUnused)) {
                firstUnused++;
            }
            valueMap.put(firstUnused, item);
            // again.
            if (null == value || ((Integer_Value) value).getValue() != firstUnused) {
                final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
                tempValue.setLocation(item.getLocation());
                item.setValue(tempValue);
            }
        }
        return;
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    if (!Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", itemID.getDisplayName()));
        value.setIsErroneous(true);
        return;
    }
    final Integer_Value temp = (Integer_Value) last;
    if (!temp.isNative()) {
        value.getLocation().reportSemanticError(MessageFormat.format("The numeric value of enumeration `{0}'' ({1}) is too large for being represented in memory", itemID.getDisplayName(), temp.getValueValue()));
        value.setIsErroneous(true);
        return;
    }
    final Integer enumValue = Integer.valueOf(temp.intValue());
    if (afterEllipsis) {
        if (enumValue >= firstUnused) {
            valueMap.put(enumValue, item);
            while (valueMap.containsKey(firstUnused)) {
                firstUnused++;
            }
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format("ENUMERATED values shall be monotonically growing after the ellipsis: the value of `{0}'' must be at least {1} instead of {2}", itemID.getDisplayName(), firstUnused, enumValue));
            value.setIsErroneous(true);
        }
    } else {
        if (valueMap.containsKey(enumValue)) {
            final Location tempLocation = valueMap.get(enumValue).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumValue, valueMap.get(enumValue).getId().getDisplayName()));
            value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumValue, itemID.getDisplayName()));
            setIsErroneous(true);
        } else {
            valueMap.put(enumValue, item);
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)154 IValue (org.eclipse.titan.designer.AST.IValue)102 IType (org.eclipse.titan.designer.AST.IType)55 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)21 ISubReference (org.eclipse.titan.designer.AST.ISubReference)18 Value (org.eclipse.titan.designer.AST.Value)18 Assignment (org.eclipse.titan.designer.AST.Assignment)16 BigInteger (java.math.BigInteger)15 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)14 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)13 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Reference (org.eclipse.titan.designer.AST.Reference)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)8 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)7 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)7 HashMap (java.util.HashMap)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)6 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)6 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)6 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)5