Browse Source

support for method argument default values

master
Julian Dolby 4 years ago
parent
commit
533d392bda
  1. 4
      com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/ClosureExtractor.java
  2. 3
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java
  3. 2
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/TranslatorToCAst.java
  4. 2
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/AstConstantFolder.java
  5. 4
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/CAstCloner.java
  6. 20
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/CAstRewriter.java
  7. 4
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/visit/CAstVisitor.java
  8. 5
      com.ibm.wala.core/src/com/ibm/wala/classLoader/IMethod.java

4
com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/ClosureExtractor.java

@ -562,6 +562,10 @@ public class ClosureExtractor extends CAstRewriterExt {
public CAstNodeTypeMap newTypes() { return theTypes; }
@Override
public Map<CAstNode, Collection<CAstEntity>> newChildren() { return theChildren; }
@Override
public CAstNode[] newDefaults() {
return null;
}
};
new_entity.setRewrite(rw);

3
com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java

@ -815,7 +815,8 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}
}
}).copy(sourceContext.unwindAst, sourceContext.astContext.getControlFlow(), sourceContext.astContext.getSourceMap(),
sourceContext.astContext.top().getNodeTypeMap(), sourceContext.astContext.top().getAllScopedEntities());
sourceContext.astContext.top().getNodeTypeMap(), sourceContext.astContext.top().getAllScopedEntities(),
sourceContext.astContext.top().getArgumentDefaults());
sourceContext.astVisitor.visit(ast.newRoot(), new DelegatingContext(sourceContext.astContext) {
@Override
public CAstSourcePositionMap getSourceMap() {

2
com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/TranslatorToCAst.java

@ -296,7 +296,7 @@ public interface TranslatorToCAst {
if (replicateForDoLoops) {
loopBody = Ast.makeNode(CAstNode.BLOCK_STMT, loopBody, continueNode);
CAstRewriter.Rewrite x = (new CAstCloner(Ast, false)).copy(loopBody, wc.cfg(), wc.pos(), wc.getNodeTypeMap(), null);
CAstRewriter.Rewrite x = (new CAstCloner(Ast, false)).copy(loopBody, wc.cfg(), wc.pos(), wc.getNodeTypeMap(), null, null);
CAstNode otherBody = x.newRoot();
wc.cfg().addAll(x.newCfg());

2
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/AstConstantFolder.java

@ -46,7 +46,7 @@ public class AstConstantFolder {
}
}
}.rewrite(ce.getAST(), ce.getControlFlow(), ce.getSourceMap(), ce.getNodeTypeMap(), ce.getAllScopedEntities());
}.rewrite(ce.getAST(), ce.getControlFlow(), ce.getSourceMap(), ce.getNodeTypeMap(), ce.getAllScopedEntities(), ce.getArgumentDefaults());
return new DelegatingEntity(ce) {
@Override

4
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/CAstCloner.java

@ -62,7 +62,7 @@ public class CAstCloner extends CAstBasicRewriter<CAstBasicRewriter.NonCopyingCo
}
public Rewrite copy(CAstNode root, final CAstControlFlowMap cfg, final CAstSourcePositionMap pos, final CAstNodeTypeMap types,
final Map<CAstNode, Collection<CAstEntity>> children) {
return rewrite(root, cfg, pos, types, children);
final Map<CAstNode, Collection<CAstEntity>> children, CAstNode[] defaults) {
return rewrite(root, cfg, pos, types, children, defaults);
}
}

20
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/rewrite/CAstRewriter.java

@ -100,6 +100,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
Map<CAstNode, Collection<CAstEntity>> newChildren();
CAstNode[] newDefaults();
}
protected final CAst Ast;
@ -342,9 +343,14 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
* rewrite the CAst sub-tree rooted at root
*/
public Rewrite rewrite(final CAstNode root, final CAstControlFlowMap cfg, final CAstSourcePositionMap pos, final CAstNodeTypeMap types,
final Map<CAstNode, Collection<CAstEntity>> children) {
final Map<CAstNode, Collection<CAstEntity>> children, final CAstNode[] defaults) {
final Map<Pair<CAstNode, K>, CAstNode> nodes = HashMapFactory.make();
final CAstNode newRoot = copyNodes(root, cfg, rootContext, nodes);
final CAstNode newDefaults[] = new CAstNode[ defaults==null? 0: defaults.length ];
for(int i = 0; i < newDefaults.length; i++) {
newDefaults[i] = copyNodes(defaults[i], cfg, rootContext, nodes);
}
return new Rewrite() {
private CAstControlFlowMap theCfg = null;
@ -354,6 +360,11 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
private Map<CAstNode, Collection<CAstEntity>> theChildren = null;
@Override
public CAstNode[] newDefaults() {
return newDefaults;
}
@Override
public CAstNode newRoot() {
return newRoot;
@ -397,7 +408,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
if (root.getAST() != null) {
final Rewrite rewrite = rewrite(root.getAST(), root.getControlFlow(), root.getSourceMap(), root.getNodeTypeMap(),
root.getAllScopedEntities());
root.getAllScopedEntities(), root.getArgumentDefaults());
return new DelegatingEntity(root) {
@Override
@ -439,6 +450,11 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
public CAstControlFlowMap getControlFlow() {
return rewrite.newCfg();
}
@Override
public CAstNode[] getArgumentDefaults() {
return rewrite.newDefaults();
}
};
} else if (recursive) {

4
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/visit/CAstVisitor.java

@ -184,6 +184,10 @@ public abstract class CAstVisitor<C extends CAstVisitor.Context> {
break;
}
case CAstEntity.FUNCTION_ENTITY: {
for(CAstNode dflt : n.getArgumentDefaults()) {
visitor.visit(dflt, context, visitor);
visitor.visitScopedEntities(context.top(), context.top().getScopedEntities(dflt), context, visitor);
}
C codeContext = visitor.makeCodeContext(context, n);
if (visitor.visitFunctionEntity(n, context, codeContext, visitor))
break;

5
com.ibm.wala.core/src/com/ibm/wala/classLoader/IMethod.java

@ -160,4 +160,9 @@ public interface IMethod extends IMember, ContextItem {
* @return true iff the local variable table information for this method is available
*/
boolean hasLocalVariableTable();
default int getNumberOfDefaultParameters() {
return 0;
}
}

Loading…
Cancel
Save