当前位置: 首页>>代码示例>>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;未经允许,请勿转载。