Search in sources :

Example 51 with ITTCN3Template

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

the class DecodeExpression method checkFirstExpressionOperand.

private void checkFirstExpressionOperand(final CompilationTimeStamp timestamp) {
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue'' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format("Specific value template was expected instead of `{0}''", last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    if (temporalType.getTypeRefdLast(timestamp).getTypetype() != Type_type.TYPE_BITSTRING) {
        if (!isErroneous) {
            reference1.getLocation().reportSemanticError(OPERANDERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 52 with ITTCN3Template

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

the class Return_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    genRestrictionCheck = false;
    final Definition definition = myStatementBlock.getMyDefinition();
    if (definition == null) {
        location.reportSemanticError(USAGEINCONTROLPART);
        return;
    }
    switch(definition.getAssignmentType()) {
        case A_FUNCTION:
            if (template != null) {
                template.getLocation().reportSemanticError(UNEXPECTEDRETURNVALUE);
            }
            break;
        case A_FUNCTION_RVAL:
            final Type returnType = ((Def_Function) definition).getType(timestamp);
            if (template == null) {
                location.reportSemanticError(MessageFormat.format(MISSINGVALUE, returnType.getTypename()));
                break;
            }
            if (!template.isValue(timestamp)) {
                template.getLocation().reportSemanticError(SPECIFICVALUEEXPECTED);
                break;
            }
            // General:
            template.setMyGovernor(returnType);
            final IValue value = template.getValue();
            if (value != null) {
                value.setMyGovernor(returnType);
                returnType.checkThisValueRef(timestamp, value);
                returnType.checkThisValue(timestamp, value, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
            }
            break;
        case A_FUNCTION_RTEMP:
            if (template == null) {
                location.reportSemanticError(MessageFormat.format(MISSINGTEMPLATE, ((Def_Function) definition).getType(timestamp).getTypename()));
            } else {
                final Type returnType1 = ((Def_Function) definition).getType(timestamp);
                template.setMyGovernor(returnType1);
                final ITTCN3Template temporalTemplate1 = returnType1.checkThisTemplateRef(timestamp, template, Expected_Value_type.EXPECTED_TEMPLATE, null);
                temporalTemplate1.checkThisTemplateGeneric(timestamp, returnType1, true, /* isModified */
                true, /* allowOmit */
                true, /* allowAnyOrOmit */
                true, /* subCheck */
                true, /* implicitOmit */
                null);
                genRestrictionCheck = TemplateRestriction.check(timestamp, definition, temporalTemplate1, null);
            }
            break;
        case A_ALTSTEP:
            if (template != null) {
                template.getLocation().reportSemanticError(ALTSTEPRETURNINGVALUE);
            }
            break;
        default:
            location.reportSemanticError(MessageFormat.format(UNEXPETEDRETURNSTATEMENT, definition.getAssignmentName()));
            break;
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Type(org.eclipse.titan.designer.AST.Type) IValue(org.eclipse.titan.designer.AST.IValue) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 53 with ITTCN3Template

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

the class Port_Utility method getOutgoingType.

/**
 * Calculates the type of a template instance when it was to be used as
 * a parameter of a send statement.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check.
 * @param templateInstance
 *                the template instance whose type needs to be
 *                calculated.
 *
 * @return the the type of a template instance when it was to be used as
 *         a parameter of a sending statement
 */
public static IType getOutgoingType(final CompilationTimeStamp timestamp, final TemplateInstance templateInstance) {
    final IType result = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (result != null) {
        return result.getTypeRefdLast(timestamp);
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    template = template.setLoweridToReference(timestamp);
    return template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IType(org.eclipse.titan.designer.AST.IType)

Example 54 with ITTCN3Template

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

the class Port_Utility method getIncomingType.

/**
 * Calculates the type of a template instance when it was to be used as
 * a parameter of a receiving statement (receive / trigger /
 * check-receive).
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param templateInstance
 *                the template instance whose type needs to be
 *                calculated.
 * @param valueRedirect
 *                the value redirect of the receiving statement to help
 *                the identification of the type.
 * @param valueRedirectChecked
 *                after the function executed this will store whether
 *                the execution has called the checking of value
 *                redirect. This has to be an array of 1 in length.
 *
 * @return the the type of a template instance when it was to be used as
 *         a parameter of a receiving statement
 */
public static IType getIncomingType(final CompilationTimeStamp timestamp, final TemplateInstance templateInstance, final Reference valueRedirect, final boolean[] valueRedirectChecked) {
    IType result = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (result != null) {
        return result;
    }
    result = checkValueRedirect(timestamp, valueRedirect, null);
    valueRedirectChecked[0] = true;
    if (result != null) {
        return result;
    }
    final ITTCN3Template template = templateInstance.getTemplateBody();
    final ITTCN3Template temp = template.setLoweridToReference(timestamp);
    return temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IType(org.eclipse.titan.designer.AST.IType)

Example 55 with ITTCN3Template

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

the class All_From_Template method checkThisTemplateParameterizedReference.

private boolean checkThisTemplateParameterizedReference(final Reference reference, final Assignment lhs) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.isEmpty() || !(subreferences.get(0) instanceof ParameterisedSubReference)) {
        return false;
    }
    final ParameterisedSubReference subReference = (ParameterisedSubReference) subreferences.get(0);
    final ActualParameterList actualParameterList = subReference.getActualParameters();
    if (actualParameterList == null) {
        return false;
    }
    final int nofParameters = actualParameterList.getNofParameters();
    for (int i = 0; i < nofParameters; i++) {
        Reference parameterReference = null;
        final ActualParameter actualParameter = actualParameterList.getParameter(i);
        if (actualParameter instanceof Template_ActualParameter) {
            TemplateInstance templateInstance = ((Template_ActualParameter) actualParameter).getTemplateInstance();
            ITTCN3Template template = templateInstance.getTemplateBody();
            template = template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
            if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
                parameterReference = ((Referenced_Template) template).getReference();
            }
        } else if (actualParameter instanceof Referenced_ActualParameter) {
            parameterReference = ((Referenced_ActualParameter) actualParameter).getReference();
        }
        if (parameterReference != null) {
            final Assignment assignment = parameterReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            if (assignment == lhs) {
                return true;
            }
            // check their parameters as well
            switch(assignment.getAssignmentType()) {
                case A_TEMPLATE:
                case A_FUNCTION_RVAL:
                case A_FUNCTION_RTEMP:
                case A_EXT_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RTEMP:
                    if (checkThisTemplateParameterizedReference(parameterReference, lhs)) {
                        return true;
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter) Template_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Template_ActualParameter) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Referenced_ActualParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.Referenced_ActualParameter)

Aggregations

ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)67 IType (org.eclipse.titan.designer.AST.IType)42 IValue (org.eclipse.titan.designer.AST.IValue)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)19 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)19 Assignment (org.eclipse.titan.designer.AST.Assignment)17 Type (org.eclipse.titan.designer.AST.Type)13 ISubReference (org.eclipse.titan.designer.AST.ISubReference)12 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)12 Identifier (org.eclipse.titan.designer.AST.Identifier)12 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)12 Reference (org.eclipse.titan.designer.AST.Reference)10 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)8 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)7 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)6 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)6 HashMap (java.util.HashMap)5 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)5