Package dk.brics.xact.analysis.flowgraph

Examples of dk.brics.xact.analysis.flowgraph.Statement


    for (Statement s : new LinkedHashSet<Statement>(graph.getNodes()))
      s.visitBy(new StatementVisitor() {
       
        private void use(Variable v, Statement s) {
          if (v.isGlobal()) {
            Statement join = global_use.get(v);
            if (join == null) {
              // make new join node
              Debug.println(6, true, "Making join node for " + v + " (used in " + s + ")");
              join = new NopStm(s.getOrigin());
              graph.addNode(join);
View Full Code Here


    // find reachable nodes
    HashSet<Statement> reachable = new HashSet<Statement>();
    LinkedList<Statement> queue = new LinkedList<Statement>();
    queue.addAll(graph.getEntries());
    while (!queue.isEmpty()) {
      Statement s = queue.removeFirst();
      if (!reachable.contains(s)) {
        reachable.add(s);
        for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(s))
          if (edge.getData().getKind() != VariableFilter.Kind.RETURN)
            queue.addLast(edge.getTo());
View Full Code Here

            for (Edge<Statement,VariableFilter> e : graph.getOutEdges(vs))
              graph.addEdge(pred, e.getTo(), e.getData()); // XXX: ok to lose some edge info?
            graph.removeNode(vs);
          }
        } else if (graph.getOutEdges(vs).size() == 1) {
          Statement succ = graph.getOutEdges(vs).iterator().next().getTo();
          if (graph.getInEdges(succ).size()==1) { // TODO: copy propagation could be improved by not requiring "no other predecessors"
            // variable assignment with unique successor node that has no other predecessors - bypass this assignment
            final Variable vsrc = vs.getSource();
            succ.visitBy(new StatementVisitor() {

              public void visitAnalyzeStm(AnalyzeStm s) {
                s.setBase(vsrc);
              }

              public void visitGapifyStm(GapifyStm s) {
                s.setBase(vsrc);
              }

              public void visitGetStm(GetStm s) {
                s.setBase(vsrc);
              }

              public void visitRemoveStm(RemoveStm s) {
                s.setBase(vsrc);
              }

              public void visitValidateStm(ValidateStm s) {
                if (s.getBase() != null)
                  s.setBase(vsrc);
              }

              public void visitVarStm(VarStm s) {
                s.setSource(vsrc);
              }

              public void visitPlugStm(PlugStm s) {
                s.setBase(vsrc);
                if (s.getXMLSource() != null)
                  s.setXMLSource(vsrc);
              }

              public void visitCheckStm(CheckStm s) {
                if (s.getBase() != null)
                  s.setBase(vsrc);
              }

              public void visitSetStm(SetStm s) {
                s.setBase(vsrc);
                if (s.getXMLSource() != null)
                  s.setXMLSource(vsrc);
              }

              public void visitInsertStm(InsertStm s) {
                s.setBase(vsrc);
                if (s.getXMLSource() != null)
                  s.setXMLSource(vsrc);
              }

              public void visitConcatStm(ConcatStm s) {
                s.setXMLSource(vsrc);
              }

              public void visitCopyStm(CopyStm s) {
                s.setBase(vsrc);
                if (s.getFirstChild() != null)
                  s.setFirstChild(vsrc);
                if (s.getFirstAttr() != null)
                  s.setFirstAttr(vsrc);
                if (s.getNextNode() != null)
                  s.setNextNode(vsrc);
              }

              public void visitCastStm(CastStm s) {
                s.setBase(vsrc);
              }

              public void visitNodeStm(NodeStm s) {
                if (s.getFirstChild() != null)
                  s.setFirstChild(vsrc);
                if (s.getFirstAttr() != null)
                  s.setFirstAttr(vsrc);
                if (s.getNextNode() != null)
                  s.setNextNode(vsrc);
              }

              // unreachable cases (these nodes cannot be def-use graph successors)

              public void visitConstStm(ConstStm s) {}

              public void visitEmptyStm(EmptyStm s) {}

              public void visitNopStm(NopStm s) {}

              public void visitUnknownStm(UnknownStm s) {}

              // not in this phase
              public void visitArrayReadStm(ArrayReadStm s) {
              }
              public void visitArrayWriteStm(ArrayWriteStm s) {
              }
              public void visitCallStm(CallStm s) {
              }
              public void visitEscapeStm(EscapeStm s) {
              }
              public void visitArrayWriteStringStm(ArrayWriteStringStm s) {
              }
            });
            for (Edge<Statement,VariableFilter> e : graph.getInEdges(vs))
              graph.addEdge(e.getFrom(), succ, e.getData()); // XXX: ok to lose some edge info?
            graph.removeNode(vs);
          }
        }
      }
    }
   
    // find unreachable nodes
    Set<Statement> reachable = new HashSet<Statement>(graph.getEntries());
    LinkedList<Statement> queue = new LinkedList<Statement>(graph.getEntries());
    while (!queue.isEmpty()) {
      Statement stm = queue.removeFirst();
      for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(stm)) {
        if (!reachable.contains(edge.getTo())) {
          reachable.add(edge.getTo());
          queue.add(edge.getTo());
        }
      }
    }
    // find used nodes
    Set<Statement> used = new HashSet<Statement>();
    queue.clear();
    for (Statement stm : graph.getNodes()) {
      if (XMLGraphChecker.isStatementChecked(stm)) {
        queue.add(stm);
        used.add(stm);
      }
    }
    while (!queue.isEmpty()) {
      Statement stm = queue.removeFirst();
      for (Edge<Statement,VariableFilter> edge : graph.getInEdges(stm)) {
        if (!used.contains(edge.getFrom())) {
          used.add(edge.getFrom());
          queue.add(edge.getFrom());
        }
View Full Code Here

    ControlFlowBuilder cfg = new ControlFlowBuilder(graph, null);
    // transform!
    for (CallStm call : calls) {
      Method target = call.getMethod();
      cfg.setOrigin(call.getOrigin());
      Statement start = cfg.currentStatement();
      Variable[] params = target.getParameters();
      Variable[] args = call.getArguments();
      VariableFilter paramsOnly = new VariableFilter(false, VariableFilter.Kind.CALL);
      VariableFilter argsOnly = new VariableFilter(false);
      VariableFilter notArgs = new VariableFilter(true);
View Full Code Here

    Translator translator = new Translator(context, config);
    // create methods and parse field annotations
    for (SootClass c : Scene.v().getApplicationClasses()) {
      for (SootMethod m : c.getMethods()) {
        Origin origin = new Origin(c.getName() + "." + m.getName(), 0, 0);
        Statement methodentry, methodexit;
        Variable returnVar;
        Variable[] parameters = new Variable[m.getParameterCount()];
        if (m.isConcrete()) {
          // entry
          methodentry = new NopStm(origin, "method entry");
View Full Code Here

    public void startBranch() {
        // if no statement has been created, add a Nop as the start of the branch
        if (firstStatement == null) {
            addStatement(new NopStm(currentOrigin));
        }
        Statement start = lastStatement;
        Statement end = new NopStm(currentOrigin);
        graph.addNode(end);
        branchWasUsed = false;
        branches.add(new Branching(start, end));
    }
View Full Code Here

  /**
   * Generates an InsertStm.
   */
  private void putInsert(InsertStm.Kind kind, Value base, Value xpath, ValueBox source, boolean convertObjects) {
    Statement stm;
    cfg.addStatement(stm = new InsertStm(kind, hardcodeResult = makevar(), translateExpr(base),
        xpath!=null ? context.getConstantString(xpath) : null,
        convertObjects ? null : Automaton.makeEmpty(),
        convertObjects ? getVariableFromObjectExp(source) : translateExpr(source.getValue()),
        context.getCurrentOrigin()));
View Full Code Here

          emptyConstant,
          context.getCurrentOrigin()));
      for (int i=0; i<info.contents.length; i++) {
        Variable var2 = makevar();
        Variable val = translateExpr(info.contents[i].getValue());
        Statement stm;
        cfg.addStatement(stm = new InsertStm(InsertStm.Kind.APPEND,
            var2,
            var,
            null,
            Automaton.makeEmpty(),
View Full Code Here

    for (Statement s : lat.getInitial(graph))
      wl.put(s);
    // iterate until fixed point
    int steps = 0;
    while (!wl.isEmpty()) {
      Statement s = wl.removeFirst();
      boolean changed;
      if (forward)
        changed = lat.transfer(before.get(s), s, after.get(s));
      else
        changed = lat.transfer(after.get(s), s, before.get(s));
      steps++;
      if (!visited.contains(s)) {
        changed = true;
        visited.add(s);
      }
      if (changed) {
        if (forward) {
          for (Edge<Statement,VariableFilter> se : graph.getOutEdges(s)) {
            Statement ss = se.getTo();
            if (lat.merge(after.get(s), se.getData(), before.get(ss)) || !visited.contains(ss))
              wl.put(ss);
          }
        } else {
          for (Edge<Statement,VariableFilter> se : graph.getInEdges(s)) {
            Statement ss = se.getFrom();
            if (lat.merge(before.get(s), se.getData(), after.get(ss)) || !visited.contains(ss))
              wl.put(ss);
          }
        }
      }
View Full Code Here

      LinkedList<Statement> queue = new LinkedList<Statement>();
      HashMap<Statement,Integer> indegree = new HashMap<Statement,Integer>();
      int o = 0;
      queue.addAll(graph.getEntries());
      while (!queue.isEmpty()) {
        Statement s = queue.removeFirst();
        if (!order.containsKey(s)) {
          int so = o++;
          order.put(s, so);
          for (Edge<Statement,VariableFilter> out : graph.getOutEdges(s)) {
            Statement s2 = out.getTo();
            if (indegree.containsKey(s2))
              indegree.put(s2, indegree.get(s2)+1);
            else
              indegree.put(s2, 1);
            if (indegree.get(s2) == graph.getInEdges(s2).size())
View Full Code Here

TOP

Related Classes of dk.brics.xact.analysis.flowgraph.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.