Search in sources :

Example 11 with Value

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

the class Set_Value method evaluateIspresent.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIspresent(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIspresent(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIspresent(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 12 with Value

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

the class Set_Value method evaluateIsbound.

@Override
public /**
 * {@inheritDoc}
 */
boolean evaluateIsbound(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return true;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            return false;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SET:
                    if (!((TTCN3_Set_Type) type).hasComponentWithName(fieldId.getName())) {
                        return false;
                    }
                    break;
                case TYPE_ASN1_SET:
                    if (!((ASN1_Set_Type) type).hasComponentWithName(fieldId)) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
            if (values.hasNamedValueWithName(fieldId)) {
                // we can move on with the check
                return values.getNamedValueByName(fieldId).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
            }
            if (Type_type.TYPE_TTCN3_SET.equals(type.getTypetype())) {
                return false;
            }
            final CompField compField = ((ASN1_Set_Type) type).getComponentByName(fieldId);
            if (compField.isOptional()) {
                // create an explicit omit value
                final Value result = new Omit_Value();
                final BridgingNamedNode bridge = new BridgingNamedNode(this, "." + fieldId.getDisplayName());
                result.setFullNameParent(bridge);
                result.setMyScope(getMyScope());
                return result.evaluateIsbound(timestamp, reference, actualSubReference + 1);
            } else if (compField.hasDefault()) {
                return compField.getDefault().evaluateIsbound(timestamp, reference, actualSubReference + 1);
            }
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with Value

use of org.eclipse.titan.designer.AST.Value 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 14 with Value

use of org.eclipse.titan.designer.AST.Value 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)

Example 15 with Value

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

the class Indexed_Template_List method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    if (asValue != null) {
        asValue.generateCodeInit(aData, source, name);
        return;
    }
    if (myGovernor == null) {
        return;
    }
    // FIXME actually a bit more complex
    final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    String ofTypeName;
    switch(type.getTypetype()) {
        case TYPE_SEQUENCE_OF:
            ofTypeName = ((SequenceOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
            break;
        case TYPE_SET_OF:
            ofTypeName = ((SetOf_Type) type).getOfType().getGenNameTemplate(aData, source, myScope);
            break;
        case TYPE_ARRAY:
            ofTypeName = ((Array_Type) type).getElementType().getGenNameTemplate(aData, source, myScope);
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing indexed template `" + getFullName() + "''");
            return;
    }
    if (indexedTemplates.getNofTemplates() == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
    }
    // else is not needed as the loop will not run
    for (int i = 0; i < indexedTemplates.getNofTemplates(); i++) {
        final IndexedTemplate indexedTemplate = indexedTemplates.getTemplateByIndex(i);
        final String tempId = aData.getTemporaryVariableName();
        source.append("{\n");
        final Value index = indexedTemplate.getIndex().getValue();
        if (Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
            source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, ((Integer_Value) index).getValue()));
        } else {
            final String tempId2 = aData.getTemporaryVariableName();
            source.append(MessageFormat.format("TitanInteger {0} = new TitanInteger();\n", tempId2));
            index.generateCodeInit(aData, source, tempId2);
            source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", ofTypeName, tempId, name, tempId2));
        }
        indexedTemplate.getTemplate().generateCodeInit(aData, source, tempId);
        source.append("}\n");
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) IValue(org.eclipse.titan.designer.AST.IValue) IndexedValue(org.eclipse.titan.designer.AST.TTCN3.values.IndexedValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) IType(org.eclipse.titan.designer.AST.IType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)

Aggregations

Value (org.eclipse.titan.designer.AST.Value)71 IValue (org.eclipse.titan.designer.AST.IValue)63 ISubReference (org.eclipse.titan.designer.AST.ISubReference)50 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)41 IType (org.eclipse.titan.designer.AST.IType)34 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)18 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)18 Identifier (org.eclipse.titan.designer.AST.Identifier)12 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)6 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)6 BigInteger (java.math.BigInteger)5 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)5 HashMap (java.util.HashMap)4 SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)4 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Reference (org.eclipse.titan.designer.AST.Reference)3