Search in sources :

Example 1 with IVisitableNode

use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.

the class ConstantParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        value = new Value(type, Writable.NULL);
        return Action.skip(Type.class, this);
    }
    if (node instanceof org.eclipse.titan.designer.AST.Value) {
        ValueHolder holder = v -> value = v;
        return dispatch(this, type, holder, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Writable(org.eclipse.titan.codegenerator.Writable) Iterator(java.util.Iterator) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder) Identifier(org.eclipse.titan.designer.AST.Identifier) Util(org.eclipse.titan.codegenerator.template.Util) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) HashMap(java.util.HashMap) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) ArrayList(java.util.ArrayList) SourceCode(org.eclipse.titan.codegenerator.SourceCode) List(java.util.List) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Action(org.eclipse.titan.codegenerator.template.Action) Value(org.eclipse.titan.codegenerator.template.Value) Type(org.eclipse.titan.designer.AST.Type) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Value(org.eclipse.titan.codegenerator.template.Value) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder)

Example 2 with IVisitableNode

use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.

the class Export_Debug_AST_Action method exportDebugAST.

private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
    out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
    out.write("*************************".getBytes());
    out.write(lineend);
    out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
    out.write(lineend);
    out.write("*************************".getBytes());
    out.write(lineend);
    module.accept(new ASTVisitor() {

        private int padding = 0;

        @Override
        public int visit(IVisitableNode node) {
            if (node instanceof Assignment) {
                Assignment assignment = (Assignment) node;
                printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
            } else if (node instanceof Identifier) {
                printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
            } else if (node instanceof Statement) {
                Statement statement = (Statement) node;
                printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
            } else if (node instanceof Reference) {
                Reference ref = (Reference) node;
                printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
                Assignment old = ref.getAssOld();
                if (old != null) {
                    printInfoln(out, padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
                }
            } else if (node instanceof ComponentTypeBody) {
                ComponentTypeBody body = (ComponentTypeBody) node;
                Map<String, Definition> map = body.getDefinitionMap();
                printInfoln(out, padding + 1, " contains definitions:");
                if (map != null) {
                    for (Map.Entry<String, Definition> entry : map.entrySet()) {
                        printInfoln(out, padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
                    }
                }
            }
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding++;
            }
            return super.visit(node);
        }

        @Override
        public int leave(IVisitableNode node) {
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding--;
            }
            return super.leave(node);
        }
    });
    out.write("*************************".getBytes());
    out.write(lineend);
    out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
    out.write(lineend);
    out.write("*************************".getBytes());
    out.write(lineend);
    out.closeEntry();
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Reference(org.eclipse.titan.designer.AST.Reference) ZipEntry(java.util.zip.ZipEntry) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ASTVisitor(org.eclipse.titan.designer.AST.ASTVisitor) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Assignment(org.eclipse.titan.designer.AST.Assignment) ZipEntry(java.util.zip.ZipEntry) Identifier(org.eclipse.titan.designer.AST.Identifier) Map(java.util.Map) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 3 with IVisitableNode

use of org.eclipse.titan.designer.AST.IVisitableNode 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 4 with IVisitableNode

use of org.eclipse.titan.designer.AST.IVisitableNode in project titan.EclipsePlug-ins by eclipse.

the class IfContext method process_internal.

protected void process_internal() {
    final If_Statement st = getNode();
    final If_Clauses ics = st.getIfClauses();
    final Context child = getChild();
    if (child != null && child.getNode().equals(ics)) {
        // the log statement is in one of the conditional clauses
        final List<If_Clause> icl = ics.getClauses();
        final Context clauseContext = child.getChild();
        if (clauseContext != null && icl.contains(clauseContext.getNode())) {
            final IVisitableNode ic = clauseContext.getNode();
            final ClauseVisitor vis = new ClauseVisitor();
            ic.accept(vis);
            final List<Reference> refs = vis.getResult();
            for (Reference ref : refs) {
                varNamesInConditions.add(ref.getDisplayName());
            }
        }
    } else {
        // the log statement is in the else block
        final List<Reference> refs = extractAllIdsFromClauses(ics);
        for (Reference ref : refs) {
            varNamesInConditions.add(ref.getDisplayName());
        }
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) If_Clauses(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clauses) If_Clause(org.eclipse.titan.designer.AST.TTCN3.statements.If_Clause) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode)

Example 5 with IVisitableNode

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

Aggregations

IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)13 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Reference (org.eclipse.titan.designer.AST.Reference)4 Counter (org.eclipse.titanium.metrics.visitors.Counter)4 CounterVisitor (org.eclipse.titanium.metrics.visitors.CounterVisitor)4 Map (java.util.Map)2 Scope (org.eclipse.titan.codegenerator.Scope)2 org.eclipse.titan.codegenerator.myASTVisitor (org.eclipse.titan.codegenerator.myASTVisitor)2 ASTVisitor (org.eclipse.titan.designer.AST.ASTVisitor)2 Assignment (org.eclipse.titan.designer.AST.Assignment)2 LargeLocation (org.eclipse.titan.designer.AST.LargeLocation)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)2 ComponentTypeBody (org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1