Search in sources :

Example 46 with Type

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

the class TypeMappings method check.

/**
 * Does the semantic checking of the type mapping.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
public void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    mappingsMap.clear();
    for (int i = 0, size = mappings.size(); i < size; i++) {
        final TypeMapping mapping = mappings.get(i);
        mapping.check(timestamp);
        final Type sourceType = mapping.getSourceType();
        if (sourceType != null && !sourceType.getTypeRefdLast(timestamp).getIsErroneous(timestamp)) {
            final String sourceName = sourceType.getTypename();
            if (mappingsMap.containsKey(sourceName)) {
                sourceType.getLocation().reportSemanticError(MessageFormat.format("Duplicate mapping for type `{0}''", sourceName));
                final String message = MessageFormat.format("The mapping of the type `{0}'' is already given here", sourceName);
                mappingsMap.get(sourceName).getLocation().reportSemanticWarning(message);
            } else {
                mappingsMap.put(sourceName, mapping);
            }
        }
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType)

Example 47 with Type

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

the class RefersExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    if (governor == null || referredAssignment == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
        return;
    }
    final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    final String moduleName = referredAssignment.getMyScope().getModuleScope().getName();
    final String functionName = referredAssignment.getIdentifier().getName();
    expression.expression.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, expression.expression, myScope)));
    expression.expression.append("@Override\n");
    expression.expression.append("public String getModuleName() {\n");
    expression.expression.append(MessageFormat.format("return \"{0}\";\n", moduleName));
    expression.expression.append("}\n");
    expression.expression.append("@Override\n");
    expression.expression.append("public String getDefinitionName() {\n");
    expression.expression.append(MessageFormat.format("return \"{0}\";\n", functionName));
    expression.expression.append("}\n");
    if (lastGovernor.getTypetype().equals(Type_type.TYPE_FUNCTION)) {
        expression.expression.append("@Override\n");
        expression.expression.append("public ");
        final Function_Type functionType = (Function_Type) lastGovernor;
        final Type returnType = functionType.getReturnType();
        final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
        if (returnType == null) {
            expression.expression.append("void");
        } else {
            if (functionType.returnsTemplate()) {
                expression.expression.append(returnType.getGenNameTemplate(aData, expression.expression, myScope));
            } else {
                expression.expression.append(returnType.getGenNameValue(aData, expression.expression, myScope));
            }
        }
        expression.expression.append(" invoke(");
        functionType.getFormalParameters().generateCode(aData, expression.expression);
        expression.expression.append(") {\n");
        if (returnType != null) {
            expression.expression.append("return ");
        }
        expression.expression.append(referredAssignment.getIdentifier().getName());
        expression.expression.append('(');
        expression.expression.append(actualParList);
        expression.expression.append(");\n");
        expression.expression.append("}\n");
        if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
            aData.addBuiltinTypeImport("TitanComponent");
            expression.expression.append("@Override\n");
            expression.expression.append("public void start(final TitanComponent component_reference");
            if (functionType.getFormalParameters().getNofParameters() > 0) {
                expression.expression.append(", ");
                functionType.getFormalParameters().generateCode(aData, expression.expression);
            }
            expression.expression.append(") {\n");
            expression.expression.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
            if (actualParList != null && actualParList.length() > 0) {
                expression.expression.append(MessageFormat.format(", {0}", actualParList));
            }
            expression.expression.append(");\n");
            expression.expression.append("}\n");
        }
    } else if (lastGovernor.getTypetype().equals(Type_type.TYPE_ALTSTEP)) {
        aData.addBuiltinTypeImport("Default_Base");
        aData.addBuiltinTypeImport("TitanAlt_Status");
        final Altstep_Type altstepType = (Altstep_Type) lastGovernor;
        final String altstepName = referredAssignment.getIdentifier().getName();
        final StringBuilder actualParList = altstepType.getFormalParameters().generateCodeActualParlist("");
        expression.expression.append("@Override\n");
        expression.expression.append("public void invoke_standalone(");
        altstepType.getFormalParameters().generateCode(aData, expression.expression);
        expression.expression.append(") {\n");
        expression.expression.append(MessageFormat.format("{0}({1});\n", altstepName, actualParList));
        expression.expression.append("}\n");
        expression.expression.append("@Override\n");
        expression.expression.append("public Default_Base activate(");
        altstepType.getFormalParameters().generateCode(aData, expression.expression);
        expression.expression.append(") {\n");
        expression.expression.append(MessageFormat.format("return activate_{0}({1});\n", altstepName, actualParList));
        expression.expression.append("}\n");
        expression.expression.append("@Override\n");
        expression.expression.append("public TitanAlt_Status invoke(");
        altstepType.getFormalParameters().generateCode(aData, expression.expression);
        expression.expression.append(") {\n");
        expression.expression.append(MessageFormat.format("return {0}_instance({1});\n", altstepName, actualParList));
        expression.expression.append("}\n");
    } else if (lastGovernor.getTypetype().equals(Type_type.TYPE_TESTCASE)) {
        aData.addBuiltinTypeImport("TitanVerdictType");
        aData.addBuiltinTypeImport("TitanFloat");
        expression.expression.append("@Override\n");
        expression.expression.append("public ");
        final Testcase_Type testcaseType = (Testcase_Type) lastGovernor;
        expression.expression.append("TitanVerdictType");
        expression.expression.append(" execute(");
        if (testcaseType.getFormalParameters().getNofParameters() > 0) {
            testcaseType.getFormalParameters().generateCode(aData, expression.expression);
            expression.expression.append(", ");
        }
        expression.expression.append("boolean has_timer, TitanFloat timer_value");
        expression.expression.append(") {\n");
        expression.expression.append("return testcase_");
        expression.expression.append(referredAssignment.getIdentifier().getName());
        expression.expression.append('(');
        if (testcaseType.getFormalParameters().getNofParameters() > 0) {
            expression.expression.append(testcaseType.getFormalParameters().generateCodeActualParlist(""));
            expression.expression.append(", ");
        }
        expression.expression.append("has_timer, timer_value");
        expression.expression.append(");\n");
        expression.expression.append("}\n");
    }
    expression.expression.append("})\n");
}
Also used : Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) Testcase_Type(org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) Testcase_Type(org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 48 with Type

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

the class SelfComponentExpression 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 (myGovernor == null || myScope == null) {
        return;
    }
    final IType governorLast = myGovernor.getTypeRefdLast(timestamp);
    if (!Type_type.TYPE_COMPONENT.equals(governorLast.getTypetype())) {
        return;
    }
    final RunsOnScope runsOnScope = myScope.getScopeRunsOn();
    if (runsOnScope == null) {
        return;
    }
    final Type componentType = runsOnScope.getComponentType();
    if (componentType != null && !governorLast.isCompatible(timestamp, componentType, null, null, null)) {
        getLocation().reportSemanticError(MessageFormat.format("Incompatible component types: a component reference of type `{0}'' was expected, but `self'' has type `{1}''", governorLast.getTypename(), componentType.getTypename()));
        setIsErroneous(true);
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 49 with Type

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

the class MTCComponentExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (myGovernor == null || myScope == null) {
        return;
    }
    final IType governorLast = myGovernor.getTypeRefdLast(timestamp);
    if (!Type_type.TYPE_COMPONENT.equals(governorLast.getTypetype())) {
        return;
    }
    final Type componentType = myScope.getMtcSystemComponentType(timestamp, false);
    if (componentType != null && !governorLast.isCompatible(timestamp, componentType, null, null, null)) {
        getLocation().reportSemanticError(MessageFormat.format("Incompatible component types: a component reference of type `{0}'' was expected, but `mtc'' has type `{1}''", governorLast.getTypename(), componentType.getTypename()));
        setIsErroneous(true);
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Example 50 with Type

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

the class SystemComponentExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (myGovernor == null || myScope == null) {
        return;
    }
    final IType governorLast = myGovernor.getTypeRefdLast(timestamp);
    if (!Type_type.TYPE_COMPONENT.equals(governorLast.getTypetype())) {
        return;
    }
    final Type componentType = myScope.getMtcSystemComponentType(timestamp, true);
    if (componentType != null && !governorLast.isCompatible(timestamp, componentType, null, null, null)) {
        // This actually would be an internal error
        getLocation().reportSemanticError(MessageFormat.format("Incompatible component types: a component reference of type `{0}'' was expected, but `system'' has type `{1}''", governorLast.getTypename(), componentType.getTypename()));
        setIsErroneous(true);
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Type (org.eclipse.titan.designer.AST.Type)69 IType (org.eclipse.titan.designer.AST.IType)56 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IValue (org.eclipse.titan.designer.AST.IValue)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)12 HashMap (java.util.HashMap)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)9 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 Reference (org.eclipse.titan.designer.AST.Reference)8 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)8 Attribute_Type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type)7 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)6 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)6 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6