Package dk.brics.string.intermediate

Examples of dk.brics.string.intermediate.Method


    }

    // visit interprocedural successors
    if (s instanceof Return) {
      Return returnStm = (Return)s;
      Method method = s.getMethod();
      for (Call call : method.getCallSites()) {
        for (Statement afterCall : call.getSuccs()) {
          after = getInfoBefore(afterCall);
          changed = false;
          transferReturn(returnStm, call, afterCall);
          if (changed) {
View Full Code Here


   * @param returnStm the return statement.
   * @param call a call to the method containing the return statement.
   * @param to the statement receiving the alias information. This is a successor of <tt>call</tt>, and corresponds to the {@link #after} field.
   */
  private void transferReturn(Return returnStm, Call call, Statement to) {
    Method method = returnStm.getMethod();
    MethodHead head = method.getEntry();
    AliasInfo beforeCall = getInfoBefore(call);
    AliasStatus status;
    // add aliasing between arguments and return value
    // and corruption of parameters to corruption of arguments
    for (int i=0; i<head.params.length; i++) {
View Full Code Here

    Set<Method> methodQueue = new HashSet<Method>();
    methodQueue.addAll(methods);
    while (!methodQueue.isEmpty()) {
      // pop a method from the queue
      Iterator<Method> it = methodQueue.iterator();
      Method method = it.next();
      it.remove();
     
      // add defined fields backwards to all callers
      Set<Field> use = uses.getView(method);
      for (Call call : method.getCallSites()) {
        Method callerMethod = call.getMethod();
        if (callerMethod == method)
          continue;
       
        boolean changed = uses.addAll(callerMethod, use);
       
View Full Code Here

        }
        worklist.iterate();
    }

    public void transfer(Statement s) {
      Method method = s.getMethod();
     
        Set<Variable> after = getLiveAfter(s);
        Set<Variable> live = new HashSet<Variable>(after);
        live.removeAll(dv.definedVars(s));
        live.addAll(uv.usedVars(s));
        live.addAll(Arrays.asList(method.getEntry().params));
        live_before.put(s, live);
        for (Statement ps : s.getPreds()) {
            if (addLiveAfter(ps, live)) {
                worklist.add(ps);
            }
View Full Code Here

    this.translations.clear();
    this.catchers.clear();
    this.currentHotspots = new LinkedList<HotspotInfo>();
    findSourceFile();
   
    Method method = jt.getMethod(sootMethod);
    Body body = sootMethod.retrieveActiveBody();
   
    // use an exceptional unit graph for the nullness analysis
        ExceptionalUnitGraph exceptionalFlow = new ExceptionalUnitGraph(body);
        nullAnalysis = new NullnessAnalysis(exceptionalFlow);
       
        // prepare the reaching definitions analysis for the assertion creator
        LiveLocals liveness = new SimpleLiveLocals(exceptionalFlow);
        LocalDefs definitions = new SmartLocalDefs(exceptionalFlow, liveness);
       
        // translate each statement in isolation
        for (Unit unit : body.getUnits()) {
          Stmt stmt = (Stmt) unit;
          translateStmt(stmt);
        }
   
    // create intermediate Catch statements for every catch block
    for (Trap trap : body.getTraps()) {
      Catch ct = new Catch();
      method.addStatement(ct);
     
      // remember the Catch statement associated with the trap
      catchers.put(trap, ct);
     
      // add the catch block as successor
      ct.addSucc(translations.get(trap.getHandlerUnit()).getFirst());
    }
       
        // connect according to normal flow
        AssertionContext assertionContext = new AssertionContext(jt, definitions, translations, sootMethod);
        BriefUnitGraph normalFlow = new BriefUnitGraph(body);
        for (Unit stmt : body.getUnits()) {
            Statement tail = translations.get(stmt).getLast();
           
            if (stmt instanceof IfStmt) {
                // branching statement: link assertion in-between its successors
                IfStmt ifstmt = (IfStmt)stmt;
               
                Stmt trueSuccessor = ifstmt.getTarget();
                Stmt falseSuccessor = (Stmt)body.getUnits().getSuccOf(ifstmt);
                AssertionBranches assertions = assertionCreator.createAssertions(ifstmt, assertionContext);
               
                tail.addSucc(assertions.getWhenFalse().getFirst());
                tail.addSucc(assertions.getWhenTrue().getFirst());
               
                assertions.getWhenFalse().getLast().addSucc(translations.get(falseSuccessor).getFirst());
                assertions.getWhenTrue().getLast().addSucc(translations.get(trueSuccessor).getFirst());
            }
            else if (stmt instanceof LookupSwitchStmt) {
              LookupSwitchStmt sw = (LookupSwitchStmt)stmt;
             
              // add cases
              List<Integer> values = new ArrayList<Integer>();
              for (int i=0; i<sw.getTargetCount(); i++) {
                Stmt succ = (Stmt)sw.getTarget(i);
                AssertionBranch assertion = assertionCreator.createSwitchAssertions(sw.getKeyBox(), sw.getLookupValue(i), sw, assertionContext);
               
                tail.addSucc(assertion.getFirst());
                assertion.getLast().addSucc(translations.get(succ).getFirst());
               
                values.add(sw.getLookupValue(i));
              }
             
              // add default case
              AssertionBranch assertion = assertionCreator.createSwitchDefaultAssertions(sw.getKeyBox(), values, sw, assertionContext);
              tail.addSucc(assertion.getFirst());
              assertion.getLast().addSucc(translations.get(sw.getDefaultTarget()).getFirst());
            }
            else {
                // normal statement
              for (Unit succ : normalFlow.getSuccsOf(stmt)) {
                  tail.addSucc(translations.get(succ).getFirst());
              }
            }
        }
       
        // connect first statements to the head
        for (Unit stmt : normalFlow.getHeads()) {
          method.getEntry().addSucc(translations.get(stmt).getFirst());
        }
       
        // connect according to exceptional flow
        List<Catch> activeCatchers = new LinkedList<Catch>();
        for (Unit stmt : body.getUnits()) {
          // open and close catchers
          for (Trap trap : body.getTraps()) {
            if (trap.getBeginUnit() == stmt) {
              activeCatchers.add(catchers.get(trap));
            }
            if (trap.getEndUnit() == stmt) {
              activeCatchers.remove(catchers.get(trap));
            }
          }
         
          // if statement S might throw an exception, an edge from its
          // predecessors must go to the exceptional return and/or catcher.
         
          // set exceptional flow inside the translation (but not after)
          for (Statement stm : translations.get(stmt).getStatements()) {
            // return statements have no successors
            if (stm instanceof Return)
              continue;
           
            // exceptions don't get thrown if the statement completed
            // Call statements, however, may always throw an exception
            if (stm == translations.get(stmt).getLast() && !(stm instanceof Call))
              continue;
           
            for (Catch catcher : activeCatchers) {
              stm.addSuccIfAbsent(catcher);
            }
            stm.addSuccIfAbsent(method.getExceptionalReturn());
          }
         
          // set exceptional flow if the block fails immediately (before the first)
          for (Statement stm : translations.get(stmt).getFirst().getPreds()) {
            // avoid adding duplicate edges, so check if the exceptional edge is already there
            for (Catch catcher : activeCatchers) {
              stm.addSuccIfAbsent(catcher);
            }
            stm.addSuccIfAbsent(method.getExceptionalReturn());
          }
        }
       
        return currentHotspots;
  }
View Full Code Here

 
  public boolean translateConstructorCall(InstanceInvokeExpr expr,
      Variable callee, List<Variable> arguments,
      IntermediateFactory factory) {
    SootMethod sootMethod = expr.getMethod();
    Method method = factory.getMethod(sootMethod);
    if (method == null)
      return false;
   
    Variable var = factory.createVariable(VariableType.NONE);
    factory.addStatement(new Call(var, method, translateArguments(sootMethod, arguments, factory)));
View Full Code Here

  }
 
  public Variable translateMethodCall(InstanceInvokeExpr expr,
      SootMethod target, Variable callee, List<Variable> arguments,
      IntermediateFactory factory) {
    Method method = factory.getMethod(target);
    if (method == null)
      return null;
   
    Variable result = factory.createVariable(factory.fromSootType(target.getReturnType()));
   
View Full Code Here

  }

  public Variable translateStaticMethodCall(InvokeExpr expr,
      List<Variable> arguments, IntermediateFactory factory) {
    SootMethod sootMethod = expr.getMethod();
    Method method = factory.getMethod(sootMethod);
    if (method == null)
      return null;
   
    Variable result = factory.createVariable(factory.fromSootType(sootMethod.getReturnType()));
    factory.addStatement(new Call(result, method, translateArguments(sootMethod, arguments, factory)));
View Full Code Here

                        sa_ma[sa] = -1;
                    }
                    sa++;
                }
                Variable[] var_array = vars.toArray(new Variable[0]);
                Method m = new Method(application, sm.getName(), var_array);
                methods.add(m);
                sms_m.put(sm.getSignature(), m);
                sms_sa_ma.put(sm.getSignature(), sa_ma);
                sms_ma_sa.put(sm.getSignature(), ma_sa);
            }
View Full Code Here

       
        // Make tostring methods for application classes
        // Link toString calls to the hotspots for all superclasses of the
        // receiver type
        for (SootClass ac : getApplicationClasses()) {
            Method m = new Method(application, ac.getName() + ".toString",
                    new Variable[0]);
            methods.add(m);
            tostring_methods.put(ac.getName(), m);
            Variable var = application.createVariable(VariableType.STRING);
            StringStatement spot = new StringAssignment(var, var);
            m.addStatement(spot);
            Return ret = new Return(var);
            m.addStatement(ret);
            spot.addSucc(ret);
            tostring_hotspots.put(ac, spot); // these hotspots are used by
                                             // StringAnalysis.getTypeAutomaton
            Collection<SootClass> subtypes;
            if (ac.isInterface())
                subtypes = class_hierarchy.getImplementersOf(ac);
            else
                subtypes = class_hierarchy.getSubclassesOfIncluding(ac);
            for (SootClass ac2 : subtypes) {
                if (ac2.isPhantom() || ac2.isPhantomClass() || ac2.isInterface())
                    continue;
                Method target = tostring_targets.get(ac2);
                if (target == null)
                    continue;
                Call call = new Call(var, target, new Variable[0]);
                m.addStatement(call);
                m.getEntry().addSucc(call);
View Full Code Here

TOP

Related Classes of dk.brics.string.intermediate.Method

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.