further work

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4465 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2012-02-17 20:15:26 +00:00
parent c9ee502acc
commit 78ef6e3a03
4 changed files with 15 additions and 30 deletions

View File

@ -384,9 +384,6 @@ processExceptions(n, context);
} }
} }
@Override
protected boolean useLexicalAccessesForExposedVars() {
return false;
}
} }

View File

@ -45,11 +45,6 @@ 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);
} }
@ -67,12 +62,7 @@ public class JSAstTranslator extends AstTranslator {
} }
protected boolean useLocalValuesForLexicalVars() { protected boolean useLocalValuesForLexicalVars() {
return !NEW_LEXICAL; return !AstTranslator.NEW_LEXICAL;
// return false;
}
protected boolean useLexicalAccessesForExposedVars() {
return NEW_LEXICAL;
} }
protected TypeReference defaultCatchType() { protected TypeReference defaultCatchType() {

View File

@ -600,7 +600,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
System.err.println(("looking up lexical parent " + definer)); System.err.println(("looking up lexical parent " + definer));
boolean foundOnStack = false; boolean foundOnStack = false;
if (r != null) { if (r != null && !AstTranslator.NEW_LEXICAL) {
if (! funargsOnly) { if (! funargsOnly) {
if (r.isReadOnly(accesses[i].getName())) { if (r.isReadOnly(accesses[i].getName())) {
assert isLoad; assert isLoad;

View File

@ -115,12 +115,6 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
*/ */
protected abstract boolean useLocalValuesForLexicalVars(); protected abstract boolean useLocalValuesForLexicalVars();
/**
* should variables accessed by nested entities be accessed with lexical
* access instructions in the declaring entity?
*/
protected abstract boolean useLexicalAccessesForExposedVars();
protected boolean topLevelFunctionsInGlobalScope() { protected boolean topLevelFunctionsInGlobalScope() {
return true; return true;
} }
@ -257,15 +251,14 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
// variables at the beginning of the method. // variables at the beginning of the method.
if (useLocalValuesForLexicalVars()) { if (useLocalValuesForLexicalVars()) {
context.cfg().addInstruction(new AstLexicalRead(new Access[0])); context.cfg().addInstruction(new AstLexicalRead(new Access[0]));
} } else {
if (useLexicalAccessesForExposedVars()) { // perform a lexical write to copy the value stored in the local
// associated with each parameter to the lexical name
final CAstEntity entity = context.top(); final CAstEntity entity = context.top();
Set<String> exposedNames = entity2ExposedNames.get(entity); Set<String> exposedNames = entity2ExposedNames.get(entity);
if (exposedNames != null) { if (exposedNames != null) {
for (String arg : entity.getArgumentNames()) { for (String arg : entity.getArgumentNames()) {
if (exposedNames.contains(arg)) { if (exposedNames.contains(arg)) {
// perform a lexical write to copy the value stored in the local
// associated with the parameter to the lexical name
final Scope currentScope = context.currentScope(); final Scope currentScope = context.currentScope();
Symbol symbol = currentScope.lookup(arg); Symbol symbol = currentScope.lookup(arg);
assert symbol.getDefiningScope() == currentScope; assert symbol.getDefiningScope() == currentScope;
@ -290,7 +283,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
* caller is responsible for ensuring that name is defined in the local scope. * caller is responsible for ensuring that name is defined in the local scope.
*/ */
protected int doLocalRead(WalkContext context, String name) { protected int doLocalRead(WalkContext context, String name) {
if (useLexicalAccessesForExposedVars()) { if (!useLocalValuesForLexicalVars()) {
CAstEntity entity = context.top(); CAstEntity entity = context.top();
Set<String> exposed = entity2ExposedNames.get(entity); Set<String> exposed = entity2ExposedNames.get(entity);
if (exposed != null && exposed.contains(name) && Arrays.asList(entity.getArgumentNames()).contains(name)) { if (exposed != null && exposed.contains(name) && Arrays.asList(entity.getArgumentNames()).contains(name)) {
@ -306,7 +299,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
* that nm is defined in the local scope. * that nm is defined in the local scope.
*/ */
protected void doLocalWrite(WalkContext context, String nm, int rval) { protected void doLocalWrite(WalkContext context, String nm, int rval) {
if (useLexicalAccessesForExposedVars()) { if (!useLocalValuesForLexicalVars()) {
CAstEntity entity = context.top(); CAstEntity entity = context.top();
Set<String> exposed = entity2ExposedNames.get(entity); Set<String> exposed = entity2ExposedNames.get(entity);
if (exposed != null && exposed.contains(nm) && Arrays.asList(entity.getArgumentNames()).contains(nm)) { if (exposed != null && exposed.contains(nm) && Arrays.asList(entity.getArgumentNames()).contains(nm)) {
@ -389,7 +382,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); markExposedInEnclosingEntities(context, name, definingScope, E, entityName, false);
return result; return result;
} }
} }
@ -454,7 +447,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); markExposedInEnclosingEntities(context, name, definingScope, E, context.getEntityName(E), true);
} }
} }
@ -4262,6 +4255,11 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
walkEntities(N, new RootContext(N, module)); walkEntities(N, new RootContext(N, module));
} }
/**
* set to true to use new handling of lexical scoping
*/
public final static boolean NEW_LEXICAL = false;
public void translate(final CAstEntity N, final WalkContext context) { public void translate(final CAstEntity N, final WalkContext context) {
walkEntities(N, context); walkEntities(N, context);
} }