Search in sources :

Example 16 with SequenceOf_Value

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

the class ValueListAndSizeConstraint method isElement.

@Override
public /**
 * {@inheritDoc}
 */
boolean isElement(final Object o) {
    final IValue v = (IValue) o;
    SizeLimit sl;
    switch(v.getValuetype()) {
        case ARRAY_VALUE:
            sl = new SizeLimit(((Array_Value) v).getNofComponents());
            break;
        case SEQUENCEOF_VALUE:
            sl = new SizeLimit(((SequenceOf_Value) v).getNofComponents());
            break;
        case SETOF_VALUE:
            sl = new SizeLimit(((SetOf_Value) v).getNofComponents());
            break;
        default:
            ErrorReporter.INTERNAL_ERROR();
            return true;
    }
    if (sizeConstraint.isElement(sl)) {
        return !notValues.isElement(v);
    }
    return hasValues.isElement(v);
}
Also used : Array_Value(org.eclipse.titan.designer.AST.TTCN3.values.Array_Value) IValue(org.eclipse.titan.designer.AST.IValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 17 with SequenceOf_Value

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

the class ASN1_Set_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    if (getIsErroneous(timestamp)) {
        return false;
    }
    boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    switch(last.getValuetype()) {
        case SEQUENCE_VALUE:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case SEQUENCEOF_VALUE:
            if (((SequenceOf_Value) last).isIndexed()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Indexed assignment notation cannot be used for SET type `{0}''", getFullName()));
                value.setIsErroneous(true);
            } else {
                final SequenceOf_Value temporalValue = (SequenceOf_Value) last;
                if (temporalValue.getNofComponents() == 0) {
                    if (getNofComponents(timestamp) == 0) {
                        last = last.setValuetype(timestamp, Value_type.SET_VALUE);
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format(NONEMPTYEXPECTED, getFullName()));
                        value.setIsErroneous(true);
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? VALUELISTNOTATIONERRORASN1 : VALUELISTNOTATIONERRORTTCN3, getFullName()));
                    value.setIsErroneous(true);
                }
            }
            break;
        case SET_VALUE:
            if (last.isAsn()) {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            } else {
                selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            }
            break;
        case UNDEFINED_BLOCK:
            last = last.setValuetype(timestamp, Value_type.SET_VALUE);
            selfReference = checkThisValueSet(timestamp, (Set_Value) last, lhs, valueCheckingOptions.expected_value, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem);
            break;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            break;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(last.isAsn() ? SETVALUEXPECTEDASN1 : SETVALUEXPECTEDTTCN3, getFullName()));
            value.setIsErroneous(true);
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Set_Value(org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)

Example 18 with SequenceOf_Value

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

the class All_From_Template method getNofValues.

/**
 * Gets the number of values If the value is type of SEQUENCEOF_VALUE or
 * type of SETOF_VALUE then returns their size otherwise returns 1
 */
private int getNofValues(final IValue value, final CompilationTimeStamp timestamp) {
    int result = 0;
    if (value == null) {
        return result;
    }
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue lastValue = value.getValueRefdLast(timestamp, chain);
    chain.release();
    if (lastValue.getIsErroneous(timestamp)) {
        return result;
    }
    if (Value_type.SEQUENCEOF_VALUE.equals(lastValue.getValuetype())) {
        final SequenceOf_Value lvalue = (SequenceOf_Value) lastValue;
        result = lvalue.getNofComponents();
        return result;
    } else if (Value_type.SETOF_VALUE.equals(lastValue.getValuetype())) {
        final SetOf_Value svalue = (SetOf_Value) lastValue;
        result = svalue.getNofComponents();
        return result;
    } else {
        // this value is calculated as 1 in an all from
        return 1;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 19 with SequenceOf_Value

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

the class Def_Timer method generateCodeArrayDuration.

private void generateCodeArrayDuration(final JavaGenData aData, final StringBuilder source, final String genName, final ArrayList<String> classNames, final Value defaultDuration2, final int startDim) {
    final ArrayDimension dim = dimensions.get(startDim);
    final int dim_size = (int) dim.getSize();
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final Value v = (Value) defaultDuration2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (v.getValuetype() != Value_type.SEQUENCEOF_VALUE) {
        // ErrorReporter.INTERNAL_ERROR()
        return;
    }
    final SequenceOf_Value value = (SequenceOf_Value) v;
    if (value.getNofComponents() != dim_size && !value.isIndexed()) {
        ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous definition `" + getFullName() + "''");
        return;
    }
    // Value-list notation.
    if (!value.isIndexed()) {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < dim_size; i++) {
                // get_comp_byIndex(i);
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String embeddedName = MessageFormat.format("{0}.getAt({1})", genName, i + dim.getOffset());
                generateCodeArrayDuration(aData, source, embeddedName, classNames, (Value) v_elem, startDim + 1);
            }
        } else {
            // We are in the last dimension, the elements of "value" are floats.
            for (int i = 0; i < dim_size; i++) {
                final IValue v_elem = value.getValueByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                expression.expression.append(genName);
                expression.expression.append(".getAt(").append(i + dim.getOffset()).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
            }
        }
    // Indexed-list notation.
    } else {
        if (startDim + 1 < dimensions.size()) {
            // boolean temp_ref_needed = dimensions.get(startDim + 1).getSize() > 1;
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue index = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final String tempId1 = aData.getTemporaryVariableName();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                index.generateCodeInit(aData, source, tempIdX);
                source.append(MessageFormat.format("{0} {1} = {2}.getAt({3});\n", classNames.get(classNames.size() - startDim - 2), tempId1, genName, tempIdX));
                generateCodeArrayDuration(aData, source, tempId1, classNames, (Value) v_elem, startDim + 1);
                source.append("}\n");
            }
        } else {
            for (int i = 0; i < value.getNofComponents(); ++i) {
                final IValue v_elem = value.getValueByIndex(i);
                final IValue v_elemIndex = value.getIndexByIndex(i);
                if (v_elem.getValuetype() == Value_type.NOTUSED_VALUE) {
                    continue;
                }
                final ExpressionStruct expression = new ExpressionStruct();
                final String tempIdX = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append("TitanInteger " + tempIdX + " = new TitanInteger();\n");
                v_elemIndex.generateCodeInit(aData, source, tempIdX);
                final String embeddedName = MessageFormat.format("{0}.getAt(", genName);
                expression.expression.append(embeddedName).append(tempIdX).append(")");
                // originally set_default_duration(obj_name, i)
                expression.expression.append(".assign(");
                v_elem.generateCodeExpression(aData, expression, true);
                expression.expression.append(')');
                expression.mergeExpression(source);
                source.append("}\n");
            }
        }
    }
    return;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Value(org.eclipse.titan.designer.AST.Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)

Example 20 with SequenceOf_Value

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

the class RotateLeftExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    Type_type tempType1 = null;
    Type_type tempType2 = null;
    long valueSize = 0;
    long rotationSize = 0;
    IValue tempValue;
    if (value1 != null) {
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType1) {
            case TYPE_BITSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Bitstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_HEXSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Hexstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_OCTETSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Octetstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_CHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.CHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Charstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_UCHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((UniversalCharstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_SET_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.SETOF_VALUE);
                }
                if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_SEQUENCE_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SequenceOf_Value) tempValue).getNofComponents();
                } else if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_ARRAY:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.ARRAY_VALUE);
                }
                if (Value_type.ARRAY_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Array_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(FIRSTOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
                    if (!((Integer_Value) tempValue).isNative()) {
                        value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
                        setIsErroneous(true);
                        break;
                    }
                    rotationSize = ((Integer_Value) tempValue).getValue();
                    if (value1 != null && !value1.isUnfoldable(timestamp)) {
                        final String severtiy = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
                        if (valueSize == 0 || valueSize == 1) {
                            location.reportConfigurableSemanticProblem(severtiy, EFFECTLESSROTATION);
                        } else if (rotationSize < 0) {
                            location.reportConfigurableSemanticProblem(severtiy, NEGATIVEROTATEPROBLEM);
                        } else if (rotationSize == 0) {
                            location.reportConfigurableSemanticProblem(severtiy, ZEROROTATEPROBLEM);
                        } else if (rotationSize > valueSize) {
                            location.reportConfigurableSemanticProblem(severtiy, MessageFormat.format(TOOBIGROTATEPROBLEM, valueSize, rotationSize, rotationSize % valueSize));
                        }
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(SECONDOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)23 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)6 BigInteger (java.math.BigInteger)3 HashMap (java.util.HashMap)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Array_Value (org.eclipse.titan.designer.AST.TTCN3.values.Array_Value)3 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)3 Sequence_Value (org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value)3 Value (org.eclipse.titan.designer.AST.Value)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)2 ArrayDimension (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension)2 Set_Value (org.eclipse.titan.designer.AST.TTCN3.values.Set_Value)2 Values (org.eclipse.titan.designer.AST.TTCN3.values.Values)2