Search in sources :

Example 16 with IReferenceChain

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

the class Array_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) || !Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
        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 (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);
                        }
                    }
                    arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
                } else if (index < 0 || index >= values.getNofValues()) {
                // the error was already reported
                } 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 17 with IReferenceChain

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

the class Array_Value method checkEquality.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = other.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    if (!Value_type.ARRAY_VALUE.equals(last.getValuetype())) {
        return false;
    }
    final Array_Value otherArray = (Array_Value) last;
    if (values.isIndexed()) {
        if (otherArray.isIndexed()) {
            if (values.getNofIndexedValues() != otherArray.values.getNofIndexedValues()) {
                return false;
            }
            for (int i = 0, size = values.getNofIndexedValues(); i < size; i++) {
                final IndexedValue localTemp = values.getIndexedValueByIndex(i);
                final IValue indexValue = localTemp.getIndex().getValue();
                if (Value_type.INTEGER_VALUE.equals(indexValue.getValuetype())) {
                    final Integer_Value integerValue = (Integer_Value) indexValue;
                    final IValue otherValue = otherArray.values.getIndexedValueByRealIndex(integerValue.intValue());
                    if (otherValue == null || !localTemp.getValue().checkEquality(timestamp, otherValue)) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        } else {
            if (values.getNofIndexedValues() != otherArray.values.getNofValues()) {
                return false;
            }
            for (int i = 0, size = otherArray.values.getNofValues(); i < size; i++) {
                final IValue value = values.getIndexedValueByRealIndex(i);
                if (value == null || !otherArray.values.getValueByIndex(i).checkEquality(timestamp, value)) {
                    return false;
                }
            }
        }
    } else {
        if (otherArray.isIndexed()) {
            if (values.getNofValues() != otherArray.values.getNofIndexedValues()) {
                return false;
            }
            for (int i = 0, size = values.getNofValues(); i < size; i++) {
                final IValue otherValue = otherArray.values.getIndexedValueByRealIndex(i);
                if (otherValue == null || !values.getValueByIndex(i).checkEquality(timestamp, otherValue)) {
                    return false;
                }
            }
        } else {
            if (values.getNofValues() != otherArray.values.getNofValues()) {
                return false;
            }
            for (int i = 0, size = values.getNofValues(); i < size; i++) {
                if (!values.getValueByIndex(i).checkEquality(timestamp, otherArray.values.getValueByIndex(i))) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 18 with IReferenceChain

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

the class Boolean_Value method checkEquality.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = other.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    return Value_type.BOOLEAN_VALUE.equals(last.getValuetype()) && value == ((Boolean_Value) last).getValue();
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 19 with IReferenceChain

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

the class Charstring_Value method checkEquality.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkEquality(final CompilationTimeStamp timestamp, final IValue other) {
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = other.getValueRefdLast(timestamp, referenceChain);
    referenceChain.release();
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            return value.equals(((Charstring_Value) last).getValue());
        case UNIVERSALCHARSTRING_VALUE:
            return value.equals(((UniversalCharstring_Value) last).getValue().getString());
        case ISO2022STRING_VALUE:
            return value.equals(((ISO2022String_Value) last).getValueISO2022String());
        default:
            return false;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 20 with IReferenceChain

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

the class Expression_Value method getValueRefdLast.

/**
 * This function is used to check the expression semantically.
 * The function itself shell evaluate the internal semantic checking of the value, and return with the either the folded value or itself.
 * This way when this function is called from a type, it is able to check the kind of the value against the type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param expectedValue the kind of the value to be expected
 * @param referenceChain an initialized reference chain to help detecting circular references.
 *
 * @return the evaluated value of the expression or the expression itself if it can not be folded in compilation time.
 */
@Override
public final IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    IValue last = this;
    tempReferenceChain.markState();
    if (tempReferenceChain.add(this)) {
        last = evaluateValue(timestamp, expectedValue, tempReferenceChain);
    } else {
        setIsErroneous(true);
    }
    tempReferenceChain.previousState();
    if (newChain) {
        tempReferenceChain.release();
    }
    // the last safety check just to be sure
    if (last == null) {
        return this;
    }
    return last;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

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