fixed one CG building bug with useLocalsForLexicalVars() disabled

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4463 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2012-02-17 20:14:51 +00:00
parent c9d914304d
commit 8982d35800
2 changed files with 17 additions and 4 deletions

View File

@ -45,6 +45,11 @@ import com.ibm.wala.util.strings.Atom;
public class JSAstTranslator extends AstTranslator { public class JSAstTranslator extends AstTranslator {
private final static boolean DEBUG = false; private final static boolean DEBUG = false;
/**
* set to true to use new handling of lexical scoping
*/
public final static boolean NEW_LEXICAL = false;
public JSAstTranslator(JavaScriptLoader loader) { public JSAstTranslator(JavaScriptLoader loader) {
super(loader); super(loader);
} }
@ -62,11 +67,12 @@ public class JSAstTranslator extends AstTranslator {
} }
protected boolean useLocalValuesForLexicalVars() { protected boolean useLocalValuesForLexicalVars() {
return true; return !NEW_LEXICAL;
// return false;
} }
protected boolean useLexicalAccessesForExposedVars() { protected boolean useLexicalAccessesForExposedVars() {
return false; return NEW_LEXICAL;
} }
protected TypeReference defaultCatchType() { protected TypeReference defaultCatchType() {

View File

@ -389,6 +389,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
Access A = new Access(name, entityName, result); Access A = new Access(name, entityName, result);
//>>>>>>> .r4421 //>>>>>>> .r4421
context.cfg().addInstruction(new AstLexicalRead(A)); context.cfg().addInstruction(new AstLexicalRead(A));
addAccess(context, context.top(), A);
return result; return result;
} }
} }
@ -453,6 +454,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
// lexically-scoped variables must be written in their scope each time // lexically-scoped variables must be written in their scope each time
Access A = new Access(name, context.getEntityName(E), rval); Access A = new Access(name, context.getEntityName(E), rval);
context.cfg().addInstruction(new AstLexicalWrite(A)); context.cfg().addInstruction(new AstLexicalWrite(A));
addAccess(context, context.top(), A);
} }
} }
@ -480,6 +482,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
int result = context.currentScope().allocateTempValue(); int result = context.currentScope().allocateTempValue();
Access A = new Access(name, null, result); Access A = new Access(name, null, result);
context.cfg().addInstruction(new AstLexicalRead(A)); context.cfg().addInstruction(new AstLexicalRead(A));
addAccess(context, context.top(), A);
return result; return result;
} }
@ -516,6 +519,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
} else { } else {
Access A = new Access(name, null, rval); Access A = new Access(name, null, rval);
context.cfg().addInstruction(new AstLexicalWrite(A)); context.cfg().addInstruction(new AstLexicalWrite(A));
addAccess(context, context.top(), A);
} }
// globals can be treated as a single static location // globals can be treated as a single static location
@ -2649,13 +2653,15 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}; };
/** /**
* record that in entity e, the access is performed using a local variable. in * record that in entity e, the access is performed.
*
* If {@link #useLocalValuesForLexicalVars()} is true, the access is performed
* using a local variable. in
* {@link #patchLexicalAccesses(SSAInstruction[], Set)}, this information is * {@link #patchLexicalAccesses(SSAInstruction[], Set)}, this information is
* used to update an instruction that performs all the accesses at the * used to update an instruction that performs all the accesses at the
* beginning of the method and defines the locals. * beginning of the method and defines the locals.
*/ */
private void addAccess(WalkContext context, CAstEntity e, Access access) { private void addAccess(WalkContext context, CAstEntity e, Access access) {
assert useLocalValuesForLexicalVars();
context.getAccesses(e).add(access); context.getAccesses(e).add(access);
} }
@ -2833,6 +2839,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
// should just be AstLexicalRead for now; may add support for // should just be AstLexicalRead for now; may add support for
// AstLexicalWrite later // AstLexicalWrite later
assert instrs[i] instanceof AstLexicalRead; assert instrs[i] instanceof AstLexicalRead;
assert useLocalValuesForLexicalVars();
if (AC != null) { if (AC != null) {
((AstLexicalAccess) instrs[i]).setAccesses(AC); ((AstLexicalAccess) instrs[i]).setAccesses(AC);
} else { } else {