Search in sources :

Example 6 with Altstep_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Altguard method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (expression != null) {
        final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_BOOL.equals(temporalType)) {
            last.getLocation().reportSemanticError(BOOLEANEXPECTED);
            expression.setIsErroneous(true);
        }
        if (expression.getMyGovernor() == null) {
            expression.setMyGovernor(new Boolean_Type());
        }
    }
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type == null) {
        lastTimeChecked = timestamp;
        return;
    }
    type = type.getTypeRefdLast(timestamp);
    if (type == null || type.getIsErroneous(timestamp)) {
        lastTimeChecked = timestamp;
        return;
    }
    if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("A value of type altstep was expected instead of `{0}''", type.getTypename()));
        lastTimeChecked = timestamp;
        return;
    }
    value.getMyScope().checkRunsOnScope(timestamp, type, this, "call");
    final FormalParameterList formalParmaterList = ((Altstep_Type) type).getFormalParameters();
    actualParameterList = new ActualParameterList();
    formalParmaterList.checkActualParameterList(timestamp, parsedParameters, actualParameterList);
    if (statementblock != null) {
        statementblock.check(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Boolean_Type(org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 7 with Altstep_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Altstep_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)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)6 Altstep_Type (org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type)5 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)4 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)4 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)1 IValue (org.eclipse.titan.designer.AST.IValue)1 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)1 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)1 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)1 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)1 Testcase_Type (org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type)1 Type (org.eclipse.titan.designer.AST.Type)1