[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Methods/Fields in scene



Here's what I use to find methods that are not read... I have
a transformer that removes such fields (ptolemy.copernicus.kernel.UnusedFieldRemover)
along with statements that write to those fields (modulo a null check).
Note that this does not take information from the call graph into account...
Presumably it would be simple to only loop over reachable methods...

Set unusedFieldSet = new HashSet();
// Loop over all the actor instance classes and create the set of
// all fields.
for (Iterator i = Scene.v().getApplicationClasses().iterator();
i.hasNext();) {
SootClass entityClass = (SootClass)i.next();

unusedFieldSet.addAll(entityClass.getFields());
}

// Loop through all the methods and kill all the used fields.
for (Iterator i = Scene.v().getApplicationClasses().iterator();
i.hasNext();) {
SootClass entityClass = (SootClass)i.next();
for (Iterator methods = entityClass.getMethods().iterator();
methods.hasNext();) {
SootMethod method = (SootMethod)methods.next();
JimpleBody body = (JimpleBody)method.retrieveActiveBody();
for(Iterator stmts = body.getUnits().iterator();
stmts.hasNext();) {
Stmt stmt = (Stmt)stmts.next();
for (Iterator boxes = stmt.getUseBoxes().iterator();
boxes.hasNext();) {
ValueBox box = (ValueBox)boxes.next();
Value value = box.getValue();
if(value instanceof FieldRef) {
Object field = ((FieldRef)value).getField();
unusedFieldSet.remove(field);
}
}
}
}
}



At 08:06 PM 12/11/2002 -0500, Ankush Varma wrote:
I use invokeGraph.getTransitiveTargetsof(SootMethod) to get a list of all
methods reachable from a given method. Is there a way to find all reachable
fields too?

Ankush

-------------------------------------------------
Ankush Varma
Ph.D. Student / Graduate Research Assistant
DSP-CAD Research Group
Department of Electrical and Computer Engineering
University of Maryland, College Park.

email:
ankush@eng.umd.edu
not_ankush@yahoo.com

Home: 301-439-0438           Office: 301-405-3089
--------------------------------------------------