Search in sources :

Example 1 with Testcase_Type

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

the class Testcase_Reference_Value method generateSingleExpression.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateSingleExpression(final JavaGenData aData) {
    final StringBuilder result = new StringBuilder();
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    if (governor == null || referredTestcase == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        return result;
    }
    final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    result.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, result, myScope)));
    result.append("@Override\n");
    result.append("public String getModuleName() {\n");
    result.append(MessageFormat.format("return \"{0}\";\n", referredTestcase.getMyScope().getModuleScope().getIdentifier().getName()));
    result.append("}\n");
    result.append("@Override\n");
    result.append("public String getDefinitionName() {\n");
    result.append(MessageFormat.format("return \"{0}\";\n", referredTestcase.getIdentifier().getName()));
    result.append("}\n");
    aData.addBuiltinTypeImport("TitanVerdictType");
    aData.addBuiltinTypeImport("TitanFloat");
    final String moduleName = referredTestcase.getMyScope().getModuleScope().getName();
    final String testcaseName = referredTestcase.getIdentifier().getName();
    result.append("@Override\n");
    result.append("public ");
    final Testcase_Type testcaseType = (Testcase_Type) lastGovernor;
    result.append("TitanVerdictType");
    result.append(" execute(");
    if (testcaseType.getFormalParameters().getNofParameters() > 0) {
        testcaseType.getFormalParameters().generateCode(aData, result);
        result.append(", ");
    }
    result.append("boolean has_timer, TitanFloat timer_value");
    result.append(") {\n");
    result.append(MessageFormat.format("return {0}.testcase_{1}(", moduleName, testcaseName));
    if (testcaseType.getFormalParameters().getNofParameters() > 0) {
        result.append(testcaseType.getFormalParameters().generateCodeActualParlist(""));
        result.append(", ");
    }
    result.append("has_timer, timer_value");
    result.append(");\n");
    result.append("}\n");
    result.append("})\n");
    return result;
}
Also used : Testcase_Type(org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with Testcase_Type

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

the class Referenced_Testcase_Instance_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (dereferredValue == null) {
        return;
    }
    final IValue temporalValue = dereferredValue.setLoweridToReference(timestamp);
    IType type = temporalValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null) {
        return;
    }
    if (!Type_type.TYPE_TESTCASE.equals(type.getTypetype())) {
        dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type testcase was expected in the argument of `derefers()'' instead of `{0}''", type.getTypename()));
        return;
    }
    if (myStatementBlock.getScopeRunsOn() != null) {
        dereferredValue.getLocation().reportSemanticError(DEFINITIONWITHOUTRUNSONEXPECTED);
        return;
    }
    actualParameterList2 = new ActualParameterList();
    final FormalParameterList formalParameterList = ((Testcase_Type) type).getFormalParameters();
    formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameterList2);
    if (timerValue != null) {
        timerValue.setLoweridToReference(timestamp);
        final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temporalType) {
            case TYPE_REAL:
                final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    final double i = real.getValue();
                    if (i < 0.0) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
                    } else if (real.isPositiveInfinity()) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED2, real.createStringRepresentation()));
                    }
                }
                break;
            default:
                timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
                break;
        }
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Testcase_Type(org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type) IType(org.eclipse.titan.designer.AST.IType) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 3 with Testcase_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Testcase_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 4 with Testcase_Type

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

the class ExecuteDereferedExpression 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 (value != null) {
        IType type;
        value.setLoweridToReference(timestamp);
        final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_TEMPLATE, referenceChain);
        if (last.getIsErroneous(timestamp)) {
            type = null;
        } else {
            type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
            if (type != null) {
                type = type.getTypeRefdLast(timestamp);
            }
        }
        if (type == null || type.getIsErroneous(timestamp)) {
            setIsErroneous(true);
        } else if (Type_type.TYPE_TESTCASE.equals(type.getTypetype())) {
            final FormalParameterList formalParameters = ((Testcase_Type) type).getFormalParameters();
            actualParameters = new ActualParameterList();
            final boolean isErroneous = formalParameters.checkActualParameterList(timestamp, actualParameterList, actualParameters);
            if (isErroneous) {
                setIsErroneous(true);
            }
        } else {
            value.getLocation().reportSemanticError(MessageFormat.format("Reference to a value of type testcase was expected in the argument of `derefers()'' instead of `{0}''", type.getTypename()));
            setIsErroneous(true);
        }
    }
    if (timerValue != null) {
        timerValue.setLoweridToReference(timestamp);
        final Type_type tempType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(tempType) {
            case TYPE_REAL:
                final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    final double i = real.getValue();
                    if (i < 0.0) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
                    } else if (real.isPositiveInfinity()) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED, real.createStringRepresentation()));
                    }
                }
                return;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                return;
            default:
                if (!isErroneous) {
                    timerValue.getLocation().reportSemanticError(OPERANDERROR);
                    setIsErroneous(true);
                }
                return;
        }
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, false, false);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)4 Testcase_Type (org.eclipse.titan.designer.AST.TTCN3.types.Testcase_Type)3 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)2 IValue (org.eclipse.titan.designer.AST.IValue)2 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 Altstep_Type (org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type)1 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)1 Type (org.eclipse.titan.designer.AST.Type)1