Search in sources :

Example 26 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class StatementBlockContext method process_internal.

@Override
protected void process_internal() {
    localVarIds = new ArrayList<Identifier>();
    final Context bottom = getBottom();
    final IVisitableNode bottomNode = bottom.getNode();
    if (!(bottomNode instanceof Log_Statement)) {
        ErrorReporter.logError("StatementBlockContext.process_internal(): Warning! Context chain bottom node is not a Log_Statement! ");
        return;
    }
    final Log_Statement logst = (Log_Statement) bottomNode;
    final Location logLoc = logst.getLocation();
    // 
    final StatementBlock sb = getNode();
    final StatementBlockVisitor vis = new StatementBlockVisitor(logLoc);
    sb.accept(vis);
    localVarIds.addAll(vis.getIdsFound());
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Log_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Log_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Location(org.eclipse.titan.designer.AST.Location)

Example 27 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class ReturnVisitor method visit.

@Override
public int visit(final IVisitableNode node) {
    // certain YES
    if (node instanceof Return_Statement) {
        certainty = ReturnCertainty.YES;
        return V_ABORT;
    }
    // 
    if (node instanceof StatementBlock || node instanceof StatementList) {
        final StatementBlockVisitor blockVis = new StatementBlockVisitor();
        node.accept(blockVis);
        certainty = blockVis.getCertainty();
        return V_SKIP;
    }
    // custom statements
    if (node instanceof While_Statement || node instanceof DoWhile_Statement || node instanceof For_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // conditional blocks: maximum MAYBE
        certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        return V_SKIP;
    }
    if (node instanceof If_Statement) {
        final If_Statement ifs = (If_Statement) node;
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        if (ifs.getStatementBlock() != null) {
            // must enter one block: maximum YES
            certainty = branchMerger.getCertainty();
        } else {
            // conditional blocks: maximum MAYBE
            certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        }
        return V_SKIP;
    }
    if (node instanceof Alt_Statement) {
        final AltGuards ags = ((Alt_Statement) node).getAltGuards();
        final BranchMerger branchMerger = new BranchMerger();
        ags.accept(branchMerger);
        if (ags.hasElse()) {
            // must enter one block: maximum YES
            certainty = branchMerger.getCertainty();
        } else {
            // conditional blocks: maximum MAYBE
            certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        }
        return V_SKIP;
    }
    if (node instanceof Interleave_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // conditional block: maximum MAYBE
        certainty = branchMerger.getCertainty().or(ReturnCertainty.NO);
        return V_SKIP;
    }
    if (node instanceof StatementBlock_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // must enter block: maximum YES
        certainty = branchMerger.getCertainty();
        return V_SKIP;
    }
    if (node instanceof SelectCase_Statement) {
        final BranchMerger branchMerger = new BranchMerger();
        node.accept(branchMerger);
        // must enter one block: maximum YES
        certainty = branchMerger.getCertainty();
        return V_SKIP;
    }
    return V_ABORT;
}
Also used : For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) SelectCase_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement) Interleave_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Interleave_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement) StatementBlock_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock_Statement) AltGuards(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards) Return_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) While_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)

Example 28 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class Def_Testcase_Writer method writeTestCaseFunction.

public String writeTestCaseFunction(StatementBlock tcStatementBlock) {
    int testcaseSize = tcStatementBlock.getSize();
    for (int j = 0; j < testcaseSize; j++) {
        if (tcStatementBlock.getStatementByIndex(j) instanceof Definition_Statement) {
            Definition_Statement tc_defStatement = (Definition_Statement) tcStatementBlock.getStatementByIndex(j);
            defCounter++;
            defValueCounter++;
            writeDefinitionStatement(tc_defStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Assignment_Statement) {
            Assignment_Statement tc_assignStatement = (Assignment_Statement) tcStatementBlock.getStatementByIndex(j);
            assignCounter++;
            testCaseString.append(writeAssignmentStatement(tc_assignStatement));
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Connect_Statement) {
            Connect_Statement tc_connectStatement = (Connect_Statement) tcStatementBlock.getStatementByIndex(j);
            connectCounter++;
            writeConnectStatement(tc_connectStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Start_Statement) {
            Unknown_Start_Statement tc_startStatement = (Unknown_Start_Statement) tcStatementBlock.getStatementByIndex(j);
            writeUnknownStartStatement(tc_startStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Done_Statement) {
            testCaseString.append("hc.done(\"all component\");" + "\r\n");
        // TODO: where is all coming from?
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Map_Statement) {
            Map_Statement tc_mapStatement = (Map_Statement) tcStatementBlock.getStatementByIndex(j);
            mapCounter++;
            writeMapStatement(tc_mapStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof If_Statement) {
            If_Statement tc_ifStatement = (If_Statement) tcStatementBlock.getStatementByIndex(j);
            tcIfConditionCounter++;
            writeIfStatement(tc_ifStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Setverdict_Statement) {
            Setverdict_Statement tc_setVerdictStatement = (Setverdict_Statement) tcStatementBlock.getStatementByIndex(j);
            writeSetVerdictStatement(tc_setVerdictStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof DoWhile_Statement) {
            doWhileCounter++;
            DoWhile_Statement doWhileStatement = (DoWhile_Statement) tcStatementBlock.getStatementByIndex(j);
            String test = doWhileStatement.getExpression().toString();
            testCaseString.append("do{" + "\r\n");
            this.writeTestCaseFunction(doWhileStatement.getStatementBlock());
            testCaseString.append("while(" + doWhileExpressions.get(doWhileCounter) + ".getValue());\r\n");
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Send_Statement) {
            Send_Statement tc_SendStatement = (Send_Statement) tcStatementBlock.getStatementByIndex(j);
            sendCounter++;
            testCaseString.append(writeSendStatement(tc_SendStatement));
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Receive_Port_Statement) {
            Receive_Port_Statement tc_ReceiveStatement = (Receive_Port_Statement) tcStatementBlock.getStatementByIndex(j);
            receiveCounter++;
            blockStatementBlockStatementWriter = true;
            testCaseString.append(writeReceiveStatement(tc_ReceiveStatement));
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Unknown_Stop_Statement) {
            Unknown_Stop_Statement tc_StopStatement = (Unknown_Stop_Statement) tcStatementBlock.getStatementByIndex(j);
            writeUnknownStopStatement(tc_StopStatement);
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Alt_Statement) {
            altStatementCounter++;
            altStatements.get(altStatementCounter).setTimerInfo(isThereAStartedTimer, currentTimerName);
            testCaseString.append(altStatements.get(altStatementCounter).getJavaSource());
        } else if (tcStatementBlock.getStatementByIndex(j) instanceof Disconnect_Statement) {
            Disconnect_Statement tc_disconnectStatement = (Disconnect_Statement) tcStatementBlock.getStatementByIndex(j);
            disconnectCounter++;
            writeDisconnectStatement(tc_disconnectStatement);
        } else if ((tcStatementBlock.getStatementByIndex(j) instanceof StatementBlock_Statement) && !blockStatementBlockStatementWriter) {
            StatementBlock_Statement tc_statementBlockStatement = (StatementBlock_Statement) tcStatementBlock.getStatementByIndex(j);
            blockStatementBlockStatementWriter = false;
            testCaseString.append("{\r\n");
            blockWriter = true;
            writeTestCaseFunction(tc_statementBlockStatement.getStatementBlock());
            blockWriter = false;
            testCaseString.append("}\r\n");
        }
    }
    if (!blockWriter) {
        testCaseString.append("}" + "\r\n");
    }
    return testCaseString.toString();
}
Also used : Done_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Done_Statement) Connect_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Connect_Statement) Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement) StatementBlock_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock_Statement) Receive_Port_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Receive_Port_Statement) Assignment_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement) Unknown_Stop_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Unknown_Stop_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) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Map_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Map_Statement) Setverdict_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Setverdict_Statement)

Example 29 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class Def_Altstep method setMyScope.

@Override
public /**
 * {@inheritDoc}
 */
void setMyScope(final Scope scope) {
    if (bridgeScope != null && bridgeScope.getParentScope() == scope) {
        return;
    }
    bridgeScope = new NamedBridgeScope();
    bridgeScope.setParentScope(scope);
    scope.addSubScope(getLocation(), bridgeScope);
    bridgeScope.setScopeMacroName(identifier.getDisplayName());
    super.setMyScope(bridgeScope);
    if (runsOnRef != null) {
        runsOnRef.setMyScope(bridgeScope);
    }
    formalParList.setMyScope(bridgeScope);
    if (block != null) {
        block.setMyScope(formalParList);
        altGuards.setMyScope(block);
        bridgeScope.addSubScope(block.getLocation(), block);
    }
    bridgeScope.addSubScope(formalParList.getLocation(), formalParList);
    if (altGuards != null) {
        for (int i = 0; i < altGuards.getNofAltguards(); i++) {
            final AltGuard ag = altGuards.getAltguardByIndex(i);
            final StatementBlock sb = ag.getStatementBlock();
            if (sb != null) {
                bridgeScope.addSubScope(sb.getLocation(), sb);
            }
        }
    }
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 30 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class TooManyStatements method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof StatementBlock) {
        final StatementBlock s = (StatementBlock) node;
        if (s.getSize() > reportTooManyStatementsSize) {
            final String msg = MessageFormat.format(TOOMANYSTATEMENTS, reportTooManyStatementsSize, s.getSize());
            problems.report(s.getLocation(), msg);
        }
    }
}
Also used : StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Aggregations

StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)21 IValue (org.eclipse.titan.designer.AST.IValue)11 Assignment (org.eclipse.titan.designer.AST.Assignment)8 Reference (org.eclipse.titan.designer.AST.Reference)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)7 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)6 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)5 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)5 Assignment_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement)4 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Location (org.eclipse.titan.designer.AST.Location)3 Module (org.eclipse.titan.designer.AST.Module)3 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)3 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)3 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)3 Map (java.util.Map)2