Search in sources :

Example 1 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class TestCase_Function_Visit_Handler method leave.

public void leave(IVisitableNode node) {
    if (waitForTC || waitForFunction) {
        if (node instanceof Definition_Statement) {
            if (!waitForRecord) {
                nodeVarIsRecord.add(false);
            }
            waitForRecord = false;
            waitForValue = false;
            evaluateExpression();
        }
        if (node instanceof Undefined_LowerIdentifier_Value) {
            blockReferenceListing = false;
        }
        if ((node instanceof Assignment_Statement) || ((node instanceof If_Clause))) {
            waitForValue = false;
            // if assignment is a createExpression
            if (node instanceof Assignment_Statement) {
                if (((Assignment_Statement) node).getTemplate() instanceof SpecificValue_Template) {
                    SpecificValue_Template specValTemplate = (SpecificValue_Template) ((Assignment_Statement) node).getTemplate();
                    if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
                        isCreate = true;
                    }
                }
            }
            evaluateExpression();
        }
        if (node instanceof SequenceOf_Value) {
            evaluateExpression();
        }
        if ((waitForFunction && (node instanceof Return_Statement)) || (waitForTC && (node instanceof ComponentCreateExpression)) || (node instanceof Send_Statement) || (node instanceof Receive_Port_Statement)) {
            evaluateExpression();
        }
        if (waitForTcStartValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (waitForTcStopValues && (node instanceof Identifier) && myASTVisitor.blockIdListing) {
            myASTVisitor.blockIdListing = false;
        }
        if (node instanceof Connect_Statement) {
            waitForTcConnectValues = false;
        }
        if (node instanceof Disconnect_Statement) {
            waitForTcDisconnectValues = false;
        }
        if (node instanceof Unknown_Start_Statement) {
            waitForTcStartValues = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForTcStopValues = false;
        }
        if (node instanceof Definition_Statement) {
            waitForDefStatement = false;
            if (waitForValue) {
                nodeVarValues.add(null);
                nodeVarIsAValueReference.add(false);
                waitForValue = false;
            }
        }
        if (node instanceof Map_Statement) {
            waitForMapIdentifiers = false;
        }
        if (node instanceof ComponentCreateExpression) {
            // switch first two values
            testCaseCreateValues.add(testCaseCreateCharValues.get(0));
            testCaseCreateValues.add(testCaseCreateRefValues.get(0));
            for (int i = 1; i < testCaseCreateCharValues.size(); i++) {
                testCaseCreateValues.add(testCaseCreateCharValues.get(i));
            }
            testCaseCreateCharValues.clear();
            testCaseCreateRefValues.clear();
            waitForTcCreateValues = false;
        }
        if (node instanceof Assignment_Statement) {
            waitForAssignmentIdentifiers = false;
            waitForValue = true;
        }
        if (waitForTcIfCondition && (node instanceof If_Clause)) {
            waitForTcIfCondition = false;
        }
        if (waitForTcStartParameter && (node instanceof Unknown_Start_Statement)) {
            testCaseStartValueParameters.add(null);
        }
        if (waitForTcStopParameter && (node instanceof Unknown_Stop_Statement)) {
            testCaseStopValueParameters.add(null);
        }
        if (isAltGuards && (node instanceof Operation_Altguard)) {
            altGuardConditions.add(null);
        }
        if (node instanceof Operation_Altguard) {
            waitForAltStatements = false;
            isAltGuards = false;
            isReceiveValue = false;
        }
        handleAltCases(node);
        if (node instanceof Unknown_Start_Statement) {
            waitForUnknownStartStatement = false;
        }
        if (node instanceof Unknown_Stop_Statement) {
            waitForUnknownStopStatement = false;
        }
        if (node instanceof Receive_Port_Statement) {
            if (waitForReceiveParameter) {
                altGuardReceiveType.add("noparam");
            }
        // TODO checkAnyport = true;
        }
    }
    if (node instanceof Def_Testcase) {
        handleTestcase(node);
        waitForTC = false;
    }
    if (node instanceof Def_Function) {
        handleFunction(node);
        waitForTC = false;
    }
    if (waitForAssignmentIdentifiers && (node instanceof ArraySubReference)) {
        waitForAssignmentIdentifiers = false;
    }
}
Also used : Connect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement) Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) Def_Testcase(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) ComponentCreateExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ComponentCreateExpression) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) Operation_Altguard(org.eclipse.titan.designer.AST.TTCN3.statements.Operation_Altguard) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Identifier(org.eclipse.titan.designer.AST.Identifier) Unknown_Stop_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_Statement) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Send_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Send_Statement) Disconnect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Disconnect_Statement) Unknown_Start_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Start_Statement) Map_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 2 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class Start_Component_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    final Assignment func = functionInstanceReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final Def_Function function = (Def_Function) func;
    expression.expression.append(MessageFormat.format("{0}(", func.getGenNameFromScope(aData, source, myScope, "start_")));
    componentReference.generateCodeExpression(aData, expression, false);
    FormalParameterList formalParameterList = function.getFormalParameterList();
    if (formalParameterList.getNofParameters() > 0) {
        expression.expression.append(',');
        ISubReference subReference = functionInstanceReference.getSubreferences().get(0);
        ((ParameterisedSubReference) subReference).getActualParameters().generateCodeNoAlias(aData, expression);
    }
    expression.expression.append(')');
    expression.mergeExpression(source);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 3 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class Reference method generateCodeIsPresentBoundChosen.

/**
 * Generates code for checking if the reference
 * and the referred objects are bound or not.
 *
 * generate_code_ispresentbound in the compiler
 *
 * @param aData only used to update imports if needed
 * @param expression the expression for code generated
 * @param isTemplate if the reference is pointing to a template
 * @param optype true to generate code for isbound, false otherwise
 */
public void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final Operation_type optype, final String field) {
    final Assignment assignment = getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final String ass_id = assignment.getGenNameFromScope(aData, expression.expression, myScope, null);
    String ass_id2 = ass_id;
    FormalParameterList formalParameterList;
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            formalParameterList = ((Def_Function) assignment).getFormalParameterList();
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            formalParameterList = ((Def_Extfunction) assignment).getFormalParameterList();
            break;
        case A_TEMPLATE:
            formalParameterList = ((Def_Template) assignment).getFormalParameterList();
            break;
        default:
            formalParameterList = null;
            break;
    }
    if (subReferences.size() > 0 && subReferences.get(0) instanceof ParameterisedSubReference) {
        final ParameterisedSubReference subReference = (ParameterisedSubReference) subReferences.get(0);
        final ExpressionStruct tempExpression = new ExpressionStruct();
        // FIXME should need the formal parameters and other
        // options
        subReference.getActualParameters().generateCodeAlias(aData, tempExpression);
        if (tempExpression.preamble.length() > 0) {
            expression.preamble.append(tempExpression.preamble);
        }
        ass_id2 = MessageFormat.format("{0}({1})", ass_id, tempExpression.expression);
    } else if (formalParameterList != null) {
        // the reference does not have an actual parameter list,
        // but the assignment has
        final ExpressionStruct tempExpression = new ExpressionStruct();
        final StringBuilder newId = new StringBuilder();
        newId.append(assignment.getGenNameFromScope(aData, tempExpression.expression, getMyScope(), null));
        newId.append("( ");
        // ((FieldSubReference)subReferences.get(0));
        for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
            if (i > 0) {
                tempExpression.expression.append(", ");
            }
            formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, tempExpression);
        }
        // expression);
        if (tempExpression.preamble.length() > 0) {
            expression.preamble.append(tempExpression.preamble);
        }
        newId.append(tempExpression.expression);
        newId.append(" )");
        ass_id2 = newId.toString();
    }
    if (subReferences.size() > 1) {
        final String tempGeneralId = aData.getTemporaryVariableName();
        final ExpressionStruct isboundExpression = new ExpressionStruct();
        isboundExpression.preamble.append(MessageFormat.format("boolean {0} = {1}.isBound();\n", tempGeneralId, ass_id2));
        final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
        type.generateCodeIsPresentBoundChosen(aData, isboundExpression, subReferences, 1, tempGeneralId, ass_id2, isTemplate, optype, field);
        expression.preamble.append(isboundExpression.preamble);
        expression.preamble.append(isboundExpression.expression);
        expression.expression.append(tempGeneralId);
    } else {
        switch(optype) {
            case ISBOUND_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isBound()", ass_id2));
                break;
            case ISPRESENT_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isPresent({1})", ass_id2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
                break;
            case ISCHOOSEN_OPERATION:
                expression.expression.append(MessageFormat.format("{0}.isChosen({1})", ass_id2, field));
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
                break;
        }
    }
}
Also used : IParameterisedAssignment(org.eclipse.titan.designer.AST.TTCN3.definitions.IParameterisedAssignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 4 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class Reference method generateConstRef.

public void generateConstRef(final JavaGenData aData, final ExpressionStruct expression) {
    if (referredAssignment == null) {
        // TODO: handle null
        return;
    }
    boolean isTemplate;
    switch(referredAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            isTemplate = false;
            break;
        case A_MODULEPAR_TEMPLATE:
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            isTemplate = true;
            break;
        default:
            isTemplate = false;
            break;
    }
    FormalParameterList formalParameterList;
    switch(referredAssignment.getAssignmentType()) {
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
            break;
        case A_EXT_FUNCTION:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
            break;
        case A_TEMPLATE:
            formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
            break;
        default:
            formalParameterList = null;
            break;
    }
    final IType referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
    // ha parameterezett
    if (subReferences.get(0) instanceof ParameterisedSubReference) {
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
        final ActualParameterList actualParameterList = temp.getActualParameters();
        if (actualParameterList != null) {
            actualParameterList.generateCodeAlias(aData, expression);
        }
        expression.expression.append(" )");
    } else if (formalParameterList != null) {
        // the reference does not have an actual parameter list, but the assignment has
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
        expression.expression.append("( ");
        // FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
        for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
            if (i > 0) {
                expression.expression.append(", ");
            }
            formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
        }
        // temp.getActualParameters().generateCodeAlias(aData, expression);
        expression.expression.append(" )");
    } else {
        // TODO add fuzzy handling
        expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
    }
    generateCode(aData, expression, isTemplate, true, referedGovernor);
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)

Example 5 with Def_Function

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.

the class Scope method checkRunsOnScope.

/**
 * Checks that operations that can only be executed in definitions that
 * have a runs on scope, are really executed in such a definition. And
 * that the required runs on component is compatible with the runs on
 * component of the definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param assignment
 *                the assignment to check (used or referred to by the
 *                statement).
 * @param errorLocation
 *                the location to report the error to.
 * @param operation
 *                the name of the operation.
 */
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
    Component_Type referencedComponent;
    switch(assignment.getAssignmentType()) {
        case A_ALTSTEP:
            referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
            break;
        case A_FUNCTION:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
            referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
            break;
        case A_TESTCASE:
            referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
            break;
        default:
            return;
    }
    if (referencedComponent == null) {
        return;
    }
    final RunsOnScope runsOnScope = getScopeRunsOn();
    if (runsOnScope == null) {
        errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
    } else {
        final Component_Type localType = runsOnScope.getComponentType();
        if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
            errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
        }
    }
}
Also used : Component_Type(org.eclipse.titan.designer.AST.TTCN3.types.Component_Type) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Aggregations

Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)17 Def_Testcase (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Testcase)8 Assignment (org.eclipse.titan.designer.AST.Assignment)6 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)5 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)5 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)5 ArrayList (java.util.ArrayList)4 IType (org.eclipse.titan.designer.AST.IType)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)3 HashMap (java.util.HashMap)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2