Search in sources :

Example 61 with Assignment

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

the class TemplateInstance method checkRestriction.

/**
 * Checks the template restriction applied to a template.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param definition
 *                the definition to check.
 *
 * @return true if the restriction needs runtime check, false otherwise.
 */
public boolean checkRestriction(final CompilationTimeStamp timestamp, final Definition definition) {
    boolean needsRuntimeCheck = false;
    if (derivedReference != null) {
        final Assignment ass = derivedReference.getRefdAssignment(timestamp, true);
        switch(ass.getAssignmentType()) {
            case A_TEMPLATE:
            case A_VAR_TEMPLATE:
                needsRuntimeCheck = TemplateRestriction.check(timestamp, definition, templateBody, null);
                break;
            // case A_VAR_TEMPLATE:
            case A_EXT_FUNCTION_RTEMP:
            case A_FUNCTION_RTEMP:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
                // create a temporary Referenced_Template to be
                // added as the
                // base template than check and remove after
                // checked
                final Referenced_Template temp = new Referenced_Template(derivedReference);
                temp.setLocation(derivedReference.getLocation());
                templateBody.setBaseTemplate(temp);
                needsRuntimeCheck = TemplateRestriction.check(timestamp, definition, templateBody, null);
                templateBody.setBaseTemplate(null);
                break;
            default:
                break;
        }
    } else {
        needsRuntimeCheck = TemplateRestriction.check(timestamp, definition, templateBody, null);
    }
    return needsRuntimeCheck;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment)

Example 62 with Assignment

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

the class ValueList_Template method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    aData.addBuiltinTypeImport("Base_Template.template_sel");
    final ArrayList<Integer> variables = new ArrayList<Integer>();
    long fixedPart = 0;
    for (int i = 0; i < templates.getNofTemplates(); i++) {
        final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
        if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
            variables.add(i);
        } else {
            fixedPart++;
        }
    }
    final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
    if (variables.size() > 0) {
        final StringBuilder preamble = new StringBuilder();
        final StringBuilder setType = new StringBuilder();
        final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
        setType.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1}", name, fixedPart));
        for (int v = 0; v < variables.size(); v++) {
            TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
            // the template must be all from
            if (template instanceof All_From_Template) {
                template = ((All_From_Template) template).getAllFrom();
            }
            final Reference reference = ((SpecificValue_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            setType.append(" + ");
            final ExpressionStruct expression = new ExpressionStruct();
            reference.generateCode(aData, expression);
            if (expression.preamble.length() > 0) {
                preamble.append(expression.preamble);
            }
            switch(assignment.getAssignmentType()) {
                case A_CONST:
                case A_EXT_CONST:
                case A_MODULEPAR:
                case A_VAR:
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                case A_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RVAL:
                    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
                        expression.expression.append(".get()");
                    }
                    break;
                default:
                    break;
            }
            variableReferences[variables.get(v)] = expression.expression;
            setType.append(expression.expression);
            setType.append(".n_elem().getInt()");
        }
        source.append(preamble);
        source.append(setType);
        source.append(");\n");
        final StringBuilder shifty = new StringBuilder();
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            switch(template.getTemplatetype()) {
                case ALL_FROM:
                    {
                        // the template must be all from
                        final StringBuilder storedExpression = variableReferences[i];
                        source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
                        final String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
                        ((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
                        source.append("}\n");
                        shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
                        break;
                    }
                default:
                    if (template.needsTemporaryReference()) {
                        final String tempId = aData.getTemporaryVariableName();
                        source.append("{\n");
                        source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
                        template.generateCodeInit(aData, source, tempId);
                        source.append("}\n");
                    } else {
                        final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
                        template.generateCodeInit(aData, source, embeddedName);
                    }
                    break;
            }
        }
    } else {
        source.append(MessageFormat.format("{0}.setType(template_sel.VALUE_LIST, {1});\n", name, templates.getNofTemplates()));
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            if (template.needsTemporaryReference()) {
                final String tempId = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
                template.generateCodeInit(aData, source, tempId);
                source.append("}\n");
            } else {
                final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
                template.generateCodeInit(aData, source, embeddedName);
            }
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignment(org.eclipse.titan.designer.AST.Assignment) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 63 with Assignment

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

the class Component_Type method checkExpressionOperandComponentRefernce.

/**
 * Checks if the provided value is a reference to a component or not.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expected_value the value kind expected from the actual parameter.
 */
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
    switch(value.getValuetype()) {
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IValue last = value.getValueRefdLast(timestamp, chain);
                    chain.release();
                    if (last == null || last.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        return;
                    }
                    IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    if (type == null) {
                        value.setIsErroneous(true);
                        return;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        // don't let spread an earlier mistake
                        return;
                    }
                    if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                        value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                        value.setIsErroneous(true);
                        return;
                    }
                }
                break;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, true);
                if (assignment == null) {
                    value.setIsErroneous(true);
                    return;
                }
                switch(assignment.getAssignmentType()) {
                    case A_CONST:
                        {
                            IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            IValue tempValue = ((Def_Const) assignment).getValue();
                            if (tempValue == null) {
                                return;
                            }
                            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
                            chain.release();
                            if (tempValue == null) {
                                return;
                            }
                            chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getValueRefdLast(timestamp, chain);
                            chain.release();
                            if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                value.setIsErroneous(true);
                                return;
                            }
                            if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
                                return;
                            }
                            switch(((Expression_Value) tempValue).getOperationType()) {
                                case MTC_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case COMPONENT_NULL_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case SYSTEM_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                default:
                                    break;
                            }
                            break;
                        }
                    case A_EXT_CONST:
                        {
                            IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_MODULEPAR:
                        {
                            IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_VAR:
                        {
                            IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_EXT_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_PAR_VAL:
                    case A_PAR_VAL_IN:
                    case A_PAR_VAL_OUT:
                    case A_PAR_VAL_INOUT:
                        {
                            IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    default:
                        reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
                        value.setIsErroneous(true);
                        return;
                }
                break;
            }
        default:
            // the error was already reported if possible.
            return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 64 with Assignment

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

the class EnumItem method getDeclaration.

@Override
public /**
 * {@inheritDoc}
 */
Declaration getDeclaration() {
    if (getMyScope() == null) {
        return null;
    }
    final Module module = getMyScope().getModuleScope();
    final Assignment assignment = module.getEnclosingAssignment(getLocation().getOffset());
    final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
    if (type instanceof ITypeWithComponents) {
        final Identifier id = ((ITypeWithComponents) type).getComponentIdentifierByName(getId());
        return Declaration.createInstance(assignment, id);
    }
    return null;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) ITypeWithComponents(org.eclipse.titan.designer.AST.ITypeWithComponents) Module(org.eclipse.titan.designer.AST.Module) IType(org.eclipse.titan.designer.AST.IType)

Example 65 with Assignment

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

the class Function_Type method checkThisValue.

@Override
public /**
 * {@inheritDoc}
 */
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
    final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
    final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
    if (last == null || last.getIsErroneous(timestamp)) {
        return selfReference;
    }
    last.setMyGovernor(this);
    // already handled ones
    switch(value.getValuetype()) {
        case OMIT_VALUE:
        case REFERENCED_VALUE:
            return selfReference;
        case UNDEFINED_LOWERIDENTIFIER_VALUE:
            if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
                return selfReference;
            }
            break;
        default:
            break;
    }
    Assignment assignment = null;
    switch(last.getValuetype()) {
        case FUNCTION_REFERENCE_VALUE:
            assignment = ((Function_Reference_Value) last).getReferredFunction();
            if (assignment == null) {
                value.setIsErroneous(true);
                return selfReference;
            }
            assignment.check(timestamp);
            break;
        case TTCN3_NULL_VALUE:
            value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
            return selfReference;
        case EXPRESSION_VALUE:
        case MACRO_VALUE:
            // already checked
            return selfReference;
        default:
            value.getLocation().reportSemanticError(FUNCTIONREFERENCEVALUEEXPECTED);
            value.setIsErroneous(true);
            return selfReference;
    }
    // external functions do not have runs on clauses
    if (assignment instanceof Def_Function) {
        formalParList.checkCompatibility(timestamp, ((Def_Function) assignment).getFormalParameterList(), value.getLocation());
        final IType tempRunsOnType = ((Def_Function) assignment).getRunsOnType(timestamp);
        if (tempRunsOnType != null) {
            if (runsOnSelf) {
                // check against the runs on component type of the scope of the value
                final Scope valueScope = value.getMyScope();
                if (valueScope == null) {
                    value.setIsErroneous(true);
                    value.setLastTimeChecked(timestamp);
                    return selfReference;
                }
                final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
                if (runsOnScope != null) {
                    final Component_Type componentType = runsOnScope.getComponentType();
                    if (!tempRunsOnType.isCompatible(timestamp, componentType, null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope expects " + "component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
                    }
                } else {
                    // compatibility using this component type as the scope
                    if (valueScope instanceof ComponentTypeBody) {
                        final ComponentTypeBody body = (ComponentTypeBody) valueScope;
                        if (!tempRunsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current component definition " + "is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' " + "clause and the current scope does not have a `runs on'' clause, but {1} runs on `{2}''", getTypename(), assignment.getDescription(), tempRunsOnType.getTypename()));
                    }
                }
            } else {
                if (runsOnRef == null) {
                    value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
                    value.setIsErroneous(true);
                } else {
                    if (runsOnType != null && !tempRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
                        value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), assignment.getAssignmentName(), tempRunsOnType.getTypename()));
                        value.setIsErroneous(true);
                    }
                }
            }
        }
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            if (returnType != null) {
                value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a {1} of type `{2}'', but {3} does not have a return type", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription()));
            }
            break;
        case A_FUNCTION_RTEMP:
            {
                final Restriction_type restriction = ((Def_Function) assignment).getTemplateRestriction();
                if (!templateRestriction.equals(restriction)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
                }
                if (returnType != null) {
                    final IType tempReturnType = assignment.getType(timestamp);
                    if (!returnType.isIdentical(timestamp, tempReturnType)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                    } else if (!returnsTemplate) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
                }
                break;
            }
        case A_EXT_FUNCTION_RTEMP:
            {
                final Restriction_type restriction = ((Def_Extfunction) assignment).getTemplateRestriction();
                if (!templateRestriction.equals(restriction)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template with {1} restriction, " + "but {2} returns a template with {3} restriction", getTypename(), Restriction_type.TR_NONE.equals(templateRestriction) ? "no" : templateRestriction.getDisplayName(), assignment.getDescription(), Restriction_type.TR_NONE.equals(restriction) ? "no" : restriction.getDisplayName()));
                }
                if (returnType != null) {
                    final IType tempReturnType = assignment.getType(timestamp);
                    if (!returnType.isIdentical(timestamp, tempReturnType)) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}'', " + "but {3} returns a template of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                    } else if (!returnsTemplate) {
                        value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a value of type `{1}'', but {2} returns a template", getTypename(), returnType.getTypename(), assignment.getDescription()));
                    }
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a template of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
                }
                break;
            }
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
            if (returnType != null) {
                final IType tempReturnType = assignment.getType(timestamp);
                if (!returnType.isIdentical(timestamp, tempReturnType)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Return type mismatch: type `{0}'' expects a function or external function that returns a {1} of type `{2}''," + " but {3} returns a value of type `{3}''", getTypename(), returnsTemplate ? "template" : "value", returnType.getTypename(), assignment.getDescription(), tempReturnType.getTypename()));
                } else if (returnsTemplate) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function that returns a template of type `{1}'', but {2} returns a value", getTypename(), returnType.getTypename(), assignment.getDescription()));
                }
            } else {
                value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' expects a function or external function without return type, but {1} returns a value of type `{2}''", getTypename(), assignment.getDescription(), assignment.getType(timestamp).getTypename()));
            }
            break;
        default:
            break;
    }
    if (valueCheckingOptions.sub_check) {
        // there is no parent type to check
        if (subType != null) {
            subType.checkThisValue(timestamp, last);
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Scope(org.eclipse.titan.designer.AST.Scope) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) Restriction_type(org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)141 Reference (org.eclipse.titan.designer.AST.Reference)48 IType (org.eclipse.titan.designer.AST.IType)41 ISubReference (org.eclipse.titan.designer.AST.ISubReference)39 IValue (org.eclipse.titan.designer.AST.IValue)31 Identifier (org.eclipse.titan.designer.AST.Identifier)25 ArrayList (java.util.ArrayList)24 Module (org.eclipse.titan.designer.AST.Module)22 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)16 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)14 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)14 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)14 Assignments (org.eclipse.titan.designer.AST.Assignments)13 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 Location (org.eclipse.titan.designer.AST.Location)9 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)6