Search in sources :

Example 16 with StatementBlock

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

the class IsBoundWithoutElse method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof If_Statement)) {
        return;
    }
    final If_Statement ifs = (If_Statement) node;
    final StatementBlock elseClause = ifs.getStatementBlock();
    if (elseClause != null) {
        return;
    }
    // there is no else clause present
    final If_Clauses ifcs = ifs.getIfClauses();
    if (ifcs == null) {
        return;
    }
    final List<If_Clause> ifcL = ifcs.getClauses();
    if (ifcL == null || ifcL.isEmpty()) {
        return;
    }
    for (final If_Clause ifc : ifcL) {
        final IfConditionVisitor visitor = new IfConditionVisitor(problems);
        ifc.accept(visitor);
    }
}
Also used : If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) If_Clauses(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clauses) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause)

Example 17 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock 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 18 with StatementBlock

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

the class FMLinesOfCode method measure.

@Override
public Number measure(final MetricData data, final Def_Function function) {
    final Counter count = new Counter(0);
    function.accept(new CounterVisitor(count) {

        @Override
        public int visit(final IVisitableNode node) {
            if (node instanceof Def_Function) {
                return V_CONTINUE;
            } else if (node instanceof StatementBlock) {
                count.set(((LargeLocation) ((StatementBlock) node).getLocation()).getEndLine());
            }
            return V_SKIP;
        }
    });
    return count.val() - function.getLocation().getLine() + 1;
}
Also used : Counter(org.eclipse.titanium.metrics.visitors.Counter) CounterVisitor(org.eclipse.titanium.metrics.visitors.CounterVisitor) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 19 with StatementBlock

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

the class IfInsteadAltguard method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof AltGuard) {
        final AltGuard ag = (AltGuard) node;
        final StatementBlock statements = ag.getStatementBlock();
        if (statements != null && !statements.isEmpty()) {
            final Statement firstStatement = statements.getStatementByIndex(0);
            if (firstStatement instanceof If_Statement) {
                final Value condition = ((If_Statement) firstStatement).getIfClauses().getClauses().get(0).getExpression();
                Location reportAt;
                if (condition != null) {
                    reportAt = condition.getLocation();
                } else {
                    reportAt = firstStatement.getLocation();
                }
                problems.report(reportAt, MIGHT_ALTGUARD);
            }
        }
    }
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Value(org.eclipse.titan.designer.AST.Value) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 20 with StatementBlock

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

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