All Downloads are FREE. Search and download functionalities are using the official Maven repository.

soot.jimple.infoflow.collections.codeOptimization.ReplacementCandidates Maven / Gradle / Ivy

The newest version!
package soot.jimple.infoflow.collections.codeOptimization;

import java.util.HashSet;

import soot.SootMethod;
import soot.jimple.Stmt;
import soot.jimple.infoflow.solver.cfg.IInfoflowCFG;
import soot.jimple.toolkits.scalar.ConstantPropagatorAndFolder;

public class ReplacementCandidates extends HashSet {

	private static final long serialVersionUID = -9071828269301702785L;

	protected static class RTriple {
		private final SootMethod method;
		private final Stmt oldStmt;
		private final Stmt newStmt;

		private RTriple(SootMethod method, Stmt oldStmt, Stmt newStmt) {
			this.method = method;
			this.oldStmt = oldStmt;
			this.newStmt = newStmt;
		}

		private void replace() {
			method.getActiveBody().getUnits().swapWith(oldStmt, newStmt);
		}
	}

	public void add(SootMethod sm, Stmt oldStmt, Stmt newStmt) {
		add(new RTriple(sm, oldStmt, newStmt));
	}

	public void replace(IInfoflowCFG icfg) {
		HashSet changedMethods = new HashSet<>();
		for (RTriple rt : this) {
			rt.replace();
			changedMethods.add(rt.method);
		}

		for (SootMethod sm : changedMethods) {
			ConstantPropagatorAndFolder.v().transform(sm.getActiveBody());
			icfg.notifyMethodChanged(sm);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy