rename getNumberOfParameters to getNumberOfPositionalParameters since the Python front end now supports keyword parameters
support variable names in IR for synthetic summaries
This commit is contained in:
parent
41d254d547
commit
436d3165f7
|
@ -55,7 +55,7 @@ public class JSMethodInstructionVisitor extends JSAbstractInstructionVisitor {
|
|||
if(fndef instanceof AstGlobalRead) {
|
||||
AstGlobalRead agr = (AstGlobalRead)fndef;
|
||||
if(agr.getGlobalName().equals("global Function")) {
|
||||
if(invk.getNumberOfParameters() != 2)
|
||||
if(invk.getNumberOfPositionalParameters() != 2)
|
||||
return false;
|
||||
// this may be a genuine use of "new Function()", not a declaration/expression
|
||||
if(!symtab.isStringConstant(invk.getUse(1)))
|
||||
|
|
|
@ -103,7 +103,7 @@ public class OptimisticCallgraphBuilder extends FieldBasedCallGraphBuilder {
|
|||
offset = 1;
|
||||
}
|
||||
|
||||
for(int i=0;i<invk.getNumberOfParameters();++i) {
|
||||
for(int i=0;i<invk.getNumberOfPositionalParameters();++i) {
|
||||
// only flow receiver into 'this' if invk is, in fact, a method call
|
||||
flowgraph.addEdge(factory.makeVarVertex(caller, invk.getUse(i)), factory.makeArgVertex(callee));
|
||||
//if(i != 1 || !invk.getDeclaredTarget().getSelector().equals(AstMethodReference.fnSelector))
|
||||
|
@ -126,7 +126,7 @@ public class OptimisticCallgraphBuilder extends FieldBasedCallGraphBuilder {
|
|||
System.err.println("callees " + realCallees + " for " + caller);
|
||||
for(FuncVertex realCallee: realCallees) {
|
||||
// flow from arguments to parameters
|
||||
for(int i=2;i<invk.getNumberOfParameters();++i)
|
||||
for(int i=2;i<invk.getNumberOfPositionalParameters();++i)
|
||||
flowgraph.addEdge(factory.makeVarVertex(caller, invk.getUse(i)), factory.makeParamVertex(realCallee, i-1));
|
||||
|
||||
// flow from return vertex to result vertex
|
||||
|
|
|
@ -109,7 +109,7 @@ public class PessimisticCallGraphBuilder extends FieldBasedCallGraphBuilder {
|
|||
JavaScriptInvoke use_invk = (JavaScriptInvoke)use;
|
||||
|
||||
// yes, so add edges from arguments to parameters...
|
||||
for(int i=2;i<use_invk.getNumberOfParameters();++i)
|
||||
for(int i=2;i<use_invk.getNumberOfPositionalParameters();++i)
|
||||
flowgraph.addEdge(factory.makeVarVertex(caller, use_invk.getUse(i)), factory.makeParamVertex(callee, i));
|
||||
|
||||
// ...and from return to result
|
||||
|
@ -129,7 +129,7 @@ public class PessimisticCallGraphBuilder extends FieldBasedCallGraphBuilder {
|
|||
|
||||
// if it's not a local call, add flows from/to unknown
|
||||
if(!(def instanceof JavaScriptInvoke) || !isFunctionConstructorInvoke((JavaScriptInvoke)def)) {
|
||||
for(int i=1;i<invk.getNumberOfParameters();++i)
|
||||
for(int i=1;i<invk.getNumberOfPositionalParameters();++i)
|
||||
flowgraph.addEdge(factory.makeVarVertex(caller, invk.getUse(i)), factory.makeUnknownVertex());
|
||||
flowgraph.addEdge(factory.makeUnknownVertex(), factory.makeVarVertex(caller, invk.getDef()));
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ public class WorklistBasedOptimisticCallgraphBuilder extends FieldBasedCallGraph
|
|||
offset = 1;
|
||||
}
|
||||
|
||||
for(int i=0;i<invk.getNumberOfParameters();++i) {
|
||||
for(int i=0;i<invk.getNumberOfPositionalParameters();++i) {
|
||||
// only flow receiver into 'this' if invk is, in fact, a method call
|
||||
flowgraph.addEdge(factory.makeVarVertex(caller, invk.getUse(i)), factory.makeArgVertex(callee));
|
||||
if(i != 1 || !invk.getDeclaredTarget().getSelector().equals(AstMethodReference.fnSelector))
|
||||
|
@ -166,7 +166,7 @@ public class WorklistBasedOptimisticCallgraphBuilder extends FieldBasedCallGraph
|
|||
FuncVertex caller = reflectiveCallee.getFunction();
|
||||
|
||||
// flow from arguments to parameters
|
||||
for(int i=2;i<invk.getNumberOfParameters();++i) {
|
||||
for(int i=2;i<invk.getNumberOfPositionalParameters();++i) {
|
||||
addFlowEdge(flowgraph, factory.makeVarVertex(caller, invk.getUse(i)), factory.makeParamVertex(realCallee, i-1), worklist);
|
||||
|
||||
// flow from return vertex to result vertex
|
||||
|
|
|
@ -392,7 +392,7 @@ public class FlowGraphBuilder {
|
|||
flowgraph.addEdge(cs, factory.makeVarVertex(func, invk.getDef()));
|
||||
|
||||
// also passed as 'this' to constructor
|
||||
if (invk.getNumberOfParameters() > 1) {
|
||||
if (invk.getNumberOfPositionalParameters() > 1) {
|
||||
flowgraph.addEdge(cs, factory.makeVarVertex(func, invk.getUse(0)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,9 +135,9 @@ public class ArgumentSpecialization {
|
|||
int v = -1;
|
||||
for (SSAAbstractInvokeInstruction x : caller.getIR().getCalls(site)) {
|
||||
if (v == -1) {
|
||||
v = x.getNumberOfParameters();
|
||||
v = x.getNumberOfPositionalParameters();
|
||||
} else {
|
||||
if (v != x.getNumberOfParameters()) {
|
||||
if (v != x.getNumberOfPositionalParameters()) {
|
||||
return baseContext;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1035,7 +1035,7 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
|
|||
}
|
||||
|
||||
int paramCount = targetST.getParameterValueNumbers().length;
|
||||
int argCount = instruction.getNumberOfParameters();
|
||||
int argCount = instruction.getNumberOfPositionalParameters();
|
||||
|
||||
// the first two arguments are the function object and the receiver, neither of which
|
||||
// should become part of the arguments array
|
||||
|
|
|
@ -46,7 +46,7 @@ public class JavaScriptConstructTargetSelector implements MethodTargetSelector {
|
|||
IR callerIR = caller.getIR();
|
||||
SSAAbstractInvokeInstruction callStmts[] = callerIR.getCalls(site);
|
||||
assert callStmts.length == 1;
|
||||
int nargs = callStmts[0].getNumberOfParameters();
|
||||
int nargs = callStmts[0].getNumberOfPositionalParameters();
|
||||
return constructors.findOrCreateConstructorMethod(callerIR, callStmts[0], receiver, nargs - 1);
|
||||
} else {
|
||||
return base.getCalleeTarget(caller, site, receiver);
|
||||
|
|
|
@ -194,7 +194,7 @@ public class JavaScriptFunctionDotCallTargetSelector implements MethodTargetSele
|
|||
IR callerIR = caller.getIR();
|
||||
SSAAbstractInvokeInstruction callStmts[] = callerIR.getCalls(site);
|
||||
assert callStmts.length == 1;
|
||||
int nargs = callStmts[0].getNumberOfParameters();
|
||||
int nargs = callStmts[0].getNumberOfPositionalParameters();
|
||||
return nargs;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ public class PropertyNameContextSelector implements ContextSelector {
|
|||
SSAAbstractInvokeInstruction inst = caller.getIR().getCalls(site)[0];
|
||||
DefUse du = caller.getDU();
|
||||
|
||||
for(int i = 0; i < inst.getNumberOfParameters(); i++) {
|
||||
for(int i = 0; i < inst.getNumberOfPositionalParameters(); i++) {
|
||||
MutableIntSet values = IntSetUtil.make();
|
||||
values.add(inst.getUse(i));
|
||||
collectValues(du, du.getDef(inst.getUse(i)), values);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class EscapeCorrelation extends Correlation {
|
|||
}
|
||||
|
||||
public int getNumberOfArguments() {
|
||||
return invoke.getNumberOfParameters() - 2; // deduct one for the function object, one for the receiver
|
||||
return invoke.getNumberOfPositionalParameters() - 2; // deduct one for the function object, one for the receiver
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -80,7 +80,7 @@ public class JavaScriptInvoke extends MultiReturnValueInvokeInstruction {
|
|||
|
||||
@Override
|
||||
public int getNumberOfUses() {
|
||||
return getNumberOfParameters();
|
||||
return getNumberOfPositionalParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,7 +126,7 @@ public class JavaScriptInvoke extends MultiReturnValueInvokeInstruction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfParameters() {
|
||||
public int getNumberOfPositionalParameters() {
|
||||
if (params == null) {
|
||||
return 1;
|
||||
} else {
|
||||
|
|
|
@ -89,7 +89,7 @@ public abstract class FixedParametersInvokeInstruction
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfParameters() {
|
||||
public int getNumberOfPositionalParameters() {
|
||||
if (params == null) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -107,7 +107,7 @@ public abstract class FixedParametersInvokeInstruction
|
|||
|
||||
@Override
|
||||
public int getNumberOfUses() {
|
||||
return getNumberOfParameters();
|
||||
return getNumberOfPositionalParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,7 +119,7 @@ public abstract class FixedParametersInvokeInstruction
|
|||
|
||||
@Override
|
||||
public int getUse(int j) {
|
||||
if (j < getNumberOfParameters())
|
||||
if (j < getNumberOfPositionalParameters())
|
||||
return params[j];
|
||||
else {
|
||||
return super.getUse(j);
|
||||
|
|
|
@ -57,7 +57,7 @@ public final class AnalysisUtil {
|
|||
* including the this pointer.
|
||||
*/
|
||||
public static int[] getParameterNumbers(SSAAbstractInvokeInstruction invokeInstruction) {
|
||||
final int number = invokeInstruction.getNumberOfParameters();
|
||||
final int number = invokeInstruction.getNumberOfPositionalParameters();
|
||||
final int[] parameterNumbers = new int[number];
|
||||
assert (parameterNumbers.length == invokeInstruction.getNumberOfUses());
|
||||
|
||||
|
|
|
@ -302,10 +302,10 @@ public abstract class BasicCallGraph<T> extends AbstractNumberedGraph<CGNode> im
|
|||
@Override
|
||||
public Set<CGNode> getNodes(MethodReference m) {
|
||||
IMethod im = getClassHierarchy().resolveMethod(m);
|
||||
if (im == null) {
|
||||
return Collections.emptySet();
|
||||
if (im != null) {
|
||||
m = im.getReference();
|
||||
}
|
||||
Set<CGNode> result = mr2Nodes.get(im.getReference());
|
||||
Set<CGNode> result = mr2Nodes.get(m);
|
||||
Set<CGNode> empty = Collections.emptySet();
|
||||
return (result == null) ? empty : result;
|
||||
}
|
||||
|
|
|
@ -1617,7 +1617,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
|
|||
// }
|
||||
// } else {
|
||||
// generate contraints from parameter passing
|
||||
int nUses = instruction.getNumberOfParameters();
|
||||
int nUses = instruction.getNumberOfPositionalParameters();
|
||||
int nExpected = target.getMethod().getNumberOfParameters();
|
||||
|
||||
/*
|
||||
|
@ -1635,7 +1635,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
|
|||
// TODO: we need much more precise filters than cones in order to handle
|
||||
// the various types of dispatch logic. We need a filter that expresses
|
||||
// "the set of types s.t. x.foo resolves to y.foo."
|
||||
for (int i = 0; i < instruction.getNumberOfParameters(); i++) {
|
||||
for (int i = 0; i < instruction.getNumberOfPositionalParameters(); i++) {
|
||||
if (target.getMethod().getParameterType(i).isReferenceType()) {
|
||||
PointerKey formal = getTargetPointerKey(target, i);
|
||||
if (constParams != null && constParams[i] != null) {
|
||||
|
|
|
@ -696,7 +696,7 @@ public class SDG<T extends InstanceKey> extends AbstractNumberedGraph<Statement>
|
|||
// don't track reflection into reflective invokes
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < call.getNumberOfParameters(); i++) {
|
||||
for (int i = 0; i < call.getNumberOfPositionalParameters(); i++) {
|
||||
if (call.getUse(i) == caller.getValueNumber()) {
|
||||
if (callee.getValueNumber() == i + 1) {
|
||||
return true;
|
||||
|
|
|
@ -186,7 +186,7 @@ public class BypassMethodTargetSelector implements MethodTargetSelector {
|
|||
syntheticMethods.put(m, null);
|
||||
return null;
|
||||
}
|
||||
SummarizedMethod n = new SummarizedMethod(m, summ, C);
|
||||
SummarizedMethod n = new SummarizedMethodWithNames(m, summ, C);
|
||||
syntheticMethods.put(m, n);
|
||||
return n;
|
||||
} else {
|
||||
|
|
|
@ -151,7 +151,7 @@ public class LambdaSummaryClass extends SyntheticClass {
|
|||
|
||||
private Map<Atom,IField> makeFields() {
|
||||
Map<Atom,IField> result = HashMapFactory.make();
|
||||
for(int i = 0; i < invoke.getNumberOfParameters(); i++) {
|
||||
for(int i = 0; i < invoke.getNumberOfPositionalParameters(); i++) {
|
||||
final int yuck = i;
|
||||
result.put(Atom.findOrCreateUnicodeAtom("c" + yuck), new IField() {
|
||||
@Override
|
||||
|
@ -248,8 +248,8 @@ public class LambdaSummaryClass extends SyntheticClass {
|
|||
MethodSummary summary = new MethodSummary(ref);
|
||||
|
||||
int inst = 0;
|
||||
int args = invoke.getNumberOfParameters(), v = args + 1;
|
||||
for(int i = 0; i < invoke.getNumberOfParameters(); i++) {
|
||||
int args = invoke.getNumberOfPositionalParameters(), v = args + 1;
|
||||
for(int i = 0; i < invoke.getNumberOfPositionalParameters(); i++) {
|
||||
Atom f = Atom.findOrCreateUnicodeAtom("c" + i);
|
||||
summary.addStatement(insts.GetInstruction(inst++, v++, 1, getField(f).getReference()));
|
||||
}
|
||||
|
@ -273,11 +273,11 @@ public class LambdaSummaryClass extends SyntheticClass {
|
|||
|
||||
int numParams = getClassHierarchy().resolveMethod(callee).getNumberOfParameters();
|
||||
int params[] = new int[ numParams ];
|
||||
for(int i = isNew? 1: 0; i < invoke.getNumberOfParameters(); i++) {
|
||||
for(int i = isNew? 1: 0; i < invoke.getNumberOfPositionalParameters(); i++) {
|
||||
params[i] = args + i + 1;
|
||||
}
|
||||
int n = 2;
|
||||
for(int i = invoke.getNumberOfParameters(); i < numParams; i++) {
|
||||
for(int i = invoke.getNumberOfPositionalParameters(); i < numParams; i++) {
|
||||
params[i] = n++;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.ibm.wala.types.MemberReference;
|
|||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
import com.ibm.wala.util.warnings.Warning;
|
||||
|
||||
/**
|
||||
|
@ -69,6 +70,11 @@ public class MethodSummary {
|
|||
*/
|
||||
private boolean isFactory = false;
|
||||
|
||||
/**
|
||||
* Known names for values
|
||||
*/
|
||||
private Map<Integer, Atom> valueNames = null;
|
||||
|
||||
public MethodSummary(MethodReference method) {
|
||||
if (method == null) {
|
||||
throw new IllegalArgumentException("null method");
|
||||
|
@ -76,6 +82,18 @@ public class MethodSummary {
|
|||
this.method = method;
|
||||
}
|
||||
|
||||
public void setValueNames(Map<Integer, Atom> nameTable) {
|
||||
this.valueNames = nameTable;
|
||||
}
|
||||
|
||||
public Map<Integer, Atom> getValueNames() {
|
||||
return valueNames;
|
||||
}
|
||||
|
||||
public Atom getValue(Integer v) {
|
||||
return valueNames != null && valueNames.containsKey(v)? valueNames.get(v): null;
|
||||
}
|
||||
|
||||
public int getNumberOfStatements() {
|
||||
return (statements == null ? 0 : statements.size());
|
||||
}
|
||||
|
|
|
@ -115,4 +115,9 @@ public class SummarizedMethod extends SyntheticMethod {
|
|||
return summary.getParameterType(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalVariableName(int bcIndex, int localNumber) {
|
||||
return summary.getValue(localNumber).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,6 +73,10 @@ public class SummarizedMethodWithNames extends SummarizedMethod {
|
|||
private final MethodSummary summary;
|
||||
private final Map<Integer, Atom> localNames;
|
||||
|
||||
public SummarizedMethodWithNames(MethodReference ref, MethodSummary summary, IClass declaringClass) {
|
||||
this(ref, summary, declaringClass, summary.getValueNames());
|
||||
}
|
||||
|
||||
public SummarizedMethodWithNames(MethodReference ref, MethodSummary summary, IClass declaringClass, Map<Integer, Atom> localNames)
|
||||
throws NullPointerException {
|
||||
super(ref, summary, declaringClass);
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
|
@ -183,10 +184,12 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
|
|||
|
||||
private final static String A_NUM_ARGS = "numArgs";
|
||||
|
||||
private final static String A_PARAM_NAMES = "paramNames";
|
||||
|
||||
private final static String V_NULL = "null";
|
||||
|
||||
private final static String V_TRUE = "true";
|
||||
|
||||
|
||||
public XMLMethodSummaryReader(InputStream xmlFile, AnalysisScope scope) {
|
||||
super();
|
||||
if (xmlFile == null) {
|
||||
|
@ -924,6 +927,24 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
|
|||
for (int i = 0; i < nParams; i++) {
|
||||
symbolTable.put("arg" + i, new Integer(i + 1));
|
||||
}
|
||||
|
||||
int pn = 1;
|
||||
String paramDescString = atts.getValue(A_PARAM_NAMES);
|
||||
if (paramDescString != null) {
|
||||
StringTokenizer paramNames = new StringTokenizer(paramDescString);
|
||||
while (paramNames.hasMoreTokens()) {
|
||||
symbolTable.put(paramNames.nextToken(), pn++);
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer,Atom> nameTable = HashMapFactory.make();
|
||||
for(Map.Entry<String, Integer> x : symbolTable.entrySet()) {
|
||||
if (! x.getKey().startsWith("arg")) {
|
||||
nameTable.put(x.getValue(), Atom.findOrCreateUnicodeAtom(x.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
governingMethod.setValueNames(nameTable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -139,7 +139,7 @@ public abstract class SSAAbstractInvokeInstruction extends SSAInstruction {
|
|||
/**
|
||||
* How many parameters does this call specify?
|
||||
*/
|
||||
public abstract int getNumberOfParameters();
|
||||
public abstract int getNumberOfPositionalParameters();
|
||||
|
||||
/**
|
||||
* How many distinct values does this call return?
|
||||
|
@ -199,9 +199,9 @@ public abstract class SSAAbstractInvokeInstruction extends SSAInstruction {
|
|||
s.append(" ");
|
||||
s.append(site.getDeclaredTarget().toString());
|
||||
|
||||
if (getNumberOfParameters() > 0) {
|
||||
if (getNumberOfPositionalParameters() > 0) {
|
||||
s.append(" ").append(getValueString(symbolTable, getUse(0)));
|
||||
for (int i = 1; i < getNumberOfParameters(); i++) {
|
||||
for (int i = 1; i < getNumberOfPositionalParameters(); i++) {
|
||||
s.append(",").append(getValueString(symbolTable, getUse(i)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfParameters() {
|
||||
public int getNumberOfPositionalParameters() {
|
||||
return getNumberOfUses();
|
||||
}
|
||||
|
||||
|
|
|
@ -455,7 +455,7 @@ implements IFlowFunctionMap<BasicBlockInContext<E>> {
|
|||
// }
|
||||
|
||||
final Map<CodeElement,CodeElement> parameterMap = HashMapFactory.make();
|
||||
for (int i = 0; i < instruction.getNumberOfParameters(); i++) {
|
||||
for (int i = 0; i < instruction.getNumberOfPositionalParameters(); i++) {
|
||||
Set<CodeElement> elements = CodeElement.valueElements(instruction.getUse(i));
|
||||
for(CodeElement e: elements) {
|
||||
parameterMap.put(e, new LocalElement(i+1));
|
||||
|
|
|
@ -179,7 +179,7 @@ public class TaintTransferFunctions<E extends ISSABasicBlock> implements
|
|||
// build list of actual parameter code elements, and return a
|
||||
// function
|
||||
final int numParams = ((SSAInvokeInstruction) srcInst)
|
||||
.getNumberOfParameters();
|
||||
.getNumberOfPositionalParameters();
|
||||
List<CodeElement> actualParams = new ArrayList<>(numParams);
|
||||
for (int i = 0; i < numParams; i++) {
|
||||
actualParams.add(i, new LocalElement(srcInst.getUse(i)));
|
||||
|
|
|
@ -333,7 +333,7 @@ public class SSAtoXMLVisitor implements SSAInstruction.IVisitor {
|
|||
elt.setAttribute(XMLSummaryWriter.A_DEF, localName);
|
||||
}
|
||||
|
||||
int paramCount = instruction.getNumberOfParameters();
|
||||
int paramCount = instruction.getNumberOfPositionalParameters();
|
||||
for (int i=0; i < paramCount; i++) {
|
||||
String argName = getLocalName(instruction.getUse(i));
|
||||
elt.setAttribute(XMLSummaryWriter.A_ARG+i, argName);
|
||||
|
|
Loading…
Reference in New Issue