Package dk.brics.xact.analysis.flowgraph

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


//              Statement ea = new EmptyStm(v, s.getOrigin()); // initialisation value for the global var
//              graph.addNode(ea);
//              graph.addEntry(ea);
            }
            // add use edge
            graph.addEdge(join, s, new VariableFilter(v));
            // remove the variable from the outflow of the statement
            for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(s))
              edge.getData().removeVariable(v);
          }
        }

        public void visitAnalyzeStm(AnalyzeStm s) {
          use(s.getBase(), s);
        }

        public void visitConcatStm(ConcatStm s) {
          use(s.getXMLSource(), s);
        }

        public void visitConstStm(ConstStm s) {
          // do nothing
        }

        public void visitCopyStm(CopyStm s) {
          use(s.getBase(), s);
          if (s.getFirstChild() != null)
            use(s.getFirstChild(), s);
          if (s.getFirstAttr() != null)
            use(s.getFirstAttr(), s);
          if (s.getNextNode() != null)
            use(s.getNextNode(), s);
        }

        public void visitCastStm(CastStm s) {
          use(s.getBase(), s);
        }

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

        public void visitEmptyStm(EmptyStm s) {
          // do nothing
        }

        public void visitGapifyStm(GapifyStm s) {
          use(s.getBase(), s);
        }

        public void visitGetStm(GetStm s) {
          use(s.getBase(), s);
        }

        public void visitInsertStm(InsertStm s) {
          use(s.getBase(), s);
          if (s.getXMLSource() != null)
            use(s.getXMLSource(), s);
        }

        public void visitNodeStm(NodeStm s) {
          if (s.getFirstChild() != null)
            use(s.getFirstChild(), s);
          if (s.getFirstAttr() != null)
            use(s.getFirstAttr(), s);
          if (s.getNextNode() != null)
            use(s.getNextNode(), s);
        }

        public void visitNopStm(NopStm s) {
          // do nothing
        }

        public void visitPlugStm(PlugStm s) {
          use(s.getBase(), s);
          if (s.getXMLSource() != null)
            use(s.getXMLSource(), s);
        }

        public void visitRemoveStm(RemoveStm s) {
          use(s.getBase(), s);
        }

        public void visitSetStm(SetStm s) {
          use(s.getBase(), s);
          if (s.getXMLSource() != null)
            use(s.getXMLSource(), s);
        }

        public void visitUnknownStm(UnknownStm s) {
          // do nothing
        }

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

        public void visitVarStm(VarStm s) {
          use(s.getSource(), s);
        }
       
        // not in this phase
        public void visitArrayReadStm(ArrayReadStm s) {
        }
        public void visitArrayWriteStm(ArrayWriteStm s) {
        }
        public void visitArrayWriteStringStm(ArrayWriteStringStm s) {
        }
        public void visitCallStm(CallStm s) {
        }
        public void visitEscapeStm(EscapeStm s) {
        }
      });
   
    // insert edges from definitions to single global use
    for (Statement s : new LinkedHashSet<Statement>(graph.getNodes()))
      if (s instanceof Assignment) {
        Variable v = ((Assignment)s).getDest();
        if (v.isGlobal()) {
          Debug.println(6, true, "Redirecting join flow edge for " + v + " (assigned in " + s + ")");
          // remove the variable from the outflow of the statement
          for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(s))
            edge.getData().removeVariable(v);
          // insert new edge to the single global use (which only exists if it is used somewhere)
          if (global_use.containsKey(v)) {
            graph.addEdge(s, global_use.get(v), new VariableFilter(v));
          }
        }
      }
  }
View Full Code Here


      });

      // replace variables in edges
      // XXX this could take quadratic time. it could be improved easily
      for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(s)) {
        VariableFilter filter = edge.getData();
        for (Variable var : var_alias.getKeys())
          if (filter.containsVariable(var))
            filter.addVariable(var_alias.getRepresentativeKey(var)); // XXX: no need to remove var?
      }
    }
  }
View Full Code Here

        private void linkdefs(Statement use, Variable var) {
          Set<Assignment> defs = var_defs.get(var);
          if (defs != null)
            for (Assignment def : defs)
              graph.addEdge(def, use, new VariableFilter(var));
        }

        // statements that contain a definition but no uses - these always become entry nodes

        public void visitConstStm(ConstStm s) {
View Full Code Here

    }
    return changed;
  }
 
  public boolean transfer(Map<Variable,Set<Assignment>> in, Statement s, Map<Variable,Set<Assignment>> out) {
    VariableFilter filter = new VariableFilter();
    boolean changed = false;
    if (s instanceof Assignment) {
      Variable var = ((Assignment)s).getDest();
      changed |= setput(out, var, (Assignment)s);
      filter.removeVariable(var);
    }
    changed |= merge(in, filter, out);
    return changed;
  }
View Full Code Here

      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);
      VariableFilter resultFilter = new VariableFilter(call.getResult(), VariableFilter.Kind.RETURN);
      VariableFilter returnFilter = new VariableFilter(target.getReturnVar());
      for (int i=0; i<args.length; i++) {
        paramsOnly.addVariable(params[i]);
        argsOnly.addVariable(args[i]);
        notArgs.removeVariable(args[i]);
        if (call.isArgumentMutable(i)) {
          resultFilter.addVariable(call.getArgument(i));
          returnFilter.addVariable(target.getParameter(i));
        }
      }
      cfg.addFilter(argsOnly);
      for (int i=0; i<args.length; i++) {
        cfg.addStatement(new VarStm(params[i], args[i], call.getOrigin()));
      }
      graph.addEdge(cfg.currentStatement(), target.getEntry(), paramsOnly);
      cfg.moveToStatement(target.getExit());
      cfg.addStatement(new VarStm(call.getResult(), target.getReturnVar(), call.getOrigin()), returnFilter);
      /*for (int i=0; i<args.length; i++) {
        if (call.isArgumentMutable(i)) {
          cfg.addStatement(new VarStm(call.getArgument(i), target.getParameter(i), call.getOrigin()));
        }
      }*/
      cfg.addFilter(resultFilter);
      VariableFilter notResult = new VariableFilter(true);
      notResult.removeVariable(call.getResult());
      graph.addEdge(start, cfg.currentStatement(), notResult);
      StatementPair pair = cfg.finish();
      for (Edge<Statement,VariableFilter> edge : graph.getInEdges(call)) {
        graph.addEdge(edge.getFrom(), pair.first, edge.getData());
      }
View Full Code Here

          Unit stmt = entry.getKey();
          StatementPair translation = entry.getValue();
          // add successors
          for (Unit next : unitgraph.getSuccsOf(stmt)) {
            StatementPair nextt = translated.get(next);
            graph.addEdge(translation.last, nextt.first, new VariableFilter());
          }
          // add (exceptional) return edge
          graph.addEdge(translation.last, method.getExit(), new VariableFilter());
        }
        // add entry edges
        for (Unit head : unitgraph.getHeads()) {
          graph.addEdge(method.getEntry(), translated.get(head).first, new VariableFilter(true, VariableFilter.Kind.ENTRY));
        }
      }
    }
   
    // run string analysis
View Full Code Here

     */
    public void useBranch() {
        if (branches.empty()) {
            throw new IllegalStateException("No open branch. Call startBranch first");
        }
        graph.addEdge(lastStatement, branches.peek().end, new VariableFilter());
        lastStatement = branches.peek().start;
        branchWasUsed = true;
    }
View Full Code Here

      graph.addNode(s);
      currentOrigin = s.getOrigin();
        if (firstStatement == null) {
            firstStatement = s;
        } else {
          graph.addEdge(lastStatement, s, new VariableFilter());
        }
        lastStatement = s;
    }
View Full Code Here

          changed[0] |= out.copyFrom(in);
        }
      }
     
      public void visitNopStm(NopStm s) {
        changed[0] = merge(in, new VariableFilter(true), out);
      }
      public void visitEscapeStm(EscapeStm s) {
        changed[0] = merge(in, new VariableFilter(true), out);
      }
     
      public void visitCheckStm(CheckStm s) {
        val.transferCheck(s, getVar(in, s.getBase()));
        changed[0] = merge(in, new VariableFilter(true), out);
      }
     
      // not in this phase
      // XXX it makes sense to support these, but VariableAnalysis is never used in a phase that uses them
      public void visitArrayReadStm(ArrayReadStm s) {
View Full Code Here

TOP

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

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.