Search in sources :

Example 41 with Value

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

the class ISO2022String_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value arrayIndex = ((ArraySubReference) subreference).getValue();
            final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, refChain);
            if (!valueIndex.isUnfoldable(timestamp)) {
                if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
                    final int index = ((Integer_Value) valueIndex).intValue();
                    return getStringElement(index, arrayIndex.getLocation());
                }
                arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
                return null;
            }
            return null;
        case fieldSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
            return null;
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) 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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 42 with Value

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

the class GeneralString_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 43 with Value

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

the class SequenceOf_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;
    }
    if (lastTimeChecked == null || lastTimeChecked.isLess(timestamp)) {
        convertedValue = null;
    }
    if (convertedValue != null && convertedValue != this) {
        return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value arrayIndex = ((ArraySubReference) subreference).getValue();
            IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (valueIndex.isUnfoldable(timestamp)) {
                return false;
            }
            if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
                final int index = ((Integer_Value) valueIndex).intValue();
                if (index < 0) {
                    return false;
                }
                if (isIndexed()) {
                    for (int i = 0; i < values.getNofIndexedValues(); i++) {
                        IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
                        referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        indexedValue = indexedValue.getValueRefdLast(timestamp, referenceChain);
                        referenceChain.release();
                        if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
                            return values.getIndexedValueByIndex(i).getValue().evaluateIsbound(timestamp, reference, actualSubReference + 1);
                        }
                    }
                } else if (index >= values.getNofValues()) {
                    if (!reference.getUsedInIsbound()) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format(INDEXOVERFLOW, type.getTypename(), index, values.getNofValues()));
                    }
                } else {
                    return values.getValueByIndex(index).evaluateIsbound(timestamp, reference, actualSubReference + 1);
                }
                return false;
            }
            return false;
        case fieldSubReference:
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) 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) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 44 with Value

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

the class SequenceOf_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;
    }
    if (lastTimeChecked == null || lastTimeChecked.isLess(timestamp)) {
        convertedValue = null;
    }
    if (convertedValue != null && convertedValue != this) {
        return convertedValue.evaluateIsbound(timestamp, reference, actualSubReference);
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return false;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            final Value arrayIndex = ((ArraySubReference) subreference).getValue();
            IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, referenceChain);
            referenceChain.release();
            if (valueIndex.isUnfoldable(timestamp)) {
                return false;
            }
            if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
                final int index = ((Integer_Value) valueIndex).intValue();
                if (index < 0) {
                    return false;
                }
                if (isIndexed()) {
                    for (int i = 0; i < values.getNofIndexedValues(); i++) {
                        IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
                        referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                        indexedValue = indexedValue.getValueRefdLast(timestamp, referenceChain);
                        referenceChain.release();
                        if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
                            return values.getIndexedValueByIndex(i).getValue().evaluateIspresent(timestamp, reference, actualSubReference + 1);
                        }
                    }
                } else if (index >= values.getNofValues()) {
                    if (!reference.getUsedInIsbound()) {
                        arrayIndex.getLocation().reportSemanticError(MessageFormat.format(INDEXOVERFLOW, type.getTypename(), index, values.getNofValues()));
                    }
                } else {
                    return values.getValueByIndex(index).evaluateIspresent(timestamp, reference, actualSubReference + 1);
                }
                return false;
            }
            return false;
        case fieldSubReference:
            return false;
        case parameterisedSubReference:
            return false;
        default:
            return false;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) 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) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 45 with Value

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

the class Sequence_Value method getReferencedSubValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
        return this;
    }
    if (convertedValue != null && convertedValue != this) {
        final IValue temp = convertedValue.getReferencedSubValue(timestamp, reference, actualSubReference, refChain);
        if (temp != null && temp.getIsErroneous(timestamp)) {
            setIsErroneous(true);
        }
        return temp;
    }
    final IType type = myGovernor.getTypeRefdLast(timestamp);
    if (type.getIsErroneous(timestamp)) {
        return null;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDVALUESUBREFERENCE, type.getTypename()));
            return null;
        case fieldSubReference:
            final Identifier fieldId = ((FieldSubReference) subreference).getId();
            CompField compField;
            switch(type.getTypetype()) {
                case TYPE_TTCN3_SEQUENCE:
                    if (!((TTCN3_Sequence_Type) type).hasComponentWithName(fieldId.getName())) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((TTCN3_Sequence_Type) type).getComponentByName(fieldId.getDisplayName());
                    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;
                    }
                    if (!reference.getUsedInIsbound()) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format("Reference to unbound record field `{0}''", fieldId.getDisplayName()));
                    }
                    return null;
                case TYPE_ASN1_SEQUENCE:
                    if (!((ASN1_Sequence_Type) type).hasComponentWithName(fieldId)) {
                        subreference.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTFIELD, fieldId.getDisplayName(), type.getTypename()));
                        return null;
                    }
                    if (values.hasNamedValueWithName(fieldId)) {
                        return values.getNamedValueByName(fieldId).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    compField = ((ASN1_Sequence_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;
                    } else if (compField.hasDefault()) {
                        return compField.getDefault().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
                    }
                    return null;
                default:
                    return null;
            }
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
            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) 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) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

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