Search in sources :

Example 36 with TemplateInstance

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

the class FormalParameterList method setGenName.

public void setGenName(final String prefix) {
    for (final FormalParameter parameter : parameters) {
        final String parameterName = parameter.getIdentifier().getName();
        if (!Assignment_type.A_TIMER.equals(parameter.getAssignmentType())) {
            final Type parameterType = parameter.getType(CompilationTimeStamp.getBaseTimestamp());
            if (parameterType != null) {
                parameterType.setGenName(prefix, parameterName);
            }
        }
        if (parameter.hasDefaultValue()) {
            final StringBuilder embeddedName = new StringBuilder(prefix);
            embeddedName.append('_');
            embeddedName.append(parameterName);
            embeddedName.append("_defval");
            final ActualParameter defaultValue = parameter.getDefaultValue();
            if (defaultValue instanceof Value_ActualParameter) {
                final IValue value = ((Value_ActualParameter) defaultValue).getValue();
                // value.setGenNamePrefix("const_");//currently does not need the prefix
                value.setGenNameRecursive(embeddedName.toString());
            } else if (defaultValue instanceof Template_ActualParameter) {
                final TemplateInstance instance = ((Template_ActualParameter) defaultValue).getTemplateInstance();
                final TTCN3Template template = instance.getTemplateBody();
                // template.setGenNamePrefix("template_");//currently does not need the prefix
                template.setGenNameRecursive(embeddedName.toString());
            }
        }
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 37 with TemplateInstance

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

the class ValueofExpression 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 (templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType governor = myGovernor;
    if (governor == null) {
        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);
        return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, governor, referenceChain, expectedValue);
    if (getIsErroneous(timestamp)) {
        return;
    }
    templateInstance.getTemplateBody().checkSpecificValue(timestamp, false);
}
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 38 with TemplateInstance

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

the class ExpressionUtilities method checkExpressionOperatorCompatibilityInternal.

// the same as the previous but the last arg is template
private static void checkExpressionOperatorCompatibilityInternal(final CompilationTimeStamp timestamp, final Expression_Value expression, final IReferenceChain referenceChain, final Expected_Value_type expectedValue, final IValue param1, final TemplateInstance param2) {
    if (expression == null || param1 == null || param2 == null) {
        return;
    }
    if (param1.getIsErroneous(timestamp) || param2.getTemplateBody().getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    IValue operand1 = param1;
    final TemplateInstance operand2 = param2;
    final Type_type tempType1 = operand1.getExpressionReturntype(timestamp, expectedValue);
    final Type_type tempType2 = operand2.getExpressionReturntype(timestamp, expectedValue);
    ITTCN3Template temp2 = operand2.getTemplateBody();
    if (Type_type.TYPE_UNDEFINED.equals(tempType1)) {
        if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype())) {
                if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                    final Scope scope = expression.getMyScope();
                    final Module module = scope.getModuleScope();
                    final Identifier identifier = ((Undefined_LowerIdentifier_Value) operand1).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier) || module.hasImportedAssignmentWithID(timestamp, identifier)) {
                        operand1 = operand1.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                    final Identifier identifier2 = ((Undefined_LowerIdentifier_Value) ((SpecificValue_Template) temp2).getSpecificValue()).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier2) || module.hasImportedAssignmentWithID(timestamp, identifier2)) {
                        temp2 = temp2.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                } else {
                    operand1 = operand1.setLoweridToReference(timestamp);
                    checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                    return;
                }
            } else if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                temp2 = temp2.setLoweridToReference(timestamp);
                // To avoid infinite loop:
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
            if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
                return;
            }
            expression.getLocation().reportSemanticError(UNDETERMINABLEOPERANDSERROR);
            expression.setIsErroneous(true);
            return;
        }
        if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType2)) {
            operand1 = operand1.setLoweridToReference(timestamp);
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
            return;
        }
    } else if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
        if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType1)) {
            temp2 = temp2.setLoweridToReference(timestamp);
            // To avoid infinite loop:
            final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
            if (operand2 == tempTemplateInstance2) {
                return;
            }
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
            return;
        }
    }
    final IType type1 = operand1.getExpressionGovernor(timestamp, expectedValue);
    final IType type2 = operand2.getExpressionGovernor(timestamp, expectedValue);
    if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    if (type1 != null) {
        if (type2 != null) {
            final TypeCompatibilityInfo info1 = new TypeCompatibilityInfo(type1, type2, true);
            final TypeCompatibilityInfo info2 = new TypeCompatibilityInfo(type2, type1, true);
            final boolean retVal1 = type1.isCompatible(timestamp, type2, info1, null, null);
            final boolean retVal2 = type2.isCompatible(timestamp, type1, info2, null, null);
            if (!retVal1 && !retVal2) {
                expression.getLocation().reportSemanticError(info1.toString());
                expression.setIsErroneous(true);
                return;
            }
            if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
                if (info1.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type1.getTypename(), type2.getTypename()));
                } else if (info2.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type2.getTypename(), type1.getTypename()));
                }
            }
        } else {
            temp2.setMyGovernor(type1);
            final ITTCN3Template tempValue = type1.checkThisTemplateRef(timestamp, temp2);
            if (Template_type.OMIT_VALUE.equals(temp2.getTemplatetype()) || (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.OMIT_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()))) {
                operand1.checkExpressionOmitComparison(timestamp, expectedValue);
            } else {
                type1.checkThisTemplate(timestamp, tempValue, false, false, null);
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) tempValue);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
        }
    } else if (type2 != null) {
        operand1.setMyGovernor(type2);
        final IValue tempValue = type2.checkThisValueRef(timestamp, operand1);
        if (Value_type.OMIT_VALUE.equals(operand1.getValuetype())) {
        // temp2.check_expression_omit_comparison(timestamp,
        // expectedValue); ???
        } else {
            type2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, tempValue, operand2);
            return;
        }
    } else {
        if (Type_type.TYPE_UNDEFINED.equals(tempType1) || Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            expression.getLocation().reportSemanticError(PLEASEUSEREFERENCES);
            expression.setIsErroneous(true);
            return;
        }
        if (!Type.isCompatible(timestamp, tempType1, tempType2, false, false) && !Type.isCompatible(timestamp, tempType2, tempType1, false, false)) {
            expression.getLocation().reportSemanticError(INCOMPATIBLEOPERANDERROR);
            expression.setIsErroneous(true);
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Scope(org.eclipse.titan.designer.AST.Scope) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 39 with TemplateInstance

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

the class IsTemplateKindExpression method checkExpressionOperand1.

/**
 * Checks the 1st operand
 * in template (value) any_type
 * @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance == null) {
        setIsErroneous(true);
        return;
    }
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    IType type = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
    ITTCN3Template template = templateInstance.getTemplateBody();
    if (type == null) {
        template = template.setLoweridToReference(timestamp);
        type = template.getExpressionGovernor(timestamp, internalExpectation);
    }
    if (type == null) {
        if (!template.getIsErroneous(timestamp)) {
            templateInstance.getLocation().reportSemanticError(OPERAND1_ERROR1);
        }
        setIsErroneous(true);
        return;
    }
    IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, type, referenceChain, expectedValue);
    if (getIsErroneous(timestamp)) {
        return;
    }
    template.checkSpecificValue(timestamp, false);
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_UNDEFINED:
        case TYPE_NULL:
        case TYPE_REFERENCED:
        case TYPE_VERDICT:
        case TYPE_PORT:
        case TYPE_COMPONENT:
        case TYPE_DEFAULT:
        case TYPE_SIGNATURE:
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (!isErroneous) {
                location.reportSemanticError(OPERAND1_ERROR2);
                setIsErroneous(true);
            }
            break;
        default:
            break;
    }
}
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 40 with TemplateInstance

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

the class IsValueExpression 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 (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody();
    boolean isSingleValue = templateInstance.getDerivedReference() == null && template.isValue(timestamp);
    if (isSingleValue) {
        final IValue other = template.getValue();
        isSingleValue = other.evaluateIsvalue(false);
    }
    lastValue = new Boolean_Value(isSingleValue);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)29 IType (org.eclipse.titan.designer.AST.IType)26 IValue (org.eclipse.titan.designer.AST.IValue)16 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)13 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)13 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)10 Reference (org.eclipse.titan.designer.AST.Reference)9 Assignment (org.eclipse.titan.designer.AST.Assignment)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)8 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 Template (org.eclipse.jface.text.templates.Template)6 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)5 Port_Type (org.eclipse.titan.designer.AST.TTCN3.types.Port_Type)5 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)5 Type (org.eclipse.titan.designer.AST.Type)5 PortTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody)4 Signature_Type (org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type)4 TypeSet (org.eclipse.titan.designer.AST.TTCN3.types.TypeSet)4 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)3