Search in sources :

Example 11 with TemplateInstance

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

the class IsValueExpression 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 referencechain to detect circular references.
 * @param expectedValue
 *                the expected value of the template instance.
 */
public 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;
    }
    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)

Example 12 with TemplateInstance

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

the class EncodeExpression 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 the value to be 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 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(OPERANDERROR1);
        }
        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(OPERANDERROR2);
                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 13 with TemplateInstance

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

the class FormalParameter method checkActualParameterTimer.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a timer parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param expectedValue
 *                the value kind expected from the actual parameter.
 *
 * @return the actual parameter created from the value, or null if there
 *         was an error.
 */
private ActualParameter checkActualParameterTimer(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    final IType parameterType = actualParameter.getType();
    if (parameterType != null) {
        actualParameter.getLocation().reportSemanticError(EXPLICITESPECIFICATIONFORTIMER);
        actualParameter.checkType(timestamp, null);
    }
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(INLINETEMPLATEFORTIMER);
        actualParameter.checkDerivedReference(timestamp, null);
    }
    final ITTCN3Template template = actualParameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true, null);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        switch(assignment.getAssignmentType()) {
            case A_TIMER:
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, expectedValue);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
                }
                break;
            case A_PAR_TIMER:
                if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR2, assignment.getDescription()));
                }
                break;
            default:
                reference.getLocation().reportSemanticError(MessageFormat.format(TIMEREXPECTED1, assignment.getAssignmentName()));
                break;
        }
        return new Referenced_ActualParameter(reference);
    }
    actualParameter.getLocation().reportSemanticError(TIMEREXPECTED2);
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) IType(org.eclipse.titan.designer.AST.IType)

Example 14 with TemplateInstance

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

the class FormalParameterList method collateLazyAndNonLazyActualParameters.

/**
 * Read the parsed actual parameters, and collate the lazy and non-lazy actual parameters
 * according to their associated formal parameters.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parsedParameters
 *                the parsed actual parameters (may contain named, and unnamed parts too).
 * @param actualLazyParameters
 *                the list of actual lazy parameters returned for later usage.
 * @param actualNonLazyParameters
 *                the list of actual non lazy parameters returned for later usage.
 */
public final void collateLazyAndNonLazyActualParameters(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualLazyParameters, final ActualParameterList actualNonLazyParameters) {
    final TemplateInstances unnamed = parsedParameters.getInstances();
    final NamedParameters named = parsedParameters.getNamedParameters();
    int nofLocated = unnamed.getNofTis();
    final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
    }
    final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
    for (int i = 0, size = named.getNofParams(); i < size; i++) {
        final NamedParameter namedParameter = named.getParamByIndex(i);
        final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
        final int isAt = formalParameterMap.get(formalParameter);
        for (; nofLocated < isAt; nofLocated++) {
            final NotUsed_Template temp = new NotUsed_Template();
            if (!parameters.get(nofLocated).hasDefaultValue()) {
                temp.setIsErroneous(true);
            }
            final TemplateInstance instance = new TemplateInstance(null, null, temp);
            instance.setLocation(parsedParameters.getLocation());
            finalUnnamed.addTemplateInstance(instance);
        }
        finalUnnamed.addTemplateInstance(namedParameter.getInstance());
        nofLocated++;
    }
    finalUnnamed.setLocation(parsedParameters.getLocation());
    final int upperLimit = (finalUnnamed.getNofTis() < parameters.size()) ? finalUnnamed.getNofTis() : parameters.size();
    for (int i = 0; i < upperLimit; i++) {
        final TemplateInstance instance = finalUnnamed.getInstanceByIndex(i);
        final FormalParameter formalParameter = parameters.get(i);
        if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
            final ActualParameter defaultValue = formalParameter.getDefaultValue();
            final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
            if (defaultValue != null && !defaultValue.getIsErroneous()) {
                temp.setLocation(defaultValue.getLocation());
            }
            if (formalParameter.getIsLazy()) {
                actualLazyParameters.addParameter(temp);
            } else {
                actualNonLazyParameters.addParameter(temp);
            }
        } else {
            final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
            actualParameter.setLocation(instance.getLocation());
            if (formalParameter.getIsLazy()) {
                actualLazyParameters.addParameter(actualParameter);
            } else {
                actualNonLazyParameters.addParameter(actualParameter);
            }
        }
    }
    for (int i = upperLimit; i < parameters.size(); i++) {
        final FormalParameter formalParameter = parameters.get(i);
        final ActualParameter defaultValue = formalParameter.getDefaultValue();
        final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
        if (defaultValue != null && !defaultValue.getIsErroneous()) {
            temp.setLocation(defaultValue.getLocation());
        }
        if (formalParameter.getIsLazy()) {
            actualLazyParameters.addParameter(temp);
        } else {
            actualNonLazyParameters.addParameter(temp);
        }
    }
}
Also used : NamedParameters(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters) HashMap(java.util.HashMap) NamedParameter(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter) TemplateInstances(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances) NotUsed_Template(org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 15 with TemplateInstance

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

the class FormalParameterList method checkActualParameterList.

/**
 * Check if a list of parsed actual parameters is semantically correct
 * according to a list of formal parameters (the called entity).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parsedParameters
 *                the parsed actual parameters (may contain named, and
 *                unnamed parts too).
 * @param actualParameters
 *                the list of actual parameters returned for later
 *                usage.
 *
 * @return true if a semantic error was found, false otherwise
 */
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
    parsedParameters.setFormalParList(this);
    checkUniqueness(timestamp);
    boolean isErroneous = false;
    final TemplateInstances unnamed = parsedParameters.getInstances();
    final NamedParameters named = parsedParameters.getNamedParameters();
    int nofLocated = unnamed.getNofTis();
    final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
    }
    final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
    for (int i = 0, size = named.getNofParams(); i < size; i++) {
        final NamedParameter namedParameter = named.getParamByIndex(i);
        if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
            final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
            final int isAt = formalParameterMap.get(formalParameter);
            if (isAt >= nofLocated) {
                for (; nofLocated < isAt; nofLocated++) {
                    final NotUsed_Template temp = new NotUsed_Template();
                    if (!parameters.get(nofLocated).hasDefaultValue()) {
                        temp.setIsErroneous(true);
                    }
                    final TemplateInstance instance = new TemplateInstance(null, null, temp);
                    instance.setLocation(parsedParameters.getLocation());
                    finalUnnamed.addTemplateInstance(instance);
                }
                finalUnnamed.addTemplateInstance(namedParameter.getInstance());
                nofLocated++;
            } else {
                isErroneous = true;
                if (isAt >= unnamed.getNofTis()) {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
                } else {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
                }
            }
        } else {
            String name;
            switch(myDefinition.getAssignmentType()) {
                case A_TYPE:
                    switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
                        case TYPE_FUNCTION:
                            name = "Function reference";
                            break;
                        case TYPE_ALTSTEP:
                            name = "Altstep reference";
                            break;
                        case TYPE_TESTCASE:
                            name = "Testcase reference";
                            break;
                        default:
                            name = "";
                            break;
                    }
                    break;
                default:
                    name = myDefinition.getAssignmentName();
                    break;
            }
            isErroneous = true;
            namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
        }
    }
    if (isErroneous) {
        return false;
    }
    finalUnnamed.setLocation(parsedParameters.getLocation());
    return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
Also used : NamedParameters(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters) HashMap(java.util.HashMap) NamedParameter(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter) TemplateInstances(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances) NotUsed_Template(org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

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