Search in sources :

Example 21 with Expected_Value_type

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

the class IsBoundExpression method isUnfoldable.

@Override
public /**
 * {@inheritDoc}
 */
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance == null) {
        return true;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody().setLoweridToReference(timestamp);
    if (templateInstance.getDerivedReference() != null) {
        return true;
    }
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
        final IValue specificValue = ((SpecificValue_Template) template).getValue();
        if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
            final Reference reference = ((Referenced_Value) specificValue).getReference();
            final Assignment ass = reference.getRefdAssignment(timestamp, false);
            if (ass == null) {
                return true;
            }
            switch(ass.getAssignmentType()) {
                case A_OBJECT:
                case A_OS:
                case A_CONST:
                case A_EXT_CONST:
                case A_MODULEPAR:
                case A_VAR:
                case A_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RVAL:
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                    break;
                default:
                    return true;
            }
            // TODO improve to better detect unbound
            // elements
            final IValue last = specificValue.getValueRefdLast(timestamp, expectedValue, null);
            if (last == null) {
                return true;
            }
            if (last == this) {
                return getIsErroneous(timestamp);
            }
            return last.isUnfoldable(timestamp, expectedValue, referenceChain);
        }
        return specificValue.isUnfoldable(timestamp, expectedValue, referenceChain);
    } else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
        final Reference reference = ((Referenced_Template) template).getReference();
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (ass == null) {
            return true;
        }
        switch(ass.getAssignmentType()) {
            case A_TEMPLATE:
                break;
            default:
                return true;
        }
        // TODO improve to better detect unbound elements
        final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
        if (last == null) {
            return true;
        }
        if (last == template) {
            return last.getIsErroneous(timestamp);
        }
        if (Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
            return ((SpecificValue_Template) last).getValue().isUnfoldable(timestamp, expectedValue, referenceChain);
        }
    }
    return true;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 22 with Expected_Value_type

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

the class IsBoundExpression method checkExpressionTemplateInstance.

/**
 * Checks if the templateinstance parameter (which is a parameter of the
 * expression parameter) is actually a constant or static value or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expression
 *                the expression to report the possible errors to.
 * @param instance
 *                the template instance parameter of the expression to
 *                be checked.
 * @param type
 *                the type against which the template instance shall be
 *                checked.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
private static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
    Expected_Value_type internalExpectation;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectation = expectedValue;
    }
    final ITTCN3Template body = instance.getTemplateBody();
    if (Template_type.TEMPLATE_REFD.equals(body.getTemplatetype())) {
        ((Referenced_Template) body).getReference().setUsedInIsbound();
    } else if (Template_type.SPECIFIC_VALUE.equals(body.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) body).getValue();
        if (value != null && Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            ((Referenced_Value) value).getReference().setUsedInIsbound();
        }
    }
    instance.check(timestamp, type);
    if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
        if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
            instance.getLocation().reportSemanticError(CONSTEXPECTED1);
        } else {
            instance.getLocation().reportSemanticError(STATICEXPECTED1);
        }
        expression.setIsErroneous(true);
    }
    ITTCN3Template template = instance.getTemplateBody();
    if (template.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    switch(template.getTemplatetype()) {
        case TEMPLATE_REFD:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
                template = template.getTemplateReferencedLast(timestamp, referenceChain);
                if (template.getIsErroneous(timestamp)) {
                    expression.setIsErroneous(true);
                }
            } else {
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
                    instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                } else {
                    instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                }
                expression.setIsErroneous(true);
            }
            break;
        case SPECIFIC_VALUE:
            final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
            switch(tempValue.getValuetype()) {
                case REFERENCED_VALUE:
                    type.checkThisValueRef(timestamp, tempValue);
                    break;
                case EXPRESSION_VALUE:
                    tempValue.getValueRefdLast(timestamp, referenceChain);
                    break;
                default:
                    break;
            }
            if (tempValue.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
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) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 23 with Expected_Value_type

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

the class IsBoundExpression 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 reference chain 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);
    // setMyGovernor(governor);
    }
}
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 24 with Expected_Value_type

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

the class IsChoosenExpression 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 (reference == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (value == null) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    IValue last = value.getValueRefdLast(timestamp, referenceChain);
    boolean result;
    switch(last.getValuetype()) {
        case CHOICE_VALUE:
            result = ((Choice_Value) last).fieldIsChosen(identifier);
            break;
        case SEQUENCE_VALUE:
            last = last.setValuetype(timestamp, Value_type.CHOICE_VALUE);
            result = ((Choice_Value) last).fieldIsChosen(identifier);
            break;
        case ANYTYPE_VALUE:
            result = ((Anytype_Value) last).fieldIsChosen(timestamp, identifier);
            break;
        default:
            setIsErroneous(true);
            return last;
    }
    lastValue = new Boolean_Value(result);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Example 25 with Expected_Value_type

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

the class IsPresentExpression method checkExpressionTemplateInstance.

/**
 * Checks if the templateinstance parameter (which is a parameter of the
 * expression parameter) is actually a constant or static value or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expression
 *                the expression to report the possible errors to.
 * @param instance
 *                the template instance parameter of the expression to
 *                be checked.
 * @param type
 *                the type against which the template instance shall be
 *                checked.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
private static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
    Expected_Value_type internalExpectation;
    if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
        internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
    } else {
        internalExpectation = expectedValue;
    }
    final ITTCN3Template body = instance.getTemplateBody();
    if (Template_type.TEMPLATE_REFD.equals(body.getTemplatetype())) {
        // FIXME
        ((Referenced_Template) body).getReference().setUsedInIsbound();
    } else if (Template_type.SPECIFIC_VALUE.equals(body.getTemplatetype())) {
        final IValue value = ((SpecificValue_Template) body).getValue();
        if (value != null && Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
            // FIXME
            ((Referenced_Value) value).getReference().setUsedInIsbound();
        }
    }
    instance.check(timestamp, type);
    if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
        if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
            instance.getLocation().reportSemanticError(CONSTEXPECTED1);
        } else {
            instance.getLocation().reportSemanticError(STATICEXPECTED1);
        }
        expression.setIsErroneous(true);
    }
    ITTCN3Template template = instance.getTemplateBody();
    if (template.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    switch(template.getTemplatetype()) {
        case TEMPLATE_REFD:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
                template = template.getTemplateReferencedLast(timestamp, referenceChain);
                if (template.getIsErroneous(timestamp)) {
                    expression.setIsErroneous(true);
                }
            } else {
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
                    instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                } else {
                    instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
                }
                expression.setIsErroneous(true);
            }
            break;
        case SPECIFIC_VALUE:
            final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
            switch(tempValue.getValuetype()) {
                case REFERENCED_VALUE:
                    type.checkThisValueRef(timestamp, tempValue);
                    break;
                case EXPRESSION_VALUE:
                    tempValue.getValueRefdLast(timestamp, referenceChain);
                    break;
                default:
                    break;
            }
            if (tempValue.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
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) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)149 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)54 IType (org.eclipse.titan.designer.AST.IType)47 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)45 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)39 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)31 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)24 ISubReference (org.eclipse.titan.designer.AST.ISubReference)21 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)21 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)20 Identifier (org.eclipse.titan.designer.AST.Identifier)17 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)17 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)14 Type (org.eclipse.titan.designer.AST.Type)14 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Value (org.eclipse.titan.designer.AST.Value)11