當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalUses類代碼示例

本文整理匯總了Java中soot.toolkits.scalar.LocalUses的典型用法代碼示例。如果您正苦於以下問題:Java LocalUses類的具體用法?Java LocalUses怎麽用?Java LocalUses使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalUses類屬於soot.toolkits.scalar包,在下文中一共展示了LocalUses類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: collectDefinitionsWithAliases

import soot.toolkits.scalar.LocalUses; //導入依賴的package包/類
/**
 * Collect definitions of l in body including the definitions of aliases of
 * l.
 * 
 * In this context an alias is a local that propagates its value to l.
 * 
 * @param l
 *            the local whose definitions are to collect
 * @param localDefs
 *            the LocalDefs object
 * @param body
 *            the body that contains the local
 */
protected List<Unit> collectDefinitionsWithAliases(Local l,
		LocalDefs localDefs, LocalUses localUses, Body body) {
	Set<Local> seenLocals = new HashSet<Local>();
	Stack<Local> newLocals = new Stack<Local>();
	List<Unit> defs = new LinkedList<Unit>();
	newLocals.push(l);

	while (!newLocals.empty()) {
		Local local = newLocals.pop();
		Debug.printDbg("[null local] ", local);
		if (!seenLocals.add(local))
			continue;
		for (Unit u : collectDefinitions(local, localDefs, body)) {
			if (u instanceof AssignStmt) {
				Value r = ((AssignStmt) u).getRightOp();
				if (r instanceof Local && !seenLocals.contains((Local) r))
					newLocals.push((Local) r);
			}
			defs.add(u);
			//
			List<UnitValueBoxPair> usesOf = (List<UnitValueBoxPair>) localUses
					.getUsesOf(u);
			for (UnitValueBoxPair pair : usesOf) {
				Unit unit = pair.getUnit();
				if (unit instanceof AssignStmt) {
					Value right = ((AssignStmt) unit).getRightOp();
					Value left = ((AssignStmt) unit).getLeftOp();
					if (right == local && left instanceof Local
							&& !seenLocals.contains((Local) left))
						newLocals.push((Local) left);
				}
			}
			//
		}
	}
	return defs;
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:51,代碼來源:DexTransformer.java

示例2: internalTransform

import soot.toolkits.scalar.LocalUses; //導入依賴的package包/類
/** This method change all new Obj/<init>(args) pairs to new Obj(args) idioms. */
protected void internalTransform(Body b, String phaseName, Map options)
{
    GrimpBody body = (GrimpBody)b;

    if(Options.v().verbose())
        G.v().out.println("[" + body.getMethod().getName() +
            "] Folding constructors...");

  Chain units = body.getUnits();
  List<Unit> stmtList = new ArrayList<Unit>();
  stmtList.addAll(units);

  Iterator<Unit> it = stmtList.iterator();
  
  LocalUses localUses = LocalUses.Factory.newLocalUses(b);

  /* fold in NewExpr's with specialinvoke's */
  while (it.hasNext())
    {
      Stmt s = (Stmt)it.next();
        
      if (!(s instanceof AssignStmt))
        continue;
        
      /* this should be generalized to ArrayRefs */
      Value lhs = ((AssignStmt)s).getLeftOp();
      if (!(lhs instanceof Local))
        continue;
        
      Value rhs = ((AssignStmt)s).getRightOp();
      if (!(rhs instanceof NewExpr))
        continue;

      /* TO BE IMPLEMENTED LATER: move any copy of the object reference
         for lhs down beyond the NewInvokeExpr, with the rationale
         being that you can't modify the object before the constructor
         call in any case.

         Also, do note that any new's (object creation) without
         corresponding constructors must be dead. */
       
      List lu = localUses.getUsesOf(s);
      Iterator luIter = lu.iterator();
      boolean MadeNewInvokeExpr = false;
       
      while (luIter.hasNext())
        {
          Unit use = ((UnitValueBoxPair)(luIter.next())).unit;
          if (!(use instanceof InvokeStmt))
            continue;
          InvokeStmt is = (InvokeStmt)use;
          if (!(is.getInvokeExpr() instanceof SpecialInvokeExpr) ||
              lhs != ((SpecialInvokeExpr)is.getInvokeExpr()).getBase())
            continue;
          
          SpecialInvokeExpr oldInvoke = 
            ((SpecialInvokeExpr)is.getInvokeExpr());
          LinkedList invokeArgs = new LinkedList();
          for (int i = 0; i < oldInvoke.getArgCount(); i++)
            invokeArgs.add(oldInvoke.getArg(i));
          
          AssignStmt constructStmt = Grimp.v().newAssignStmt
            ((AssignStmt)s);
          constructStmt.setRightOp
            (Grimp.v().newNewInvokeExpr
             (((NewExpr)rhs).getBaseType(), oldInvoke.getMethodRef(), invokeArgs));
          MadeNewInvokeExpr = true;
          
          use.redirectJumpsToThisTo(constructStmt);
          units.insertBefore(constructStmt, use);
          units.remove(use);
        }
      if (MadeNewInvokeExpr)
        {
          units.remove(s);
        }
    }
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:80,代碼來源:ConstructorFolder.java

示例3: internalTransform

import soot.toolkits.scalar.LocalUses; //導入依賴的package包/類
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
       ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v(), true);
       LocalDefs localDefs = LocalDefs.Factory.newLocalDefs(graph);
       LocalUses localUses = null;
       LocalCreation localCreation = null;
       
	// If a return statement's operand has only one definition and this is
	// a copy statement, we take the original operand
	for (Unit u : body.getUnits())
		if (u instanceof ReturnStmt) {
			ReturnStmt retStmt = (ReturnStmt) u;
			if (retStmt.getOp() instanceof Local) {
				List<Unit> defs = localDefs.getDefsOfAt((Local) retStmt.getOp(), retStmt);
				if (defs.size() == 1 && defs.get(0) instanceof AssignStmt) {
					AssignStmt assign = (AssignStmt) defs.get(0);
					final Value rightOp = assign.getRightOp();
					final Value leftOp = assign.getLeftOp();
					
					// Copy over the left side if it is a local
					if (rightOp instanceof Local) {
						// We must make sure that the definition we propagate to
						// the return statement is not overwritten in between
						// a = 1; b = a; a = 3; return b; may not be translated
						// to return a;
						if (!isRedefined((Local) rightOp, u, assign, graph))
							retStmt.setOp(rightOp);
					}
					else if (rightOp instanceof Constant) {
						retStmt.setOp(rightOp);
					}
					// If this is a field access which has no other uses,
					// we rename the local to help splitting
					else if (rightOp instanceof FieldRef) {
						if (localUses == null)
							localUses = LocalUses.Factory.newLocalUses(body, localDefs);
						if (localUses.getUsesOf(assign).size() == 1) {
							if (localCreation == null)
								localCreation = new LocalCreation(body.getLocals(), "ret");
							Local newLocal = localCreation.newLocal(leftOp.getType());
							assign.setLeftOp(newLocal);
							retStmt.setOp(newLocal);
						}
					}
				}
			}
		}
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:49,代碼來源:DexReturnValuePropagator.java


注:本文中的soot.toolkits.scalar.LocalUses類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。