Search in sources :

Example 21 with ValueCheckingOptions

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

the class MatchExpression 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 || templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    if (value.getIsErroneous(timestamp) || templateInstance.getTemplateBody().getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    // Start
    IType localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    if (localGovernor == null) {
        localGovernor = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (localGovernor == null) {
        template = template.setLoweridToReference(timestamp);
        localGovernor = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (localGovernor == null) {
        // Start again:
        value.setLoweridToReference(timestamp);
        localGovernor = value.getExpressionGovernor(timestamp, expectedValue);
    }
    if (localGovernor == null) {
        if (!template.getIsErroneous(timestamp)) {
            getLocation().reportSemanticError("Cannot determine the type of arguments in `match()' operation");
        }
        setIsErroneous(true);
        return;
    }
    value.setMyGovernor(localGovernor);
    final IValue temporalValue = localGovernor.checkThisValueRef(timestamp, value);
    localGovernor.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
    // FIXME check value against governor
    template.checkThisTemplateGeneric(timestamp, localGovernor, templateInstance.getDerivedReference() != null, false, false, true, false, null);
    try {
        ExpressionUtilities.checkExpressionOperatorCompatibility(timestamp, this, referenceChain, Expected_Value_type.EXPECTED_TEMPLATE, value, templateInstance);
    } catch (StackOverflowError e) {
        ErrorReporter.logExceptionStackTrace("Stack overflow was detected while analysing `" + getFullName() + "'", e.getCause());
        getLocation().reportSemanticError("Titan was unable to analyse this statement");
        setIsErroneous(true);
    }
    if (getIsErroneous(timestamp)) {
        return;
    }
    value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    templateInstance.getTemplateBody().getTemplateReferencedLast(timestamp, referenceChain);
    templateInstance.check(timestamp, localGovernor);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 22 with ValueCheckingOptions

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

the class StringConcatenationExpression 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;
    boolean v1_string = false;
    boolean v2_string = false;
    if (value1 != null) {
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType1) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                v1_string = true;
                value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_SET_OF:
                value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                break;
            case TYPE_UNDEFINED:
                break;
            default:
                location.reportSemanticError(FIRSTOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                v2_string = true;
                value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_SET_OF:
                value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                break;
            case TYPE_UNDEFINED:
                break;
            default:
                location.reportSemanticError(SECONDOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value1 != null && value2 != null && !getIsErroneous(timestamp)) {
        if (value1.getIsErroneous(timestamp) || value2.getIsErroneous(timestamp)) {
            setIsErroneous(true);
            return;
        }
        if (v1_string && v2_string) {
            if (!((Type_type.TYPE_CHARSTRING.equals(tempType1) && Type_type.TYPE_UCHARSTRING.equals(tempType2)) || (Type_type.TYPE_CHARSTRING.equals(tempType2) && Type_type.TYPE_UCHARSTRING.equals(tempType1))) && tempType1 != tempType2) {
                location.reportSemanticError(SAMEOPERANDERROR);
                setIsErroneous(true);
            }
            return;
        }
        final IType v1_gov = value1.getExpressionGovernor(timestamp, expectedValue);
        IType v2_gov = value2.getExpressionGovernor(timestamp, expectedValue);
        if (v1_gov == null) {
            getLocation().reportSemanticError("Cannot determine the type of the left operand of `&' operation");
            setIsErroneous(true);
            return;
        } else {
            final IValue tempValue = v1_gov.checkThisValueRef(timestamp, value1);
            v1_gov.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, true, false, false));
        }
        if (v2_gov == null) {
            v2_gov = v1_gov;
            value2.setMyGovernor(v1_gov);
        }
        final IValue tempValue = v2_gov.checkThisValueRef(timestamp, value2);
        v2_gov.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, true, false, false));
        // 7.1.2 says that we shouldn't allow type compatibility.
        if (!v1_gov.isCompatible(timestamp, v2_gov, null, null, null) && !v2_gov.isCompatible(timestamp, v1_gov, null, null, null)) {
            getLocation().reportSemanticError("The operands of `&' operation should be of compatible types");
            setIsErroneous(true);
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 23 with ValueCheckingOptions

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

the class CompField method check.

/**
 * Does the semantic checking of this field.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 */
public void check(final CompilationTimeStamp timestamp) {
    if (type == null) {
        return;
    }
    type.check(timestamp);
    type.checkEmbedded(timestamp, type.getLocation(), true, "embedded into another type");
    if (defaultValue == null) {
        return;
    }
    defaultValue.setMyGovernor(type);
    final IType lastType = type.getTypeRefdLast(timestamp);
    final IValue tempValue = lastType.checkThisValueRef(timestamp, defaultValue);
    lastType.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, true, false, false));
    defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 24 with ValueCheckingOptions

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

the class SingleLenghtRestriction method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (value == null) {
        return;
    }
    final Integer_Type integer = new Integer_Type();
    value.setMyGovernor(integer);
    IValue last = integer.checkThisValueRef(timestamp, value);
    integer.checkThisValue(timestamp, last, null, new ValueCheckingOptions(expectedValue, false, false, true, false, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    last = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            {
                final BigInteger temp = ((Integer_Value) last).getValueValue();
                if (temp.compareTo(BigInteger.ZERO) == -1) {
                    value.getLocation().reportSemanticError(MessageFormat.format("The length restriction must be a non-negative integer value instead of {0}", temp));
                    value.setIsErroneous(true);
                }
                break;
            }
        default:
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) BigInteger(java.math.BigInteger) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Aggregations

ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)24 IValue (org.eclipse.titan.designer.AST.IValue)22 IType (org.eclipse.titan.designer.AST.IType)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)5 Reference (org.eclipse.titan.designer.AST.Reference)4 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)3 Identifier (org.eclipse.titan.designer.AST.Identifier)3 Module (org.eclipse.titan.designer.AST.Module)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 Scope (org.eclipse.titan.designer.AST.Scope)2 ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)2 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)2 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)2