Avoid plugging in the same AST node twice when creating code for a
method call. git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4444 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
96f0d763d2
commit
daf36902bd
|
@ -171,7 +171,7 @@ public class RhinoToAstTranslator {
|
|||
private static class BaseCollectingContext extends JavaScriptTranslatorToCAst.BaseCollectingContext<WalkContext, Node> implements WalkContext {
|
||||
|
||||
BaseCollectingContext(WalkContext parent, Node initialBaseFor,
|
||||
CAstNode baseVar) {
|
||||
String baseVar) {
|
||||
super(parent, initialBaseFor, baseVar);
|
||||
}
|
||||
|
||||
|
@ -719,22 +719,23 @@ public class RhinoToAstTranslator {
|
|||
|
||||
private CAstNode visitObjectRead(AstNode n, AstNode objAst, CAstNode elt, WalkContext context) {
|
||||
CAstNode obj = visit(objAst, context);
|
||||
CAstNode baseVar = context.getBaseVarIfRelevant(n);
|
||||
String baseVar = context.getBaseVarIfRelevant(n);
|
||||
|
||||
CAstNode get, result;
|
||||
if (baseVar != null) {
|
||||
result = Ast.makeNode(CAstNode.BLOCK_EXPR, Ast.makeNode(CAstNode.ASSIGN, baseVar, obj),
|
||||
get = Ast.makeNode(CAstNode.OBJECT_REF, baseVar, elt));
|
||||
} else {
|
||||
result = get = Ast.makeNode(CAstNode.OBJECT_REF, obj, elt);
|
||||
}
|
||||
result = Ast.makeNode(CAstNode.BLOCK_EXPR,
|
||||
Ast.makeNode(CAstNode.ASSIGN, Ast.makeNode(CAstNode.VAR, Ast.makeConstant(baseVar)), obj),
|
||||
get = Ast.makeNode(CAstNode.OBJECT_REF, Ast.makeNode(CAstNode.VAR, Ast.makeConstant(baseVar)), elt));
|
||||
} else {
|
||||
result = get = Ast.makeNode(CAstNode.OBJECT_REF, obj, elt);
|
||||
}
|
||||
|
||||
if (context.getCatchTarget() != null) {
|
||||
context.cfg().map(get, get);
|
||||
context.cfg().add(get, context.getCatchTarget(), JavaScriptTypes.TypeError);
|
||||
}
|
||||
if (context.getCatchTarget() != null) {
|
||||
context.cfg().map(get, get);
|
||||
context.cfg().add(get, context.getCatchTarget(), JavaScriptTypes.TypeError);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -870,7 +871,7 @@ public class RhinoToAstTranslator {
|
|||
if (!isPrimitiveCall(context, n)) {
|
||||
CAstNode base = Ast.makeNode(CAstNode.VAR, Ast.makeConstant(baseVarName));
|
||||
AstNode callee = n.getTarget();
|
||||
WalkContext child = new BaseCollectingContext(context, callee, base);
|
||||
WalkContext child = new BaseCollectingContext(context, callee, baseVarName);
|
||||
CAstNode fun = visit(callee, child);
|
||||
|
||||
// the first actual parameter appearing within the parentheses of the
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface JavaScriptTranslatorToCAst extends TranslatorToCAst {
|
|||
|
||||
CAstNode getCatchTarget();
|
||||
|
||||
CAstNode getBaseVarIfRelevant(T node);
|
||||
String getBaseVarIfRelevant(T node);
|
||||
|
||||
boolean foundBase(T node);
|
||||
|
||||
|
@ -66,7 +66,7 @@ public interface JavaScriptTranslatorToCAst extends TranslatorToCAst {
|
|||
return null;
|
||||
}
|
||||
|
||||
public CAstNode getBaseVarIfRelevant(T node) { return null; }
|
||||
public String getBaseVarIfRelevant(T node) { return null; }
|
||||
|
||||
public boolean foundBase(T node) { return false; }
|
||||
|
||||
|
@ -99,7 +99,7 @@ public interface JavaScriptTranslatorToCAst extends TranslatorToCAst {
|
|||
return parent.getCatchTarget();
|
||||
}
|
||||
|
||||
public CAstNode getBaseVarIfRelevant(T node) {
|
||||
public String getBaseVarIfRelevant(T node) {
|
||||
return parent.getBaseVarIfRelevant(node);
|
||||
}
|
||||
|
||||
|
@ -233,14 +233,14 @@ public interface JavaScriptTranslatorToCAst extends TranslatorToCAst {
|
|||
* the variable to be used to store the value of the expression passed as
|
||||
* the 'this' parameter
|
||||
*/
|
||||
private final CAstNode baseVar;
|
||||
private final String baseVar;
|
||||
|
||||
/**
|
||||
* have we discovered a value to be passed as the 'this' parameter?
|
||||
*/
|
||||
private boolean foundBase = false;
|
||||
|
||||
protected BaseCollectingContext(C parent, T initialBaseFor, CAstNode baseVar) {
|
||||
protected BaseCollectingContext(C parent, T initialBaseFor, String baseVar) {
|
||||
super(parent);
|
||||
baseFor.add( initialBaseFor );
|
||||
this.baseVar = baseVar;
|
||||
|
@ -251,7 +251,7 @@ public interface JavaScriptTranslatorToCAst extends TranslatorToCAst {
|
|||
* set foundBase to true. Otherwise, return <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public CAstNode getBaseVarIfRelevant(T node) {
|
||||
public String getBaseVarIfRelevant(T node) {
|
||||
if (baseFor.contains( node )) {
|
||||
foundBase = true;
|
||||
return baseVar;
|
||||
|
|
Loading…
Reference in New Issue