Search in sources :

Example 6 with Array_Value

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

the class LengthofExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody();
    final IValue value = ((SpecificValue_Template) template).getSpecificValue().getValueRefdLast(timestamp, referenceChain);
    int length;
    switch(value.getValuetype()) {
        case CHARSTRING_VALUE:
            length = ((Charstring_Value) value).getValueLength();
            break;
        case UNIVERSALCHARSTRING_VALUE:
            length = ((UniversalCharstring_Value) value).getValueLength();
            break;
        case BITSTRING_VALUE:
            length = ((Bitstring_Value) value).getValueLength();
            break;
        case HEXSTRING_VALUE:
            length = ((Hexstring_Value) value).getValueLength();
            break;
        case OCTETSTRING_VALUE:
            length = ((Octetstring_Value) value).getValueLength();
            break;
        case SEQUENCEOF_VALUE:
            length = ((SequenceOf_Value) value).getNofComponents();
            break;
        case SETOF_VALUE:
            length = ((SetOf_Value) value).getNofComponents();
            break;
        case ARRAY_VALUE:
            length = ((Array_Value) value).getNofComponents();
            break;
        default:
            setIsErroneous(true);
            return lastValue;
    }
    lastValue = new Integer_Value(length);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 7 with Array_Value

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

the class IncorrectRotate method getFirstRotateOperandLength.

/**
 * @param ct the compilation timestamp to be used
 * @param value the first operand of the rotate operation
 * @return the length of the first operand if it can be determined
 */
private static long getFirstRotateOperandLength(final CompilationTimeStamp ct, final Value value) {
    if (value == null) {
        return 0;
    }
    final Type_type tempType = value.getExpressionReturntype(ct, null);
    final IValue refd = value.getValueRefdLast(ct, null);
    long valueSize = 0;
    switch(tempType) {
        case TYPE_BITSTRING:
            if (Value_type.BITSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Bitstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_HEXSTRING:
            if (Value_type.HEXSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Hexstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_OCTETSTRING:
            if (Value_type.OCTETSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Octetstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_CHARSTRING:
            if (Value_type.CHARSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((Charstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_UCHARSTRING:
            if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(refd.getValuetype())) {
                valueSize = ((UniversalCharstring_Value) refd).getValueLength();
            }
            break;
        case TYPE_SET_OF:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            } else if (Value_type.SETOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SetOf_Value) value).getNofComponents();
            }
            break;
        case TYPE_SEQUENCE_OF:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            } else if (Value_type.SETOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SetOf_Value) value).getNofComponents();
            }
            break;
        case TYPE_ARRAY:
            if (Value_type.SEQUENCEOF_VALUE.equals(value.getValuetype())) {
                valueSize = ((SequenceOf_Value) value).getNofComponents();
            }
            if (Value_type.ARRAY_VALUE.equals(value.getValuetype())) {
                valueSize = ((Array_Value) value).getNofComponents();
            }
            break;
        default:
            break;
    }
    return valueSize;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 8 with Array_Value

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

the class Array_Type method checkThisValueArray.

private boolean checkThisValueArray(final CompilationTimeStamp timestamp, final IValue originalValue, final Assignment lhs, final Array_Value lastValue, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    if (dimension == null) {
        return false;
    }
    boolean selfReference = false;
    final int nofValues = lastValue.getNofComponents();
    if (!dimension.getIsErroneous(timestamp) && dimension.getSize() < nofValues) {
        originalValue.getLocation().reportSemanticError(MessageFormat.format(TOOMANYEXPECTED, dimension.getSize(), nofValues));
        originalValue.setIsErroneous(true);
    }
    if (lastValue.isIndexed()) {
        boolean checkHoles = !dimension.getIsErroneous(timestamp) && Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue);
        final long arraySize = dimension.getSize();
        BigInteger maxIndex = BigInteger.valueOf(-1);
        final Map<BigInteger, Integer> indexMap = new HashMap<BigInteger, Integer>(lastValue.getNofComponents());
        for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
            final IValue component = lastValue.getValueByIndex(i);
            final Value index = lastValue.getIndexByIndex(i);
            dimension.checkIndex(timestamp, index, expectedValue);
            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(elementType);
            final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
            selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
        }
        if (checkHoles) {
            if (indexMap.size() < arraySize) {
                lastValue.getLocation().reportSemanticError("It's not allowed to create hole(s) in constant values");
                originalValue.setIsErroneous(true);
            }
        }
    } else {
        if (!dimension.getIsErroneous(timestamp)) {
            final long arraySize = dimension.getSize();
            if (arraySize > nofValues) {
                originalValue.getLocation().reportSemanticError(MessageFormat.format("Too few elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
                originalValue.setIsErroneous(true);
            } else if (arraySize < nofValues) {
                originalValue.getLocation().reportSemanticError(MessageFormat.format("Too many elements in the array value: {0} was expected instead of {1}", arraySize, nofValues));
                originalValue.setIsErroneous(true);
            }
        }
        for (int i = 0, size = lastValue.getNofComponents(); i < size; i++) {
            final IValue component = lastValue.getValueByIndex(i);
            component.setMyGovernor(elementType);
            if (Value_type.NOTUSED_VALUE.equals(component.getValuetype())) {
                if (!incompleteAllowed) {
                    component.getLocation().reportSemanticError(AbstractOfType.INCOMPLETEPRESENTERROR);
                }
            } else {
                final IValue tempValue2 = elementType.checkThisValueRef(timestamp, component);
                selfReference |= elementType.checkThisValue(timestamp, tempValue2, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, implicitOmit, strElem));
            }
        }
    }
    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) Array_Value(org.eclipse.titan.designer.AST.TTCN3.values.Array_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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)8 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)5 Array_Value (org.eclipse.titan.designer.AST.TTCN3.values.Array_Value)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 Assignment_type (org.eclipse.titan.designer.AST.Assignment.Assignment_type)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)1 Def_Timer (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer)1 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)1 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)1 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)1