Search in sources :

Example 91 with Integer_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Enumerated_Type method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 */
@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String ownName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
    final ArrayList<Enum_field> fields = new ArrayList<EnumeratedGenerator.Enum_field>(items.getItems().size());
    for (int i = 0; i < items.getItems().size(); i++) {
        final EnumItem tempItem = items.getItems().get(i);
        fields.add(new Enum_field(tempItem.getId().getName(), tempItem.getId().getDisplayName(), ((Integer_Value) tempItem.getValue()).getValue()));
    }
    final Enum_Defs e_defs = new Enum_Defs(fields, ownName, displayName, getGenNameTemplate(aData, source, myScope), hasRaw);
    EnumeratedGenerator.generateValueClass(aData, source, e_defs);
    EnumeratedGenerator.generateTemplateClass(aData, source, e_defs);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : Enum_field(org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_field) ArrayList(java.util.ArrayList) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Enum_Defs(org.eclipse.titan.designer.AST.TTCN3.types.EnumeratedGenerator.Enum_Defs)

Example 92 with Integer_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Enumerated_Type method check.

/**
 * Does the semantic checking of the enumerations.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 */
@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    parseAttributes(timestamp);
    nameMap = new HashMap<String, EnumItem>(items.getItems().size());
    final Map<Long, EnumItem> valueMap = new HashMap<Long, EnumItem>(items.getItems().size());
    final List<EnumItem> enumItems = items.getItems();
    // check duplicated names and values
    for (int i = 0, size = enumItems.size(); i < size; i++) {
        final EnumItem item = enumItems.get(i);
        final Identifier id = item.getId();
        final String fieldName = id.getName();
        if (nameMap.containsKey(fieldName)) {
            nameMap.get(fieldName).getId().getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERFIRST, id.getDisplayName()));
            id.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEENUMERATIONIDENTIFIERREPEATED, id.getDisplayName()));
        } else {
            nameMap.put(fieldName, item);
        }
        final Value value = item.getValue();
        if (value != null && item.isOriginal()) {
            if (value.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(value.getValuetype())) {
                value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for enumeration `{0}''", id.getDisplayName()));
                setIsErroneous(true);
            } else {
                final Integer_Value enumValue = (Integer_Value) value;
                if (!enumValue.isNative()) {
                    enumValue.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERERROR, enumValue.getValueValue()));
                    setIsErroneous(true);
                } else {
                    final Long enumLong = enumValue.getValue();
                    if (valueMap.containsKey(enumLong)) {
                        valueMap.get(enumLong).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEFIRST, enumLong, valueMap.get(enumLong).getId().getDisplayName()));
                        value.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDENUMERATIONVALUEREPEATED, enumLong, id.getDisplayName()));
                        setIsErroneous(true);
                    } else {
                        valueMap.put(enumLong, item);
                    }
                }
            }
        }
    }
    // Assign default values
    if (!getIsErroneous(timestamp) && lastTimeChecked == null) {
        Long firstUnused = Long.valueOf(0);
        while (valueMap.containsKey(firstUnused)) {
            firstUnused++;
        }
        for (int i = 0, size = enumItems.size(); i < size; i++) {
            final EnumItem item = enumItems.get(i);
            if (!item.isOriginal()) {
                // optimization: if the same value was already assigned, there is no need to create it again.
                final IValue value = item.getValue();
                if (value == null || ((Integer_Value) value).getValue() != firstUnused) {
                    final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
                    tempValue.setLocation(item.getLocation());
                    item.setValue(tempValue);
                }
                valueMap.put(firstUnused, item);
                firstUnused = Long.valueOf(firstUnused.longValue() + 1);
                while (valueMap.containsKey(firstUnused)) {
                    firstUnused++;
                }
            }
        }
    }
    valueMap.clear();
    lastTimeChecked = timestamp;
    checkSubtypeRestrictions(timestamp);
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) 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) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 93 with Integer_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.

the class SequenceOf_Type method checkThisValueSequenceOf.

/**
 * Checks the SequenceOf_value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for sure
 * that the value is of set-of type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value expected here.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param implicitOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
public boolean checkThisValueSequenceOf(final CompilationTimeStamp timestamp, final SequenceOf_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    if (value.isIndexed()) {
        boolean checkHoles = Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
        BigInteger maxIndex = BigInteger.valueOf(-1);
        final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(value.getNofComponents());
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            final IValue index = value.getIndexByIndex(i);
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            final IType tempType = TypeFactory.createType(Type_type.TYPE_INTEGER);
            tempType.check(timestamp);
            indexLast.setMyGovernor(tempType);
            final IValue temporalValue = tempType.checkThisValueRef(timestamp, indexLast);
            tempType.checkThisValue(timestamp, temporalValue, lhs, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, true, false, false));
            if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(temporalValue.getValuetype())) {
                checkHoles = false;
            } else {
                final BigInteger tempIndex = ((Integer_Value) temporalValue).getValueValue();
                if (tempIndex.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A integer value less than `{0}'' was expected for indexing type `{1}'' instead of `{2}''", Integer.MAX_VALUE, getTypename(), tempIndex));
                    checkHoles = false;
                } else if (tempIndex.compareTo(BigInteger.ZERO) == -1) {
                    index.getLocation().reportSemanticError(MessageFormat.format("A non-negative integer value was expected for indexing type `{0}'' instead of `{1}''", getTypename(), tempIndex));
                    checkHoles = false;
                } else if (indexMap.containsKey(tempIndex)) {
                    index.getLocation().reportSemanticError(MessageFormat.format("Duplicate index value `{0}'' for components {1} and {2}", tempIndex, indexMap.get(tempIndex), i + 1));
                    checkHoles = false;
                } else {
                    indexMap.put(tempIndex, Integer.valueOf(i + 1));
                    if (maxIndex.compareTo(tempIndex) == -1) {
                        maxIndex = tempIndex;
                    }
                }
            }
            component.setMyGovernor(getOfType());
            final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
            selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
        }
        if (checkHoles) {
            if (maxIndex.compareTo(BigInteger.valueOf(indexMap.size() - 1)) != 0) {
                value.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
            }
        }
    } else {
        for (int i = 0, size = value.getNofComponents(); i < size; i++) {
            final IValue component = value.getValueByIndex(i);
            component.setMyGovernor(getOfType());
            if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
                if (!incompleteAllowed) {
                    component.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                }
            } else {
                final IValue tempValue2 = getOfType().checkThisValueRef(timestamp, component);
                selfReference |= getOfType().checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : BigInteger(java.math.BigInteger) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger) IType(org.eclipse.titan.designer.AST.IType)

Example 94 with Integer_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.

the class SequenceOf_Type method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            if (indexValue != null) {
                indexValue.setLoweridToReference(timestamp);
                final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
                switch(tempType) {
                    case TYPE_INTEGER:
                        final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
                        if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
                            final Integer_Value lastInteger = (Integer_Value) last;
                            if (lastInteger.isNative()) {
                                final long temp = lastInteger.getValue();
                                if (temp < 0) {
                                    indexValue.getLocation().reportSemanticError(MessageFormat.format(NONNEGATIVINDEXEXPECTED, temp));
                                    indexValue.setIsErroneous(true);
                                }
                            } else {
                                indexValue.getLocation().reportSemanticError(MessageFormat.format(TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
                                indexValue.setIsErroneous(true);
                            }
                        }
                        break;
                    case TYPE_UNDEFINED:
                        indexValue.setIsErroneous(true);
                        break;
                    default:
                        indexValue.getLocation().reportSemanticError(INTEGERINDEXEXPECTED);
                        indexValue.setIsErroneous(true);
                        break;
                }
            }
            if (getOfType() != null) {
                return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
            }
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) 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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 95 with Integer_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.

the class AbstractOfType method getFieldType.

@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            if (indexValue != null) {
                indexValue.setLoweridToReference(timestamp);
                final Type_type tempType = indexValue.getExpressionReturntype(timestamp, expectedIndex);
                switch(tempType) {
                    case TYPE_INTEGER:
                        final IValue last = indexValue.getValueRefdLast(timestamp, expectedIndex, refChain);
                        if (Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
                            final Integer_Value lastInteger = (Integer_Value) last;
                            if (lastInteger.isNative()) {
                                final long temp = lastInteger.getValue();
                                if (temp < 0) {
                                    indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.NONNEGATIVINDEXEXPECTED, temp));
                                    indexValue.setIsErroneous(true);
                                }
                            } else {
                                indexValue.getLocation().reportSemanticError(MessageFormat.format(SequenceOf_Type.TOOBIGINDEX, lastInteger.getValueValue(), getTypename()));
                                indexValue.setIsErroneous(true);
                            }
                        }
                        break;
                    case TYPE_UNDEFINED:
                        indexValue.setIsErroneous(true);
                        break;
                    default:
                        indexValue.getLocation().reportSemanticError(SequenceOf_Type.INTEGERINDEXEXPECTED);
                        indexValue.setIsErroneous(true);
                        break;
                }
            }
            if (getOfType() != null) {
                return getOfType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
            }
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)91 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)87 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)23 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)19 IType (org.eclipse.titan.designer.AST.IType)17 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)15 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)15 BigInteger (java.math.BigInteger)13 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)12 Value (org.eclipse.titan.designer.AST.Value)12 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)9 HashMap (java.util.HashMap)8 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)8 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)8 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)8