Search in sources :

Example 21 with Value

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

the class GeneralizedTime_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 ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        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) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 22 with Value

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

the class AbstractOfType method checkThisValueSetOf.

/**
 * Checks the SequenceOf_value kind value against this type.
 * SequenceOf_value kinds have to be converted before calling this
 * function.
 * <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 checkThisValueSetOf(final CompilationTimeStamp timestamp, final SetOf_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 Value index = value.getIndexByIndex(i);
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue indexLast = index.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (indexLast.getIsErroneous(timestamp) || !Value_type.INTEGER_VALUE.equals(indexLast.getValuetype())) {
                checkHoles = false;
            } else {
                final BigInteger tempIndex = ((Integer_Value) indexLast).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 && 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) 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) BigInteger(java.math.BigInteger)

Example 23 with Value

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

the class BitString_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 ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        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) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 24 with Value

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

the class TTCN3_Choice_Type method checkCodingAttributes.

@Override
public /**
 * {@inheritDoc}
 */
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    // TODO can unions have length restriction?
    if (rawAttribute != null) {
        // TODO force_raw()
        if (rawAttribute.taglist != null) {
            for (int c = 0; c < rawAttribute.taglist.size(); c++) {
                final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
                final Identifier fieldname = singleTag.fieldName;
                if (!hasComponentWithName(fieldname.getName())) {
                    fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
                    continue;
                }
                if (singleTag.keyList != null) {
                    for (int a = 0; a < singleTag.keyList.size(); a++) {
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(fieldname));
                        for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
                            reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
                        }
                        final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                        if (t != null) {
                            final Value v = singleTag.keyList.get(a).v_value;
                            if (v != null) {
                                v.setMyScope(getMyScope());
                                v.setMyGovernor(t);
                                final IValue tempValue = t.checkThisValueRef(timestamp, v);
                                t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
                            }
                        }
                    }
                }
            }
        }
    }
    if (refChain.contains(this)) {
        return;
    }
    refChain.add(this);
    refChain.markState();
    for (int i = 0; i < getNofComponents(); i++) {
        final CompField cf = getComponentByIndex(i);
        cf.getType().checkCodingAttributes(timestamp, refChain);
    }
    refChain.previousState();
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) Choice_Value(org.eclipse.titan.designer.AST.TTCN3.values.Choice_Value) RawAST.rawAST_single_tag(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST.rawAST_single_tag) IType(org.eclipse.titan.designer.AST.IType)

Example 25 with Value

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

the class CharString_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 ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            if (subreferences.size() > actualSubReference + 1) {
                subreference.getLocation().reportSemanticError(ArraySubReference.INVALIDSTRINGELEMENTINDEX);
                return null;
            } else if (subreferences.size() == actualSubReference + 1) {
                reference.setStringElementReferencing();
            }
            final Value indexValue = ((ArraySubReference) subreference).getValue();
            checkStringIndex(timestamp, indexValue, expectedIndex, refChain);
            return this;
        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) Value(org.eclipse.titan.designer.AST.Value) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

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