Search in sources :

Example 1 with For_Statement

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

the class SizeCheckInLoop method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof For_Statement) {
        final For_Statement s = (For_Statement) node;
        s.getFinalExpression().accept(new LoopVisitor(problems));
    } else if (node instanceof While_Statement) {
        final While_Statement s = (While_Statement) node;
        s.getExpression().accept(new LoopVisitor(problems));
    } else if (node instanceof DoWhile_Statement) {
        final DoWhile_Statement s = (DoWhile_Statement) node;
        s.getExpression().accept(new LoopVisitor(problems));
    } else {
        return;
    }
}
Also used : For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement) While_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement) DoWhile_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)

Example 2 with For_Statement

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

the class IterateOnWrongArray method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof For_Statement)) {
        return;
    }
    final For_Statement fs = (For_Statement) node;
    // find the loop variable
    final LoopVariableFinder lvVisitor = new LoopVariableFinder();
    fs.accept(lvVisitor);
    final Reference loopVar = lvVisitor.getLoopVariable();
    if (loopVar == null) {
        return;
    }
    final Assignment loopVarDef = loopVar.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (loopVarDef == null) {
        return;
    }
    // find the array over which the loop iterates
    final Value finalExpr = fs.getFinalExpression();
    if (finalExpr == null) {
        return;
    }
    final FinalExprVisitor exprVisitor = new FinalExprVisitor();
    finalExpr.accept(exprVisitor);
    final List<Reference> arraysIterated = exprVisitor.getArraysIterated();
    if (arraysIterated.isEmpty()) {
        return;
    }
    /* search every statement block for references that has the loop variable in them and the
		 * reference differs from the reference of the array over which the for loop iterates */
    final StatementBlock sb = fs.getStatementBlock();
    if (sb == null) {
        return;
    }
    final StatementBlockVisitor sbVisitor = new StatementBlockVisitor(loopVar, arraysIterated);
    sb.accept(sbVisitor);
    final List<Reference> matchingRefs = sbVisitor.getMatchingReferences();
    for (final Reference r : matchingRefs) {
        if (r.getUsedOnLeftHandSide()) {
            continue;
        }
        problems.report(r.getLocation(), MessageFormat.format(ERR_MSG, loopVar));
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) Reference(org.eclipse.titan.designer.AST.Reference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value) Value(org.eclipse.titan.designer.AST.Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) IValue(org.eclipse.titan.designer.AST.IValue) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 3 with For_Statement

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

the class Environment method isLoopScope.

/**
 * Returns true if the given BlockNode is a statement block of a loop statement (for, while, alt)
 */
private static boolean isLoopScope(final BlockNode scope) {
    final StatementNode parentSN = scope.getParent();
    if (parentSN == null) {
        return false;
    }
    final IVisitableNode scopeSt = parentSN.getAstNode();
    return (scopeSt instanceof For_Statement || scopeSt instanceof While_Statement || scopeSt instanceof Alt_Statement);
}
Also used : For_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement) Alt_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement) While_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 4 with For_Statement

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

the class ReferenceFinder method detectSmallestScope.

/**
 * Detect the smallest scope where the references should be searched
 *
 * @param assignment
 *                The assignment
 * @return The detected scope
 */
private Scope detectSmallestScope(final Assignment assignment) {
    Scope localScope = assignment.getMyScope();
    final Module module = localScope.getModuleScope();
    if (localScope instanceof StatementBlock) {
        final StatementBlock statementBlock = (StatementBlock) localScope;
        if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
            localScope = localScope.getParentScope();
        }
        if (statementBlock.hasEnclosingLoopOrAltguard()) {
            localScope = localScope.getParentScope();
        }
    }
    if (localScope instanceof NamedBridgeScope) {
        localScope = localScope.getParentScope();
    }
    // control,function,testcase,altstep then it is global
    if (localScope instanceof Assignments && localScope.getParentScope() == module) {
        localScope = module;
    } else // treat it as global definition
    if (localScope instanceof ComponentTypeBody) {
        // FIXME this still does not make them global, that is something completely different.
        localScope = module;
    } else // search for actual named parameters everywhere
    if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
        localScope = module;
    } else // For_Statement that must be searched
    if (localScope instanceof For_Loop_Definitions) {
        localScope = localScope.getParentScope();
    }
    return localScope;
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope) For_Loop_Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.For_Loop_Definitions) Def_Altstep(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) RunsOnScope(org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)

Example 5 with For_Statement

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

Aggregations

For_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.For_Statement)5 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)3 While_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.While_Statement)3 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)2 DoWhile_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.DoWhile_Statement)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 ISubReference (org.eclipse.titan.designer.AST.ISubReference)1 IValue (org.eclipse.titan.designer.AST.IValue)1 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)1 For_Loop_Definitions (org.eclipse.titan.designer.AST.TTCN3.definitions.For_Loop_Definitions)1 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)1 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)1 AltGuards (org.eclipse.titan.designer.AST.TTCN3.statements.AltGuards)1 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)1 Interleave_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Interleave_Statement)1 Return_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Return_Statement)1 SelectCase_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.SelectCase_Statement)1