Search in sources :

Example 86 with Type_type

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

the class RemoveBomExpression 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) {
    if (value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_OCTETSTRING:
            // TODO: implement missing part if range check is needed
            return;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            return;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 87 with Type_type

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

the class ReplaceExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance1 == null || templateInstance4 == null || getIsErroneous(timestamp)) {
        return true;
    }
    final ITTCN3Template template1 = templateInstance1.getTemplateBody();
    if (template1 == null || !Template_type.SPECIFIC_VALUE.equals(template1.getTemplatetype())) {
        return true;
    }
    final ITTCN3Template template4 = templateInstance4.getTemplateBody();
    if (template4 == null || !Template_type.SPECIFIC_VALUE.equals(template4.getTemplatetype())) {
        return true;
    }
    final IValue value1 = ((SpecificValue_Template) template1).getSpecificValue();
    final IValue value4 = ((SpecificValue_Template) template4).getSpecificValue();
    if (value1 == null || value4 == null) {
        return true;
    }
    if (value2 == null || value3 == null) {
        return true;
    }
    if (value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain) || value3.isUnfoldable(timestamp, expectedValue, referenceChain) || value4.isUnfoldable(timestamp, expectedValue, referenceChain)) {
        return true;
    }
    value1.setLoweridToReference(timestamp);
    final Type_type tempType = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            return false;
        default:
            return true;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 88 with Type_type

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

the class ReplaceExpression 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) {
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    Type_type tempType1 = null;
    IValue value1 = null;
    if (templateInstance1 != null) {
        final ITTCN3Template temp = templateInstance1.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                break;
            case TEMPLATE_LIST:
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR13);
                setIsErroneous(true);
                return;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
                setIsErroneous(true);
                return;
        }
        // temp is specific value:
        value1 = ((SpecificValue_Template) temp).getSpecificValue();
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType1) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value1.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        final Type_type tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
                    if (((Integer_Value) last2).isNative()) {
                        final long i = ((Integer_Value) last2).getValue();
                        if (i < 0) {
                            value2.getLocation().reportSemanticError(OPERANDERROR3);
                            setIsErroneous(true);
                        }
                    } else {
                        value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR11, ((Integer_Value) last2).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value2.getLocation().reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        value3.setLoweridToReference(timestamp);
        final Type_type tempType3 = value3.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
                    if (((Integer_Value) last3).isNative()) {
                        final long i = ((Integer_Value) last3).getValue();
                        if (i < 0) {
                            value3.getLocation().reportSemanticError(OPERANDERROR4);
                            setIsErroneous(true);
                        }
                    } else {
                        value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR12, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value3.getLocation().reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    Type_type tempType4 = null;
    IValue value4 = null;
    if (templateInstance4 != null) {
        final ITTCN3Template temp = templateInstance4.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                value4 = ((SpecificValue_Template) temp).getSpecificValue();
                break;
            case TEMPLATE_LIST:
                if (!((Template_List) temp).isValue(timestamp)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                    setIsErroneous(true);
                    return;
                }
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                tempType4 = templateInstance4.getExpressionReturntype(timestamp, expectedValue);
                if (Type_type.TYPE_UNDEFINED.equals(tempType4)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR13);
                }
                return;
            default:
                templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                return;
        }
        value4.setLoweridToReference(timestamp);
        tempType4 = value4.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType4) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value4.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                break;
        }
    }
    if (tempType1 != null && tempType4 != null && !tempType1.equals(tempType4) && !getIsErroneous(timestamp)) {
        location.reportSemanticError(OPERANDERROR7);
        setIsErroneous(true);
    }
    checkExpressionOperandsHelper(timestamp, value1, expectedValue, referenceChain);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) 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) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 89 with Type_type

use of org.eclipse.titan.designer.AST.IType.Type_type 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)

Example 90 with Type_type

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

the class RotateLeftExpression method getExpressionReturntype.

@Override
public /**
 * {@inheritDoc}
 */
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IValue last = getValueRefdLast(timestamp, expectedValue, null);
    if (last == null || value1 == null) {
        return Type_type.TYPE_UNDEFINED;
    }
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return Type_type.TYPE_UNDEFINED;
    }
    value1.setLoweridToReference(timestamp);
    final Type_type tempType = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
        case TYPE_SET_OF:
        case TYPE_SEQUENCE_OF:
        case TYPE_ARRAY:
            return tempType;
        case TYPE_UNDEFINED:
            return tempType;
        default:
            setIsErroneous(true);
            return Type_type.TYPE_UNDEFINED;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Aggregations

Type_type (org.eclipse.titan.designer.AST.IType.Type_type)130 IValue (org.eclipse.titan.designer.AST.IValue)79 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)19 IType (org.eclipse.titan.designer.AST.IType)13 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)9 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)9 Assignment (org.eclipse.titan.designer.AST.Assignment)7 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)7 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)3 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)3 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)3 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)3 SetOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)3 Module (org.eclipse.titan.designer.AST.Module)2