Search in sources :

Example 6 with IType

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

the class RegexpExpression 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;
    setIsErroneous(false);
    if (templateInstance1 != null) {
        IType governor1 = templateInstance1.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template template = templateInstance1.getTemplateBody();
        if (governor1 == null) {
            template = template.setLoweridToReference(timestamp);
            governor1 = template.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor1 == null) {
            if (!template.getIsErroneous(timestamp)) {
                templateInstance1.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance1, governor1, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        final ITTCN3Template temp = template.setLoweridToReference(timestamp);
        temp.checkSpecificValue(timestamp, false);
        switch(governor1.getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (templateInstance2 != null) {
        IType governor2 = templateInstance2.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template temp = templateInstance2.getTemplateBody();
        if (governor2 == null) {
            temp = temp.setLoweridToReference(timestamp);
            governor2 = temp.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor2 == null) {
            if (!temp.getIsErroneous(timestamp)) {
                templateInstance2.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance2, governor2, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        switch(governor2.getTypeRefdLast(timestamp).getTypetype()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        final IValue temp = value3.setLoweridToReference(timestamp);
        final Type_type tempType3 = temp.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = temp.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(OPERANDERROR5, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR3);
                setIsErroneous(true);
                break;
        }
    }
// TODO add regexp specific checks once patterns become
// supported
}
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) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with IType

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

the class RegexpExpression method getExpressionGovernor.

@Override
public /**
 * {@inheritDoc}
 */
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IType governor = super.getMyGovernor();
    if (governor != null) {
        return governor;
    }
    if (templateInstance1 == null) {
        return null;
    }
    IType tempType;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        tempType = templateInstance1.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    } else {
        tempType = templateInstance1.getExpressionGovernor(timestamp, expectedValue);
    }
    if (tempType != null) {
        tempType = tempType.getTypeRefdLast(timestamp);
    }
    return tempType;
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 8 with IType

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

the class ReplaceExpression method getExpressionGovernor.

@Override
public /**
 * {@inheritDoc}
 */
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IType governor = super.getMyGovernor();
    if (governor != null) {
        return governor;
    }
    if (templateInstance1 == null) {
        return null;
    }
    IType tempType;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        tempType = templateInstance1.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    } else {
        tempType = templateInstance1.getExpressionGovernor(timestamp, expectedValue);
    }
    if (tempType != null) {
        tempType = tempType.getTypeRefdLast(timestamp);
    }
    return tempType;
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 9 with IType

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

the class IsValueExpression 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 referenceChain
 *                the referencechain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
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;
    IType governor = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (governor == null) {
        template = template.setLoweridToReference(timestamp);
        governor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (governor == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance.getLocation().reportSemanticError(OPERANDERROR);
        }
        setIsErroneous(true);
    } else {
        templateInstance.getExpressionReturntype(timestamp, internalExpectation);
        checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) IType(org.eclipse.titan.designer.AST.IType)

Example 10 with IType

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

the class LessThanExpression 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 (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) < 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() < ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)414 IValue (org.eclipse.titan.designer.AST.IValue)94 ISubReference (org.eclipse.titan.designer.AST.ISubReference)82 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)65 Identifier (org.eclipse.titan.designer.AST.Identifier)49 Assignment (org.eclipse.titan.designer.AST.Assignment)40 Value (org.eclipse.titan.designer.AST.Value)34 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)21 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)21 Reference (org.eclipse.titan.designer.AST.Reference)21 Type (org.eclipse.titan.designer.AST.Type)20 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)18 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)17 ArrayList (java.util.ArrayList)16 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)15 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)13