translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min);
MethodDescriptor mdCallee = min.getMethod();
calleeSet.add(mdCallee);
- //
- // FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
- //
- // NTuple<Descriptor> methodInvokeBaseDescTuple = mapMethodInvokeNodeToBaseTuple.get(min);
- // NTuple<Location> methodInvokeBaseLocTuple = null;
- // if (methodInvokeBaseDescTuple != null) {
- // methodInvokeBaseLocTuple = translateToLocTuple(mdCaller, methodInvokeBaseDescTuple);
- // }
-
- // ////////////////
- // ////////////////
-
- // If the location of an argument has a composite location
- // need to assign a proper composite location to the corresponding callee parameter
- // System.out.println("---translate arg composite location to callee param. min="
- // + min.printNode(0));
- // Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple =
- // mapMethodInvokeNodeToArgIdxMap.get(min);
- // Set<Integer> idxSet = mapIdxToArgTuple.keySet();
- // for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) {
- // Integer idx = (Integer) iterator2.next();
- //
- // if (idx == 0 && !min.getMethod().isStatic()) {
- // continue;
- // }
- //
- // NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
- // if (argTuple.size() > 0) {
- // // check if an arg tuple has been already assigned to a composite location
- // NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
- // Location argLocalLoc = argLocTuple.get(0);
- //
- // // if (!isPrimitiveType(argTuple)) {
- // if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
- //
- // CompositeLocation argLocalCompositeLocation = callerMapLocToCompLoc.get(argLocalLoc);
- // CompositeLocation argCompLoc = argLocalCompositeLocation.clone();
- // for (int i = 1; i < argLocTuple.size(); i++) {
- // argCompLoc.addLocation(argLocTuple.get(i));
- // }
- //
- // FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
- //
- // System.out
- // .println("----- argLocTuple=" + argLocTuple + " argLocalLoc=+" + argLocalLoc);
- // System.out.println("-------need to translate argCompLoc=" + argCompLoc
- // + " with baseTuple=" + methodInvokeBaseLocTuple + " calleeParamLocTuple="
- // + calleeParamFlowNode);
- //
- // // CompositeLocation paramCompLoc = translateArgCompLocToParamCompLoc(min, argCompLoc);
- // // calleeParamFlowNode.setCompositeLocation(paramCompLoc);
- //
- // // if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
- // //
- // // FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
- // // NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
- // // NTuple<Location> calleeParamLocTuple
- // // =###translateCompositeLocationAssignmentToFlowGraph mdCaller=public static void
- // // huffcodetab.huffman_decoder(int htIdx, int x, BitReserve br)
- //
- // // translateToLocTuple(mdCallee, calleeParamDescTuple);
- // //
- // // System.out.println("---need to translate callerCompLoc=" + callerCompLoc
- // // + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple="
- // // + calleeParamLocTuple);
- // //
- // // CompositeLocation newCalleeCompLoc =
- // // translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
- // //
- // // calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
- // // newCalleeCompLoc);
- // //
- // // System.out.println("---callee loc=" + calleeParamLocTuple.get(0)
- // // + " newCalleeCompLoc=" + newCalleeCompLoc);
- // //
- // // // System.out.println("###need to assign composite location to=" +
- // // // calleeParamDescTuple
- // // // + " with baseTuple=" + baseLocTuple);
- // // }
- //
- // }
- // }
- // }
}
- // ////////////////
- // ////////////////
for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
MethodDescriptor callee = (MethodDescriptor) iterator.next();
translateCompositeLocationAssignmentToFlowGraph(callee);
}
- // for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
- // MethodInvokeNode min = (MethodInvokeNode) iterator.next();
- // // add an additional ordering constraint
- // // if the first element of a parameter composite location matches 'this' reference,
- // // the corresponding argument in the caller is required to be higher than the translated
- // // parameter location in the caller lattice
- // // TODO
- // // addOrderingConstraintFromCompLocParamToArg(mdCaller, min);
- // }
-
}
private CompositeLocation translateArgCompLocToParamCompLoc(MethodInvokeNode min,
//
// update return flow nodes in the caller
CompositeLocation returnLoc = getMethodSummary(mdCallee).getRETURNLoc();
-
System.out.println("### min=" + min.printNode(0) + " returnLoc=" + returnLoc);
if (returnLoc != null && returnLoc.get(0).getLocDescriptor().equals(mdCallee.getThis())
&& returnLoc.getSize() > 1) {
}
System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
+ } else {
+ // if the return loc set was empty and later pcloc was connected to the return loc
+ // need to make sure that return loc reflects to this changes.
+ FlowReturnNode flowReturnNode = callerFlowGraph.getFlowReturnNode(min);
+ if (flowReturnNode != null && flowReturnNode.getReturnTupleSet().isEmpty()) {
+
+ if (needToUpdateReturnLocHolder(min.getMethod(), flowReturnNode)) {
+ NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
+ NTuple<Descriptor> newReturnTuple = baseTuple.clone();
+ flowReturnNode.addTuple(newReturnTuple);
+ }
+
+ }
+
}
}
}
+ private boolean needToUpdateReturnLocHolder(MethodDescriptor mdCallee,
+ FlowReturnNode flowReturnNode) {
+ FlowGraph fg = getFlowGraph(mdCallee);
+ MethodSummary summary = getMethodSummary(mdCallee);
+ CompositeLocation returnCompLoc = summary.getRETURNLoc();
+ NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnCompLoc.getTuple());
+ Set<FlowNode> incomingNodeToReturnNode =
+ fg.getIncomingFlowNodeSet(fg.getFlowNode(returnDescTuple));
+ for (Iterator iterator = incomingNodeToReturnNode.iterator(); iterator.hasNext();) {
+ FlowNode inNode = (FlowNode) iterator.next();
+ if (inNode.getDescTuple().get(0).equals(mdCallee.getThis())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void addMapMethodDescToMethodInvokeNodeSet(MethodInvokeNode min) {
MethodDescriptor md = min.getMethod();
if (!mapMethodDescToMethodInvokeNodeSet.containsKey(md)) {
System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc="
+ inferCompLoc);
+ MethodDescriptor md = (MethodDescriptor) inferCompLoc.get(0).getDescriptor();
+
CompositeLocation newCompLoc = new CompositeLocation();
for (int i = 0; i < inferCompLoc.getSize(); i++) {
newCompLoc.addLocation(inferCompLoc.get(i));
Descriptor lastDescOfPrefix = nodeDescTuple.get(0);
Descriptor enclosingDescriptor;
if (lastDescOfPrefix instanceof InterDescriptor) {
- enclosingDescriptor = null;
+ enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(lastDescOfPrefix);
} else {
enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
}
} else {
int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple);
if (paramIdx == -1) {
- // System.out.println("*****key=" + key + " callerCompLoc=" + callerCompLoc);
+ // here, the first element of the current composite location comes from the current
+ // callee
+ // so transfer the same composite location to the callee
if (!calleeGlobalGraph.contrainsInferCompositeLocationMapKey(key)) {
- // calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc);
- System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc
- + " newCalleeCompLoc=" + callerCompLoc);
- System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
- if (!callerCompLoc.get(0).getDescriptor().equals(mdCallee)) {
- System.exit(0);
+ if (callerCompLoc.get(0).getDescriptor().equals(mdCallee)) {
+ System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc
+ + " newCalleeCompLoc=" + callerCompLoc);
+ System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
+ calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc);
+ } else {
+ System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc);
}
}
continue;
}
+
+ // It is the case where two parameters have relative orderings between them by having
+ // composite locations
+ // if we found the param idx, it means that the first part of the caller composite
+ // location corresponds to the one of arguments.
+ // for example, if the caller argument is <<caller.this>,<Decoder.br>>
+ // and the current caller composite location mapping
+ // <<caller.this>,<Decoder.br>,<Br.value>>
+ // and the parameter which matches with the caller argument is 'Br brParam'
+ // then, the translated callee composite location will be <<callee.brParam>,<Br.value>>
NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(paramIdx);
FlowNode paramFlowNode = calleeFlowGraph.getParamFlowNode(paramIdx);
for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
Integer argIdx = (Integer) iterator2.next();
NTuple<Descriptor> argTuple = map.get(argIdx);
- // System.out.println("argTuple=" + argTuple);
- // if (argIdx == 0 && !min.getMethod().isStatic()) {
- // ClassDescriptor currentMethodThisType = getClassTypeDescriptor(argTuple.get(0));
- //
- // for (int i = 0; i < curPrefix.size(); i++) {
- // ClassDescriptor prefixType =
- // getClassTypeDescriptor(curPrefix.get(i).getLocDescriptor());
- // if (prefixType != null && prefixType.equals(currentMethodThisType)) {
- // System.out.println("PREFIX TYPE MATCHES WITH=" + currentMethodThisType);
- // for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) {
- // GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
- // if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor()
- // .equals(md.getThis())) {
- // System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode);
- // System.out.println("here4?!");
- //
- // return true;
- // }
- // }
- // }
- // }
- //
- // }
+
if (!(!md.isStatic() && argIdx == 0)) {
- if (argTuple.get(argTuple.size() - 1).equals(lastLocationOfPrefix.getLocDescriptor())) {
+ // if the argTuple is empty, we don't need to do with anything(LITERAL CASE).
+ if (argTuple.size() > 0
+ && argTuple.get(argTuple.size() - 1).equals(lastLocationOfPrefix.getLocDescriptor())) {
NTuple<Location> locTuple =
translateToLocTuple(md, flowGraph.getParamFlowNode(argIdx).getDescTuple());
lastLocationOfPrefix = locTuple.get(0);
return prefixList;
- // List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
- //
- // for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
- // GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
- // NTuple<Location> inNodeTuple = inNode.getLocTuple();
- //
- // for (int i = 1; i < inNodeTuple.size(); i++) {
- // NTuple<Location> prefix = inNodeTuple.subList(0, i);
- // if (!prefixList.contains(prefix)) {
- // prefixList.add(prefix);
- // }
- // }
- // }
- //
- // Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
- // public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
- // int s0 = arg0.size();
- // int s1 = arg1.size();
- // if (s0 > s1) {
- // return -1;
- // } else if (s0 == s1) {
- // return 0;
- // } else {
- // return 1;
- // }
- // }
- // });
- // return prefixList;
}
private boolean containsClassDesc(ClassDescriptor cd, NTuple<Location> prefixLocTuple) {
NTuple<Location> locTuple = new NTuple<Location>();
Descriptor enclosingDesc = md;
- // System.out.println("md=" + md + " descTuple=" + descTuple);
+ System.out.println("md=" + md + " descTuple=" + descTuple);
for (int i = 0; i < descTuple.size(); i++) {
Descriptor desc = descTuple.get(i);
// this method will return the same nodeLocTuple if the corresponding argument is literal
// value.
- FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
+ // System.out.println("translateToCallerLocTuple=" + nodeLocTuple);
+ FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
NTuple<Descriptor> nodeDescTuple = translateToDescTuple(nodeLocTuple);
if (calleeFlowGraph.isParameter(nodeDescTuple)) {
int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple);
// // the type of argument is primitive.
// return nodeLocTuple.clone();
// }
- // System.out.println("paramIdx=" + paramIdx + " argDescTuple=" + argDescTuple);
+ // System.out.println("paramIdx=" + paramIdx + " argDescTuple=" + argDescTuple + " from min="
+ // + min.printNode(0));
NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
NTuple<Location> callerLocTuple = new NTuple<Location>();
return false;
}
+ public static boolean isReference(Descriptor desc) {
+
+ if (desc instanceof FieldDescriptor) {
+
+ TypeDescriptor type = ((FieldDescriptor) desc).getType();
+ if (type.isArray()) {
+ return false;
+ } else {
+ return type.isPtr();
+ }
+
+ } else if (desc instanceof VarDescriptor) {
+ TypeDescriptor type = ((VarDescriptor) desc).getType();
+ if (type.isArray()) {
+ return false;
+ } else {
+ return type.isPtr();
+ }
+ }
+
+ return false;
+ }
+
private NTuple<Descriptor> translateToDescTuple(NTuple<Location> locTuple) {
NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
- System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple);
+ System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple
+ + " srcNode=" + srcNode + " dstNode=" + dstNode);
if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
&& srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
}
}
- rtr += "\")";
-
if (desc instanceof MethodDescriptor) {
System.out.println("#EXTRA LOC DECLARATION GEN=" + desc);
MethodDescriptor md = (MethodDescriptor) desc;
MethodSummary methodSummary = getMethodSummary(md);
+ TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
+ if (!ssjava.getMethodContainingSSJavaLoop().equals(desc) && returnType != null
+ && (!returnType.isVoid())) {
+ CompositeLocation returnLoc = methodSummary.getRETURNLoc();
+ if (returnLoc.getSize() == 1) {
+ String returnLocStr = generateLocationAnnoatation(methodSummary.getRETURNLoc());
+ if (rtr.indexOf(returnLocStr) == -1) {
+ rtr += "," + returnLocStr;
+ }
+ }
+ }
+ rtr += "\")";
+
if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) {
- TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
if (returnType != null && (!returnType.isVoid())) {
rtr +=
"\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")";
}
+
CompositeLocation pcLoc = methodSummary.getPCLoc();
if ((pcLoc != null) && (!pcLoc.get(0).isTop())) {
rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")";
}
rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
+ } else {
+ rtr += "\")";
}
return rtr;
if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
String orgSourceLine = sourceVec.get(varLineNum);
+ System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine);
int idx =
orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
System.out.println("idx=" + idx
// calculate a return location:
// the return location type is lower than all parameters and the location of return values
MethodSummary methodSummary = getMethodSummary(md);
- if (methodSummary.getRETURNLoc() != null) {
- return;
- }
+ // if (methodSummary.getRETURNLoc() != null) {
+ // System.out.println("$HERE?");
+ // return;
+ // }
+
FlowGraph fg = getFlowGraph(md);
Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
Set<Integer> paramIdxSet = mapParamToLoc.keySet();
}
+ // makes sure that PCLOC is higher than RETURNLOC
+ CompositeLocation pcLoc = methodSummary.getPCLoc();
+ if (!pcLoc.get(0).isTop()) {
+ NTuple<Descriptor> pcLocDescTuple = translateToDescTuple(pcLoc.getTuple());
+ fg.addValueFlowEdge(pcLocDescTuple, returnDescTuple);
+ }
+
}
}
} else {
// all parameter is started with 'this', so PCLOC will be set relative to the composite
// location started with 'this'.
- for (int idx = 0; idx < minSize - 1; idx++) {
+ // for (int idx = 0; idx < minSize - 1; idx++) {
+ for (int idx = 0; idx < 1; idx++) {
Set<Descriptor> locDescSet = new HashSet<Descriptor>();
Location curLoc = null;
NTuple<Location> paramLocTuple = null;
for (int idx = 0; idx < numParam; idx++) {
FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
CompositeLocation compLoc = paramNode.getCompositeLocation();
+ System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc);
if (compLoc != null && compLoc.get(0).getLocDescriptor().equals(min.getMethod().getThis())) {
- System.out.println("$$$COMPLOC CASE=" + compLoc);
+ System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx);
+
NTuple<Descriptor> argTuple = getNodeTupleByArgIdx(min, idx);
+ System.out.println("--- argTuple=" + argTuple + " current compLoc="
+ + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation());
+
NTuple<Descriptor> translatedParamTuple =
translateCompositeLocationToCaller(idx, min, compLoc);
System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple);
tuple.add(baseTuple.get(i));
}
- for (int i = baseTuple.size(); i < compLocForParam1.getSize(); i++) {
+ for (int i = 1; i < compLocForParam1.getSize(); i++) {
Location loc = compLocForParam1.get(i);
tuple.add(loc.getLocDescriptor());
}
} else if (curDescriptor instanceof NameDescriptor) {
// it is "GLOBAL LOC" case!
enclosingDescriptor = GLOBALDESC;
+ } else if (curDescriptor instanceof InterDescriptor) {
+ enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(curDescriptor);
} else {
enclosingDescriptor = null;
}
+ " idx=" + idx);
if (!srcFieldDesc.equals(dstFieldDesc)) {
// add a new edge
+ System.out.println("-ADD EDGE");
getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
- } else if (isPrimitive(srcFieldDesc) && isPrimitive(dstFieldDesc)) {
+ } else if (!isReference(srcFieldDesc) && !isReference(dstFieldDesc)) {
+ System.out.println("-ADD EDGE");
getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
}
System.out.println("");
toanalyze_methodDescList = computeMethodList();
+ // hack... it seems that there is a problem with topological sorting.
+ // so String.toString(Object o) is appeared too higher in the call chain.
+ MethodDescriptor mdToString = null;
+ for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) {
+ MethodDescriptor md = (MethodDescriptor) iterator.next();
+ if (md.toString().equals("public static String String.valueOf(Object o)")) {
+ mdToString = md;
+ break;
+ }
+ }
+ if (mdToString != null) {
+ toanalyze_methodDescList.remove(mdToString);
+ toanalyze_methodDescList.addLast(mdToString);
+ }
+
LinkedList<MethodDescriptor> methodDescList =
(LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
newImplicitTupleSet.addTupleSet(condTupleNode);
+ System.out.println("A5");
newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
- // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
+ System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
NodeTupleSet condTupleNode = new NodeTupleSet();
analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
// translateToLocTuple(md, callerImplicitTuple));
// }
// }
+ System.out.println("A4");
newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
ExpressionNode en, NodeTupleSet nodeSet, NTuple<Descriptor> base,
NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
+ // System.out.println("en=" + en.printNode(0) + " class=" + en.getClass());
+
// note that expression node can create more than one flow node
// nodeSet contains of flow nodes
// base is always assigned to null except the case of a name node!
NTuple<Descriptor> flowTuple;
switch (en.kind()) {
-
case Kind.AssignmentNode:
analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
implicitFlowTupleSet);
private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
- // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
+ System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
newImplicitTupleSet.addTuple(interTuple);
}
+ System.out.println("A7");
newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
+ System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet);
// add edges from tertiaryTupleNode to all nodes of conditional nodes
// tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
newImplicitTupleSet, false);
+ System.out.println("A8");
nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
nodeSet.addTupleSet(tertiaryTupleNode);
addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min);
FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
- System.out.println("mdCallee=" + mdCallee);
+ System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph);
Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
System.out.println("---calleeReturnSet=" + calleeReturnSet);
NodeTupleSet baseNodeSet = new NodeTupleSet();
analyzeFlowExpressionNode(mdCaller, nametable, min.getExpression(), baseNodeSet, null,
implicitFlowTupleSet, false);
+ System.out.println("baseNodeSet=" + baseNodeSet);
assert (baseNodeSet.size() == 1);
NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
// the location type of the return value is started with 'this'
// reference
NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
+
+ if (inFlowTuple.get(0) instanceof InterDescriptor) {
+ // min.getExpression()
+ } else {
+
+ }
+
inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
// nodeSet.addTuple(inFlowTuple);
+ System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from="
+ + mdCallee.getThis());
tupleSet.addTuple(inFlowTuple);
} else {
// TODO
+ System.out.println("returnNode=" + returnNode);
Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
// System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode);
for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) {
FlowNode inFlowNode = (FlowNode) iterator2.next();
if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) {
// nodeSet.addTupleSet(baseNodeSet);
+ System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from="
+ + mdCallee.getThis());
tupleSet.addTupleSet(baseNodeSet);
-
}
}
}
NodeTupleSet argTupleSet = new NodeTupleSet();
analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false);
// if argument is liternal node, argTuple is set to NULL
- System.out.println("argTupleSet=" + argTupleSet);
+ System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet);
NTuple<Descriptor> argTuple = generateArgTuple(mdCaller, argTupleSet);
// if an argument is literal value,
// that node if needed
if (argTuple.size() > 0
&& (argTuple.get(0).equals(GLOBALDESC) || argTuple.get(0).equals(LITERALDESC))) {
- System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple);
- System.out.println("8");
-
- NTuple<Descriptor> interTuple =
- getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
- ((InterDescriptor) interTuple.get(0)).setMethodArgIdxPair(min, idx);
- addFlowGraphEdge(mdCaller, argTuple, interTuple);
- argTuple = interTuple;
- addArgIdxMap(min, idx, argTuple);
- System.out.println("new min mapping i=" + idx + " ->" + argTuple);
+ /*
+ * System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple); System.out.println("8");
+ *
+ * NTuple<Descriptor> interTuple =
+ * getFlowGraph(mdCaller).createIntermediateNode().getDescTuple(); ((InterDescriptor)
+ * interTuple.get(0)).setMethodArgIdxPair(min, idx); addFlowGraphEdge(mdCaller,
+ * argTuple, interTuple); argTuple = interTuple; addArgIdxMap(min, idx, argTuple);
+ * System.out.println("new min mapping i=" + idx + " ->" + argTuple);
+ */
+ argTuple = new NTuple<Descriptor>();
}
addArgIdxMap(min, idx, argTuple);
// }
// }
+ System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet);
if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
|| mdCallee.getModifiers().isNative()) {
addParamNodeFlowingToReturnValue(mdCallee, paramNode);
// nodeSet.addTupleSet(argTupleSet);
+ System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode);
tupleSet.addTupleSet(argTupleSet);
}
}
if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min);
- setNode.addTupleSet(tupleSet);
+ System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode);
+
+ if (needToGenerateInterLoc(tupleSet)) {
+ System.out.println("20");
+ FlowGraph fg = getFlowGraph(mdCaller);
+ NTuple<Descriptor> interTuple = fg.createIntermediateNode().getDescTuple();
+
+ for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) {
+ NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
+
+ Set<NTuple<Descriptor>> addSet = new HashSet<NTuple<Descriptor>>();
+ FlowNode node = fg.getFlowNode(tuple);
+ if (node instanceof FlowReturnNode) {
+ addSet.addAll(fg.getReturnTupleSet(((FlowReturnNode) node).getReturnTupleSet()));
+ } else {
+ addSet.add(tuple);
+ }
+ for (Iterator iterator2 = addSet.iterator(); iterator2.hasNext();) {
+ NTuple<Descriptor> higher = (NTuple<Descriptor>) iterator2.next();
+ addFlowGraphEdge(mdCaller, higher, interTuple);
+ }
+ }
+
+ setNode.addTuple(interTuple);
+ } else {
+ setNode.addTupleSet(tupleSet);
+ }
+
nodeSet.addTuple(setNode.getDescTuple());
+
}
// propagateFlowsFromCallee(min, md, min.getMethod());
NTuple<Location> calleeReturnLocTuple =
translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple);
- nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
- calleeReturnLocTuple));
+ NTuple<Location> transaltedToCaller =
+ translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple);
+ // System.out.println("translateToCallerLocTuple="
+ // + translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple));
+ if (transaltedToCaller.size() > 0) {
+ nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
+ calleeReturnLocTuple));
+ }
}
System.out.println("min nodeSet=" + nodeSet);
private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
// return true if inNode has in-flows to nodeSet
+ if (nodeSet.contains(inNode)) {
+ // in this case, the method directly returns a parameter variable.
+ return true;
+ }
// Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
- // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
+ System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
FlowNode fn = (FlowNode) iterator.next();
private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
- // System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0));
+ System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0));
String currentArrayAccessNodeExpStr = aan.printNode(0);
arrayAccessNodeStack.push(aan.printNode(0));
NodeTupleSet expNodeTupleSet = new NodeTupleSet();
NTuple<Descriptor> base =
analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
+ System.out.println("-base=" + base);
+ nodeSet.setMethodInvokeBaseDescTuple(base);
NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
}
nodeSetArrayAccessExp.clear();
nodeSetArrayAccessExp.addTuple(interTuple);
+ FlowGraph fg = getFlowGraph(md);
+
+ System.out.println("base=" + base);
+ if (base != null) {
+ fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
+ getClassTypeDescriptor(base.get(base.size() - 1)));
+ }
}
}
+ System.out.println("A1");
nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
nodeSet.addTupleSet(nodeSetArrayAccessExp);
NodeTupleSet leftOpSet = new NodeTupleSet();
NodeTupleSet rightOpSet = new NodeTupleSet();
+ System.out.println("analyzeFlowOpNode=" + on.printNode(0));
+
// left operand
analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet,
false);
+ System.out.println("--leftOpSet=" + leftOpSet);
if (on.getRight() != null) {
// right operand
analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null,
implicitFlowTupleSet, false);
}
+ System.out.println("--rightOpSet=" + rightOpSet);
Operation op = on.getOp();
nodeSet.addTupleSet(leftOpSet);
nodeSet.addTupleSet(rightOpSet);
+ System.out.println("A6");
nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
implicitFlowTupleSet, isLHS);
- nodeSet.addTupleSet(idxNodeTupleSet);
}
base =
analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
}
} else {
+ nodeSet.addTupleSet(idxNodeTupleSet);
// if it is the array case and not the LHS case
if (isArrayCase) {
NTuple<Descriptor> higherTuple = iter.next();
addFlowGraphEdge(md, higherTuple, interTuple);
}
+
+ FlowGraph fg = getFlowGraph(md);
+ fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
+ getClassTypeDescriptor(base.get(base.size() - 1)));
+
nodeSet.clear();
flowFieldTuple = interTuple;
}
-
+ System.out.println("A3");
nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
}
analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
false);
- // System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
- // System.out.println("-nodeSetLHS=" + nodeSetLHS);
- // System.out.println("-nodeSetRHS=" + nodeSetRHS);
- // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+ System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
+ System.out.println("-nodeSetLHS=" + nodeSetLHS);
+ System.out.println("-nodeSetRHS=" + nodeSetRHS);
+ System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
// System.out.println("-");
if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
NTuple<Descriptor> interTuple = null;
if (needToGenerateInterLoc(nodeSetRHS)) {
System.out.println("2");
-
interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
}
NTuple<Location> calleeReturnLocTuple = iterator.next();
for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
NTuple<Descriptor> callerLHSTuple = iter2.next();
- globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
- translateToLocTuple(md, callerLHSTuple));
System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
+ translateToLocTuple(md, callerLHSTuple));
+ globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+ translateToLocTuple(md, callerLHSTuple));
}
}
if (nodeSet != null) {
nodeSet.addTupleSet(nodeSetLHS);
+ System.out.println("A2");
nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
}
}
String highLocId = pair.getFirst();
String lowLocId = pair.getSecond();
- System.out.println("addedLocSet=" + addedLocSet);
if (!addedLocSet.contains(highLocId)) {
addedLocSet.add(highLocId);
drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);