Browse Source

1) a bit more source mappimg information

2) fixes to how Contexts are combined
master
Julian Dolby 4 years ago
parent
commit
b2503628a4
  1. 5
      com.ibm.wala.cast.java.ecj/.settings/org.eclipse.jdt.core.prefs
  2. 52
      com.ibm.wala.cast.java.ecj/src/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java
  3. 1
      com.ibm.wala.cast.java.test/.settings/org.eclipse.jdt.core.prefs
  4. 1
      com.ibm.wala.cast.js.html.nu_validator/.settings/org.eclipse.jdt.core.prefs
  5. 1
      com.ibm.wala.cast.js.nodejs.test/.settings/org.eclipse.jdt.core.prefs
  6. 1
      com.ibm.wala.cast.js.nodejs/.settings/org.eclipse.jdt.core.prefs
  7. 1
      com.ibm.wala.cast.js.rhino.test/.settings/org.eclipse.jdt.core.prefs
  8. 35
      com.ibm.wala.cast.js.rhino/source/com/ibm/wala/cast/js/translator/RhinoToAstTranslator.java
  9. 5
      com.ibm.wala.cast.js.test.data/.settings/org.eclipse.jdt.core.prefs
  10. 1
      com.ibm.wala.cast.js.test/.settings/org.eclipse.jdt.core.prefs
  11. 1
      com.ibm.wala.cast.js/.settings/org.eclipse.jdt.core.prefs
  12. 5
      com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/ExtractedFunction.java
  13. 1
      com.ibm.wala.cast.test/.settings/org.eclipse.jdt.core.prefs
  14. 6
      com.ibm.wala.cast.test/harness-src/java/com/ibm/wala/cast/test/TestConstantCollector.java
  15. 6
      com.ibm.wala.cast.test/harness-src/java/com/ibm/wala/cast/test/TestNativeTranslator.java
  16. 13
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java
  17. 2
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstMethod.java
  18. 5
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/CAstEntity.java
  19. 5
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/impl/DelegatingEntity.java
  20. 2
      com.ibm.wala.cast/source/java/com/ibm/wala/cast/util/AstConstantCollector.java
  21. 1
      com.ibm.wala.core.testdata/.settings/org.eclipse.jdt.core.prefs
  22. 1
      com.ibm.wala.core.testdata/src/cornerCases/Main.java
  23. 1
      com.ibm.wala.core.testdata/src/cornerCases/YuckyInterface.java
  24. 1
      com.ibm.wala.core.tests/.settings/org.eclipse.jdt.core.prefs
  25. 8
      com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/Java7CallGraphTest.java
  26. 3
      com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/KawaCallGraphTest.java
  27. 7
      com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java
  28. 2
      com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java
  29. 18
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextInterpreter.java
  30. 22
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextSelector.java
  31. 17
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassNewInstanceContextInterpreter.java
  32. 15
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetClassContextInterpeter.java
  33. 7
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetMethodContext.java
  34. 26
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetMethodContextInterpreter.java
  35. 57
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java
  36. 16
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ReflectiveInvocationInterpreter.java
  37. 13
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/java7/MethodHandles.java
  38. 1
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/AnalysisOptions.java
  39. 9
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/Context.java
  40. 12
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/ContextKey.java
  41. 5
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/DelegatingContext.java
  42. 9
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/BasicCallGraph.java
  43. 8
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/DelegatingContextSelector.java
  44. 3
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/AllocationSiteInNodeFactory.java
  45. 2
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java
  46. 2
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/SmushedAllocationSiteInstanceKeys.java
  47. 6
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/TargetMethodContextSelector.java
  48. 4
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/cfa/CallStringContext.java
  49. 15
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/cfa/CallStringContextSelector.java
  50. 16
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/cfa/ContainerContextSelector.java
  51. 7
      com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/cfa/DefaultPointerKeyFactory.java
  52. 2
      com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/SummarizedMethodWithNames.java
  53. 8
      com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/XMLMethodSummaryReader.java
  54. 5
      com.ibm.wala.dalvik.test/.settings/org.eclipse.jdt.core.prefs
  55. 2
      com.ibm.wala.dalvik.test/source/com/ibm/wala/dalvik/drivers/APKCallGraphDriver.java
  56. 1
      com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/dex/instructions/Invoke.java
  57. 1
      com.ibm.wala.dalvik/src/com/ibm/wala/dalvik/ssa/DexSSABuilder.java
  58. 1
      com.ibm.wala.ide.tests/.settings/org.eclipse.jdt.core.prefs
  59. 1
      com.ibm.wala.ide/.settings/org.eclipse.jdt.core.prefs
  60. 5
      com.ibm.wala.scandroid/.settings/org.eclipse.jdt.core.prefs
  61. 1
      com.ibm.wala.util/.settings/org.eclipse.jdt.core.prefs

5
com.ibm.wala.cast.java.ecj/.settings/org.eclipse.jdt.core.prefs

@ -9,8 +9,13 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=error
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=error

52
com.ibm.wala.cast.java.ecj/src/com/ibm/wala/cast/java/translator/jdt/JDTJava2CAstTranslator.java

@ -289,8 +289,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
private final T fSourcePosition;
private final T fNamePos;
public ClassEntity(ITypeBinding jdtType, String name, Collection<CAstQualifier> quals, Collection<CAstEntity> entities,
T pos) {
T pos, T namePos) {
fNamePos = namePos;
fName = name;
fQuals = quals;
fEntities = entities;
@ -396,6 +399,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
return fTypeDict.new JdtJavaType(fJdtType);
}
@Override
public Position getNamePosition() {
return fNamePos;
}
}
private static boolean isInterface(AbstractTypeDeclaration decl) {
@ -405,7 +413,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
private CAstEntity visitTypeDecl(AbstractTypeDeclaration n, WalkContext context) {
return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(), n.getName().getIdentifier(), n.getModifiers(),
isInterface(n), n instanceof AnnotationTypeDeclaration, context);
isInterface(n), n instanceof AnnotationTypeDeclaration, context, makePosition(n.getName()));
}
/**
@ -416,10 +424,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
* @param typeBinding
* @param name Used in creating default constructor, and passed into new ClassEntity()
* @param context
* @param namePos
*/
private CAstEntity createClassDeclaration(ASTNode n, List<BodyDeclaration> bodyDecls,
List<EnumConstantDeclaration> enumConstants, ITypeBinding typeBinding, String name, int modifiers,
boolean isInterface, boolean isAnnotation, WalkContext context) {
boolean isInterface, boolean isAnnotation, WalkContext context, T namePos) {
final List<CAstEntity> memberEntities = new ArrayList<>();
// find and collect all initializers (type Initializer) and field initializers (type VariableDeclarationFragment).
@ -465,7 +474,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
IVariableBinding fieldBinding = fieldFrag.resolveBinding();
memberEntities.add(new FieldEntity(fieldFrag.getName().getIdentifier(), fieldBinding.getType(), quals,
makePosition(fieldFrag.getStartPosition(), fieldFrag.getStartPosition() + fieldFrag.getLength()),
handleAnnotations(fieldBinding)));
handleAnnotations(fieldBinding), makePosition(fieldFrag.getName())));
}
} else if (decl instanceof Initializer) {
// Initializers are inserted into constructors when making constructors.
@ -526,12 +535,12 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
Collection<CAstQualifier> quals = JDT2CAstUtils.mapModifiersToQualifiers(modifiers, isInterface, isAnnotation);
return new ClassEntity(typeBinding, name, quals, memberEntities, makePosition(n));
return new ClassEntity(typeBinding, name, quals, memberEntities, makePosition(n), namePos);
}
private CAstEntity visit(AnonymousClassDeclaration n, WalkContext context) {
return createClassDeclaration(n, n.bodyDeclarations(), null, n.resolveBinding(),
JDT2CAstUtils.anonTypeName(n.resolveBinding()), 0 /* no modifiers */, false, false, context);
JDT2CAstUtils.anonTypeName(n.resolveBinding()), 0 /* no modifiers */, false, false, context, null);
}
private CAstNode visit(TypeDeclarationStatement n, WalkContext context) {
@ -1106,6 +1115,15 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
SingleVariableDeclaration p = (SingleVariableDeclaration) fDecl.parameters().get(arg);
return makePosition(p);
}
@Override
public Position getNamePosition() {
if (fDecl == null) {
return null;
} else {
return makePosition(fDecl);
}
}
}
// ////////////////////////////////////
@ -1158,13 +1176,16 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
private final T position;
private final T namePos;
private final Set<CAstAnnotation> annotations;
private FieldEntity(String name, ITypeBinding type, Collection<CAstQualifier> quals, T position, Set<CAstAnnotation> annotations) {
private FieldEntity(String name, ITypeBinding type, Collection<CAstQualifier> quals, T position, Set<CAstAnnotation> annotations, T namePos) {
super();
this.type = type;
this.quals = quals;
this.name = name;
this.namePos = namePos;
this.position = position;
this.annotations = annotations;
}
@ -1261,6 +1282,13 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
@Override
public Position getPosition(int arg) {
return namePos;
}
@Override
public Position getNamePosition() {
// TODO Auto-generated method stub
return null;
}
}
@ -3045,6 +3073,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
public Position getPosition(int arg) {
return null;
}
@Override
public Position getNamePosition() {
return null;
}
}
// /////////////////////////////
@ -3340,7 +3373,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
*/
private CAstEntity visit(EnumConstantDeclaration decl, WalkContext context) {
return new FieldEntity(decl.getName().getIdentifier(), decl.resolveVariable().getType(), enumQuals, makePosition(decl
.getStartPosition(), decl.getStartPosition() + decl.getLength()), null);
.getStartPosition(), decl.getStartPosition() + decl.getLength()), null, makePosition(decl.getName()));
}
/**
@ -3489,10 +3522,9 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
}
private CAstEntity visit(EnumDeclaration n, WalkContext context) {
// JDT contains correct type info / class / subclass info for the enum
return createClassDeclaration(n, n.bodyDeclarations(), n.enumConstants(), n.resolveBinding(), n.getName().getIdentifier(), n
.resolveBinding().getModifiers(), false, false, context);
.resolveBinding().getModifiers(), false, false, context, makePosition(n.getName()));
}
/**

1
com.ibm.wala.cast.java.test/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.cast.js.html.nu_validator/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.cast.js.nodejs.test/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.cast.js.nodejs/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.cast.js.rhino.test/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

35
com.ibm.wala.cast.js.rhino/source/com/ibm/wala/cast/js/translator/RhinoToAstTranslator.java

@ -409,7 +409,9 @@ public class RhinoToAstTranslator implements TranslatorToCAst {
private final CAstSourcePositionMap pos;
private final Position entityPosition;
private final Position namePosition;
private final Position[] paramPositions;
private ScriptOrFnEntity(AstNode n, Map<CAstNode, Collection<CAstEntity>> subs, CAstNode ast, CAstControlFlowMap map, CAstSourcePositionMap pos, String name) {
@ -418,6 +420,7 @@ public class RhinoToAstTranslator implements TranslatorToCAst {
if (n instanceof FunctionNode) {
FunctionNode f = (FunctionNode) n;
namePosition = makePosition(f.getFunctionName());
f.flattenSymbolTable(false);
int i = 0;
arguments = new String[f.getParamCount() + 2];
@ -436,6 +439,7 @@ public class RhinoToAstTranslator implements TranslatorToCAst {
} else {
paramPositions = new Position[0];
arguments = new String[0];
namePosition = null;
}
kind = (n instanceof FunctionNode) ? CAstEntity.FUNCTION_ENTITY : CAstEntity.SCRIPT_ENTITY;
this.subs = subs;
@ -538,6 +542,11 @@ public class RhinoToAstTranslator implements TranslatorToCAst {
public Position getPosition(int arg) {
return paramPositions[arg];
}
@Override
public Position getNamePosition() {
return namePosition;
}
}
private CAstEntity walkEntity(final AstNode n, List<CAstNode> body, String name, WalkContext child) {
@ -569,18 +578,22 @@ public class RhinoToAstTranslator implements TranslatorToCAst {
}
private Position makePosition(AstNode n) {
URL url = ((SourceModule)sourceModule).getURL();
int line = n.getLineno();
Position pos = new RangePosition(url, line, n.getAbsolutePosition(), n.getAbsolutePosition()+n.getLength());
if (sourceModule instanceof MappedSourceModule) {
Position np = ((MappedSourceModule) sourceModule).getMapping().getIncludedPosition(pos);
if (np != null) {
return np;
if (n != null) {
URL url = ((SourceModule)sourceModule).getURL();
int line = n.getLineno();
Position pos = new RangePosition(url, line, n.getAbsolutePosition(), n.getAbsolutePosition()+n.getLength());
if (sourceModule instanceof MappedSourceModule) {
Position np = ((MappedSourceModule) sourceModule).getMapping().getIncludedPosition(pos);
if (np != null) {
return np;
}
}
}
return pos;
return pos;
} else {
return null;
}
}
protected CAstNode noteSourcePosition(WalkContext context, CAstNode n, AstNode p) {

5
com.ibm.wala.cast.js.test.data/.settings/org.eclipse.jdt.core.prefs

@ -1,7 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

1
com.ibm.wala.cast.js.test/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.cast.js/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

5
com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/ExtractedFunction.java

@ -191,4 +191,9 @@ class ExtractedFunction implements CAstEntity {
public Position getPosition(int arg) {
return null;
}
@Override
public Position getNamePosition() {
return null;
}
}

1
com.ibm.wala.cast.test/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

6
com.ibm.wala.cast.test/harness-src/java/com/ibm/wala/cast/test/TestConstantCollector.java

@ -130,6 +130,12 @@ public class TestConstantCollector {
// TODO Auto-generated method stub
return null;
}
@Override
public Position getNamePosition() {
// TODO Auto-generated method stub
return null;
}
};
}

6
com.ibm.wala.cast.test/harness-src/java/com/ibm/wala/cast/test/TestNativeTranslator.java

@ -148,6 +148,12 @@ public class TestNativeTranslator {
// TODO Auto-generated method stub
return null;
}
@Override
public Position getNamePosition() {
// TODO Auto-generated method stub
return null;
}
};
}
}

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

@ -504,6 +504,8 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
private static class AstDebuggingInformation implements DebuggingInformation {
private Position codeBodyPosition;
private Position codeBodyNamePosition;
private String[][] valueNumberNames;
private Position[] instructionPositions;
@ -512,7 +514,9 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
private Position[] parameterPositions;
AstDebuggingInformation(Position codeBodyPosition, Position[] instructionPositions, Position[][] operandPositions, Position[] parameterPositions, String[] names) {
AstDebuggingInformation(Position codeBodyNamePosition, Position codeBodyPosition, Position[] instructionPositions, Position[][] operandPositions, Position[] parameterPositions, String[] names) {
this.codeBodyNamePosition = codeBodyNamePosition;
this.codeBodyPosition = codeBodyPosition;
this.instructionPositions = instructionPositions;
@ -536,6 +540,11 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
return codeBodyPosition;
}
@Override
public Position getCodeNamePosition() {
return codeBodyNamePosition;
}
@Override
public Position getInstructionPosition(int instructionOffset) {
return instructionPositions[instructionOffset];
@ -3386,7 +3395,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
Position[] parameterPositions = getParameterPositions(n);
DebuggingInformation DBG = new AstDebuggingInformation(n.getPosition(), line, operand, parameterPositions, nms);
DebuggingInformation DBG = new AstDebuggingInformation(n.getNamePosition(), n.getPosition(), line, operand, parameterPositions, nms);
// actually make code body
defineFunction(n, parentContext, cfg, symtab, katch, catchTypes, monitor, LI, DBG);

2
com.ibm.wala.cast/source/java/com/ibm/wala/cast/loader/AstMethod.java

@ -46,6 +46,8 @@ public abstract class AstMethod implements IMethod {
Position getCodeBodyPosition();
Position getCodeNamePosition();
Position getInstructionPosition(int instructionOffset);
String[][] getSourceNamesForValues();

5
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/CAstEntity.java

@ -161,6 +161,11 @@ public interface CAstEntity {
*/
CAstSourcePositionMap.Position getPosition();
/**
* The source position of the token denoting this entity's name.
*/
CAstSourcePositionMap.Position getNamePosition();
/**
* The source position of argument 'arg' this entity, if any;
*/

5
com.ibm.wala.cast/source/java/com/ibm/wala/cast/tree/impl/DelegatingEntity.java

@ -116,4 +116,9 @@ public class DelegatingEntity implements CAstEntity {
return base.getPosition(arg);
}
@Override
public Position getNamePosition() {
return base.getNamePosition();
}
}

2
com.ibm.wala.cast/source/java/com/ibm/wala/cast/util/AstConstantCollector.java

@ -35,7 +35,7 @@ public class AstConstantCollector {
Object val = s.getSingle("value").getValue();
if (! bad.contains(var)) {
if (values.containsKey(var)) {
if (!values.get(var).equals(val)) {
if (val == null? values.get(var) != null: !values.get(var).equals(val)) {
values.remove(var);
bad.add(var);
}

1
com.ibm.wala.core.testdata/.settings/org.eclipse.jdt.core.prefs vendored

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

1
com.ibm.wala.core.testdata/src/cornerCases/Main.java vendored

@ -19,7 +19,6 @@ import sun.java2d.FontSupport;
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
@SuppressWarnings("restriction")
public class Main {
public static void main(String[] args) {

1
com.ibm.wala.core.testdata/src/cornerCases/YuckyInterface.java vendored

@ -18,7 +18,6 @@ import sun.java2d.FontSupport;
* When analyzed with J2EEClassHierarchy exclusions, the superinterface
* FontSupport should not be found because we exclude sun.java2d.*
*/
@SuppressWarnings("restriction")
public interface YuckyInterface extends FontSupport {

1
com.ibm.wala.core.tests/.settings/org.eclipse.jdt.core.prefs

@ -10,6 +10,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8

8
com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/Java7CallGraphTest.java

@ -18,6 +18,7 @@ import java.util.jar.JarFile;
import org.junit.Test;
import com.ibm.wala.analysis.reflection.java7.MethodHandles;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.core.tests.shrike.DynamicCallGraphTestBase;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
@ -54,14 +55,17 @@ public class Java7CallGraphTest extends DynamicCallGraphTestBase {
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lpack/ocamljavaMain");
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
options.setUseConstantSpecificKeys(true);
IAnalysisCacheView cache = new AnalysisCacheImpl();
SSAPropagationCallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);
MethodHandles.analyzeMethodHandles(options, builder);
CallGraph cg = builder.makeCallGraph(options, null);
System.err.println(cg);
instrument(F.getAbsolutePath());
run("pack.ocamljavaMain", null, args);

3
com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/KawaCallGraphTest.java

@ -53,6 +53,7 @@ public class KawaCallGraphTest extends DynamicCallGraphTestBase {
Set<CGNode> color = getNodes(CG, "Lchess", "startingColor", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
assert ! color.isEmpty();
System.out.println(CG);
}
@Test
@ -78,7 +79,7 @@ public class KawaCallGraphTest extends DynamicCallGraphTestBase {
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
IAnalysisCacheView cache = new AnalysisCacheImpl();
options.setReflectionOptions(ReflectionOptions.NONE);
options.setReflectionOptions(ReflectionOptions.STRING_ONLY);
options.setTraceStringConstants(true);
options.setUseConstantSpecificKeys(true);

7
com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/ReflectionTest.java

@ -29,6 +29,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
@ -278,9 +279,8 @@ public class ReflectionTest extends WalaTestCase {
for (CGNode node : mainChildren) {
Context context = node.getContext();
if (context instanceof ReceiverInstanceContext && node.getMethod().getReference().equals(newInstanceMr)) {
ReceiverInstanceContext r = (ReceiverInstanceContext) context;
ConstantKey<IMethod> c = (ConstantKey<IMethod>) r.getReceiver();
if (context.isA(ReceiverInstanceContext.class) && node.getMethod().getReference().equals(newInstanceMr)) {
ConstantKey<IMethod> c = (ConstantKey<IMethod>) context.get(ContextKey.RECEIVER);
IMethod ctor = c.getValue();
if (ctor.getSignature().equals(fpInitSig)) {
filePermConstrNewInstanceNode = node;
@ -377,6 +377,7 @@ public class ReflectionTest extends WalaTestCase {
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/lang/Integer");
MethodReference mr = MethodReference.findOrCreate(tr, "toString", "()Ljava/lang/String;");
Set<CGNode> nodes = cg.getNodes(mr);
System.err.println(cg);
Assert.assertFalse(nodes.isEmpty());
}

2
com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java

@ -208,7 +208,7 @@ public abstract class DynamicCallGraphTestBase extends WalaTestCase {
if (! filter.test(callerRef)) {
continue loop;
}
Assert.assertEquals(callerMethod, 1, nodes.size());
Assert.assertEquals(callerRef.toString(), 1, nodes.size());
caller = nodes.iterator().next();
}

18
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextInterpreter.java

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import com.ibm.wala.analysis.typeInference.TypeAbstraction;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference;
@ -21,6 +22,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.summaries.SyntheticIR;
import com.ibm.wala.ssa.DefUse;
@ -63,7 +66,7 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
/** BEGIN Custom change: caching */
final JavaTypeContext context = (JavaTypeContext) node.getContext();
final Context context = node.getContext();
final IMethod method = node.getMethod();
final String hashKey = method.toString() + "@" + context.toString();
@ -97,7 +100,7 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (!(node.getContext() instanceof JavaTypeContext)) {
if (!(node.getContext().isA(JavaTypeContext.class))) {
return false;
}
return ClassFactoryContextSelector.isClassFactory(node.getMethod().getReference());
@ -112,8 +115,7 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
throw new IllegalArgumentException("node is null");
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
TypeReference tr = ((TypeAbstraction)node.getContext().get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
return new NonNullSingletonIterator<>(NewSiteReference.make(0, tr));
}
@ -129,12 +131,12 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
return EmptyIterator.instance();
}
private static SSAInstruction[] makeStatements(JavaTypeContext context) {
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
private static SSAInstruction[] makeStatements(Context context) {
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
ArrayList<SSAInstruction> statements = new ArrayList<>();
// vn1 is the string parameter
int retValue = 2;
TypeReference tr = context.getType().getTypeReference();
TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr);
statements.add(l);
@ -149,7 +151,7 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
return result;
}
private static IR makeIR(IMethod method, JavaTypeContext context) {
private static IR makeIR(IMethod method, Context context) {
SSAInstruction instrs[] = makeStatements(context);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null);
}

22
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextSelector.java

@ -13,10 +13,12 @@ package com.ibm.wala.analysis.reflection;
import com.ibm.wala.analysis.typeInference.PointType;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IClassLoader;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR;
@ -103,19 +105,35 @@ class ClassFactoryContextSelector implements ContextSelector {
return new JavaTypeContext(new PointType(klass));
}
}
int nameVn = callee.isStatic()? 0: 1;
if (receiver != null && receiver.length > nameVn) {
if (receiver[nameVn] instanceof ConstantKey) {
ConstantKey ik = (ConstantKey) receiver[nameVn];
if (ik.getConcreteType().getReference().equals(TypeReference.JavaLangString)) {
String className = StringStuff.deployment2CanonicalTypeString(ik.getValue().toString());
for(IClassLoader cl : caller.getClassHierarchy().getLoaders()) {
TypeReference t = TypeReference.findOrCreate(cl.getReference(), className);
IClass klass = caller.getClassHierarchy().lookupClass(t);
if (klass != null) {
return new JavaTypeContext(new PointType(klass));
}
}
}
}
}
}
return null;
}
private static final IntSet thisParameter = IntSetUtil.make(new int[]{0});
private static final IntSet firstParameter = IntSetUtil.make(new int[]{1});
private static final IntSet firstParameter = IntSetUtil.make(new int[]{0, 1});
@Override
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
if (isClassFactory(site.getDeclaredTarget())) {
SSAAbstractInvokeInstruction[] invokeInstructions = caller.getIR().getCalls(site);
if (invokeInstructions.length != 1) {
if (invokeInstructions.length >= 1) {
if (invokeInstructions[0].isStatic()) {
return thisParameter;
} else {

17
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassNewInstanceContextInterpreter.java

@ -13,6 +13,7 @@ package com.ibm.wala.analysis.reflection;
import java.util.Iterator;
import java.util.Map;
import com.ibm.wala.analysis.typeInference.TypeAbstraction;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference;
@ -20,6 +21,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ipa.summaries.SyntheticIR;
@ -81,7 +84,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
}
/** BEGIN Custom change: caching */
final JavaTypeContext context = (JavaTypeContext) node.getContext();
final Context context = node.getContext();
final IMethod method = node.getMethod();
final String hashKey = method.toString() + "@" + context.toString();
@ -112,7 +115,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (!(node.getContext() instanceof JavaTypeContext)) {
if (!(node.getContext().isA(JavaTypeContext.class))) {
return false;
}
return node.getMethod().getReference().equals(CLASS_NEW_INSTANCE_REF);
@ -124,8 +127,8 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
throw new IllegalArgumentException("node is null");
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
Context context = node.getContext();
TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
return new NonNullSingletonIterator<>(NewSiteReference.make(0, tr));
}
@ -138,9 +141,9 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
return EmptyIterator.instance();
}
private IR makeIR(IMethod method, JavaTypeContext context) {
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
TypeReference tr = context.getType().getTypeReference();
private IR makeIR(IMethod method, Context context) {
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
SpecializedMethod m = new SpecializedMethod(method, method.getDeclaringClass(), method.isStatic(), false);
IClass klass = cha.lookupClass(tr);

15
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetClassContextInterpeter.java

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import com.ibm.wala.analysis.typeInference.TypeAbstraction;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference;
@ -21,6 +22,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.summaries.SyntheticIR;
import com.ibm.wala.ssa.DefUse;
@ -59,7 +62,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
}
/** BEGIN Custom change: caching */
final JavaTypeContext context = (JavaTypeContext) node.getContext();
final Context context = node.getContext();
final IMethod method = node.getMethod();
final String hashKey = method.toString() + "@" + context.toString();
@ -90,7 +93,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (!(node.getContext() instanceof JavaTypeContext)) {
if (!(node.getContext().isA(JavaTypeContext.class))) {
return false;
}
return node.getMethod().getReference().equals(GetClassContextSelector.GET_CLASS);
@ -106,12 +109,12 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
return EmptyIterator.instance();
}
private static SSAInstruction[] makeStatements(JavaTypeContext context) {
private static SSAInstruction[] makeStatements(Context context) {
ArrayList<SSAInstruction> statements = new ArrayList<>();
int nextLocal = 2;
int retValue = nextLocal++;
TypeReference tr = context.getType().getTypeReference();
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference();
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
if (tr != null) {
SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr);
statements.add(l);
@ -126,7 +129,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
return result;
}
private static IR makeIR(IMethod method, JavaTypeContext context) {
private static IR makeIR(IMethod method, Context context) {
SSAInstruction instrs[] = makeStatements(context);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null);
}

7
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetMethodContext.java

@ -83,10 +83,17 @@ public class GetMethodContext implements Context {
this.name = name;
}
class NameItem implements ContextItem {
String name() { return getName(); }
};
@Override
public ContextItem get(ContextKey name) {
if (name == ContextKey.RECEIVER) {
return type;
} else if (name == ContextKey.NAME) {
return new NameItem();
} else if (name == ContextKey.PARAMETERS[0]) {
if (type instanceof PointType) {
IClass cls = ((PointType) type).getIClass();

26
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/GetMethodContextInterpreter.java

@ -15,6 +15,8 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import com.ibm.wala.analysis.reflection.GetMethodContext.NameItem;
import com.ibm.wala.analysis.typeInference.TypeAbstraction;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference;
@ -22,6 +24,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.summaries.SyntheticIR;
import com.ibm.wala.ssa.ConstantValue;
@ -79,15 +83,15 @@ public class GetMethodContextInterpreter implements SSAContextInterpreter {
System.err.println("generating IR for " + node);
}
IMethod method = node.getMethod();
GetMethodContext context = (GetMethodContext) node.getContext();
Context context = node.getContext();
Map<Integer,ConstantValue> constants = HashMapFactory.make();
if (method.getReference().equals(GET_METHOD)) {
Atom name = Atom.findOrCreateAsciiAtom(context.getName());
Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name());
SSAInstruction instrs[] = makeGetMethodStatements(context,constants,name);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants);
}
if (method.getReference().equals(GET_DECLARED_METHOD)) {
Atom name = Atom.findOrCreateAsciiAtom(context.getName());
Atom name = Atom.findOrCreateAsciiAtom(((NameItem)(context.get(ContextKey.NAME))).name());
SSAInstruction instrs[] = makeGetDeclaredMethodStatements(context,constants,name);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), constants);
}
@ -117,7 +121,7 @@ public class GetMethodContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (!(node.getContext() instanceof GetMethodContext)) {
if (!(node.getContext().isA(GetMethodContext.class))) {
return false;
}
MethodReference mRef = node.getMethod().getReference();
@ -190,13 +194,13 @@ public class GetMethodContextInterpreter implements SSAContextInterpreter {
(
MethodReference ref,
Collection<IMethod> returnValues,
GetMethodContext context,
Context context,
Map<Integer, ConstantValue> constants
) {
ArrayList<SSAInstruction> statements = new ArrayList<>();
int nextLocal = ref.getNumberOfParameters() + 2;
IClass cls = context.getType().getType();
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
if (cls != null) {
for (IMethod m : returnValues) {
int c = nextLocal++;
@ -219,11 +223,11 @@ public class GetMethodContextInterpreter implements SSAContextInterpreter {
private static SSAInstruction[] makeGetMethodStatements
(
GetMethodContext context,
Context context,
Map<Integer,ConstantValue> constants,
Atom name
) {
IClass cls = context.getType().getType();
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
if (cls == null) {
return getParticularMethodStatements(GET_METHOD, null, context, constants);
} else {
@ -234,8 +238,8 @@ public class GetMethodContextInterpreter implements SSAContextInterpreter {
/**
* Create statements for {@link Class#getDeclaredMethod(String, Class...)}.
*/
private static SSAInstruction[] makeGetDeclaredMethodStatements(GetMethodContext context, Map<Integer, ConstantValue> constants,Atom name) {
IClass cls = context.getType().getType();
private static SSAInstruction[] makeGetDeclaredMethodStatements(Context context, Map<Integer, ConstantValue> constants,Atom name) {
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
if (cls == null) {
return getParticularMethodStatements(GET_DECLARED_METHOD, null, context, constants);
} else {

57
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/JavaLangClassContextInterpreter.java

@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import com.ibm.wala.analysis.typeInference.TypeAbstraction;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference;
@ -22,6 +23,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.summaries.SyntheticIR;
import com.ibm.wala.ssa.ConstantValue;
@ -106,7 +109,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
/** BEGIN Custom change: caching */
final JavaTypeContext context = (JavaTypeContext) node.getContext();
final Context context = node.getContext();
final IMethod method = node.getMethod();
final String hashKey = method.toString() + "@" + context.toString();
@ -128,7 +131,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getIR(node);
}
private static IR makeIR(IMethod method, JavaTypeContext context) {
private static IR makeIR(IMethod method, Context context) {
Map<Integer, ConstantValue> constants = HashMapFactory.make();
if (method.getReference().equals(GET_CONSTRUCTOR)) {
SSAInstruction instrs[] = makeGetCtorStatements(context, constants);
@ -192,7 +195,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (!(node.getContext() instanceof JavaTypeContext)) {
if (!(node.getContext().isA(JavaTypeContext.class))) {
return false;
}
MethodReference mRef = node.getMethod().getReference();
@ -207,8 +210,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
throw new IllegalArgumentException("node is null");
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
Context context = node.getContext();
TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference();
if (tr != null) {
return new NonNullSingletonIterator<>(NewSiteReference.make(0, tr));
}
@ -280,13 +283,13 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
*
* @param returnValues the possible return values for this method.
*/
private static SSAInstruction[] getMethodArrayStatements(MethodReference ref, Collection<IMethod> returnValues, JavaTypeContext context,
private static SSAInstruction[] getMethodArrayStatements(MethodReference ref, Collection<IMethod> returnValues, Context context,
Map<Integer, ConstantValue> constants) {
ArrayList<SSAInstruction> statements = new ArrayList<>();
int nextLocal = ref.getNumberOfParameters() + 2;
int retValue = nextLocal++;
IClass cls = context.getType().getType();
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
if (cls != null) {
TypeReference arrType = ref.getReturnType();
NewSiteReference site = new NewSiteReference(retValue, arrType);
@ -328,11 +331,11 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
* @param returnValues the possible return values for this method.
*/
private static SSAInstruction[] getParticularMethodStatements(MethodReference ref, Collection<IMethod> returnValues,
JavaTypeContext context, Map<Integer, ConstantValue> constants) {
Context context, Map<Integer, ConstantValue> constants) {
ArrayList<SSAInstruction> statements = new ArrayList<>();
int nextLocal = ref.getNumberOfParameters() + 2;
IClass cls = context.getType().getType();
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory();
if (cls != null) {
for (IMethod m : returnValues) {
int c = nextLocal++;
@ -356,8 +359,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
/**
* create statements for getConstructor()
*/
private static SSAInstruction[] makeGetCtorStatements(JavaTypeContext context, Map<Integer, ConstantValue> constants) {
IClass cls = context.getType().getType();
private static SSAInstruction[] makeGetCtorStatements(Context context, Map<Integer, ConstantValue> constants) {
IClass cls = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType();
if (cls == null) {
return getParticularMethodStatements(GET_CONSTRUCTOR, null, context, constants);
} else {