use of polyglot.ast.Node in project soot by Sable.
the class InitialResolver method handleFinalLocals.
private void handleFinalLocals(polyglot.ast.ClassMember member) {
MethodFinalsChecker mfc = new MethodFinalsChecker();
member.visit(mfc);
// System.out.println("mfc inners: "+mfc.inners());
if (cCallList == null) {
cCallList = new ArrayList<Node>();
}
cCallList.addAll(mfc.ccallList());
// System.out.println("cCallList: "+cCallList);
AnonLocalClassInfo alci = new AnonLocalClassInfo();
if (member instanceof polyglot.ast.ProcedureDecl) {
polyglot.ast.ProcedureDecl procedure = (polyglot.ast.ProcedureDecl) member;
// not sure if this will break deep nesting
alci.finalLocalsAvail(mfc.finalLocals());
if (procedure.flags().isStatic()) {
alci.inStaticMethod(true);
}
} else if (member instanceof polyglot.ast.FieldDecl) {
alci.finalLocalsAvail(new ArrayList<IdentityKey>());
if (((polyglot.ast.FieldDecl) member).flags().isStatic()) {
alci.inStaticMethod(true);
}
} else if (member instanceof polyglot.ast.Initializer) {
// for now don't make final locals avail in init blocks
// need to test this
alci.finalLocalsAvail(mfc.finalLocals());
if (((polyglot.ast.Initializer) member).flags().isStatic()) {
alci.inStaticMethod(true);
}
}
if (finalLocalInfo == null) {
finalLocalInfo = new HashMap<IdentityKey, AnonLocalClassInfo>();
}
Iterator<IdentityKey> it = mfc.inners().iterator();
while (it.hasNext()) {
polyglot.types.ClassType cType = (polyglot.types.ClassType) it.next().object();
// do the comparison about locals avail and locals used here
HashMap<IdentityKey, ArrayList<IdentityKey>> typeToLocalUsed = mfc.typeToLocalsUsed();
ArrayList<IdentityKey> localsUsed = new ArrayList<IdentityKey>();
if (typeToLocalUsed.containsKey(new polyglot.util.IdentityKey(cType))) {
ArrayList localsNeeded = typeToLocalUsed.get(new polyglot.util.IdentityKey(cType));
Iterator usesIt = localsNeeded.iterator();
while (usesIt.hasNext()) {
polyglot.types.LocalInstance li = (polyglot.types.LocalInstance) ((polyglot.util.IdentityKey) usesIt.next()).object();
if (alci.finalLocalsAvail().contains(new polyglot.util.IdentityKey(li))) {
localsUsed.add(new polyglot.util.IdentityKey(li));
}
}
}
AnonLocalClassInfo info = new AnonLocalClassInfo();
info.inStaticMethod(alci.inStaticMethod());
info.finalLocalsAvail(localsUsed);
if (!finalLocalInfo.containsKey(new polyglot.util.IdentityKey(cType))) {
finalLocalInfo.put(new polyglot.util.IdentityKey(cType), info);
}
}
}
Aggregations