+ CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
+ System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
+ System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc="
+ + newCompLoc);
+ globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
+ // }
+
+ continue next;
+ // }
+
+ }
+
+ }
+
+ }
+
+ }
+ }
+
+ private boolean checkFlowNodeReturnThisField(MethodDescriptor md) {
+
+ MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
+ GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
+
+ FlowGraph flowGraph = getFlowGraph(md);
+
+ ClassDescriptor enclosingDesc = getClassTypeDescriptor(md.getThis());
+ if (enclosingDesc == null) {
+ return false;
+ }
+
+ int count = 0;
+ Set<FlowNode> returnNodeSet = flowGraph.getReturnNodeSet();
+ Set<GlobalFlowNode> globalReturnNodeSet = new HashSet<GlobalFlowNode>();
+ for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
+ FlowNode flowNode = (FlowNode) iterator.next();
+ NTuple<Location> locTuple = translateToLocTuple(md, flowNode.getDescTuple());
+ GlobalFlowNode globalReturnNode = globalFlowGraph.getFlowNode(locTuple);
+ globalReturnNodeSet.add(globalReturnNode);
+
+ List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, globalReturnNode);
+ for (int i = 0; i < prefixList.size(); i++) {
+ NTuple<Location> curPrefix = prefixList.get(i);
+ ClassDescriptor cd =
+ getClassTypeDescriptor(curPrefix.get(curPrefix.size() - 1).getLocDescriptor());
+ if (cd != null && cd.equals(enclosingDesc)) {
+ count++;
+ break;
+ }
+ }
+
+ }
+
+ if (count == returnNodeSet.size()) {
+ // in this case, all return nodes in the method returns values coming from a location that
+ // starts with "this"
+
+ System.out.println("$$$SET RETURN LOC TRUE=" + md);
+ mapMethodDescriptorToCompositeReturnCase.put(md, Boolean.TRUE);
+
+ // NameDescriptor returnLocDesc = new NameDescriptor("RLOC" + (locSeed++));
+ // NTuple<Descriptor> rDescTuple = new NTuple<Descriptor>();
+ // rDescTuple.add(md.getThis());
+ // rDescTuple.add(returnLocDesc);
+ //
+ // for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
+ // FlowNode rnode = (FlowNode) iterator.next();
+ // flowGraph.addValueFlowEdge(rnode.getDescTuple(), rDescTuple);
+ // }
+ //
+ // getMethodSummary(md).setRETURNLoc(new CompositeLocation(translateToLocTuple(md,
+ // rDescTuple)));
+
+ } else {
+ mapMethodDescriptorToCompositeReturnCase.put(md, Boolean.FALSE);
+ }
+
+ return mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
+
+ }
+
+ private boolean needToGenerateCompositeLocation(GlobalFlowNode node, NTuple<Location> curPrefix) {
+ // return true if there is a path between a node to which we want to give a composite location
+ // and nodes which start with curPrefix
+
+ System.out.println("---needToGenerateCompositeLocation curPrefix=" + curPrefix);
+
+ Location targetLocalLoc = node.getLocTuple().get(0);
+
+ MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor();
+ FlowGraph flowGraph = getFlowGraph(md);
+ FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple());
+ Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
+
+ Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
+ for (Iterator iterator = paramNodeSet.iterator(); iterator.hasNext();) {
+ FlowNode paramFlowNode = (FlowNode) iterator.next();
+ if (curPrefix.startsWith(translateToLocTuple(md, paramFlowNode.getDescTuple()))) {
+ System.out.println("here1?!");
+ return true;
+ }
+ }
+
+ if (targetLocalLoc.getLocDescriptor() instanceof InterDescriptor) {
+ Pair<MethodInvokeNode, Integer> pair =
+ ((InterDescriptor) targetLocalLoc.getLocDescriptor()).getMethodArgIdxPair();
+
+ if (pair != null) {
+ System.out.println("$$$TARGETLOCALLOC HOLDER=" + targetLocalLoc);
+
+ MethodInvokeNode min = pair.getFirst();
+ Integer paramIdx = pair.getSecond();
+ MethodDescriptor mdCallee = min.getMethod();
+
+ FlowNode paramNode = getFlowGraph(mdCallee).getParamFlowNode(paramIdx);
+ if (checkNodeReachToReturnNode(mdCallee, paramNode)) {
+ System.out.println("here2?!");
+ return true;
+ }
+
+ }
+
+ }
+
+ GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
+ Set<GlobalFlowNode> subGlobalReachableSet = subGlobalFlowGraph.getReachableNodeSetFrom(node);
+
+ if (!md.isStatic()) {
+ ClassDescriptor currentMethodThisType = getClassTypeDescriptor(md.getThis());
+ 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);
+
+ if (mapMethodDescriptorToCompositeReturnCase.containsKey(md)) {
+ boolean hasCompReturnLocWithThis =
+ mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
+ if (hasCompReturnLocWithThis) {
+ if (checkNodeReachToReturnNode(md, flowNode)) {
+ System.out.println("here3?!");
+ return true;
+ }
+ }
+ }
+
+ 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;
+ }
+ }
+ }
+ }
+ }
+
+ // System.out.println("flowGraph.getReturnNodeSet()=" + flowGraph.getReturnNodeSet());
+ // System.out.println("flowGraph.contains(node.getDescTuple())="
+ // + flowGraph.contains(node.getDescTuple()) + " flowGraph.getFlowNode(node.getDescTuple())="
+ // + flowGraph.getFlowNode(node.getDescTuple()));reachableSet
+
+ // if (flowGraph.contains(node.getDescTuple())
+ // && flowGraph.getReturnNodeSet().contains(flowGraph.getFlowNode(node.getDescTuple()))) {
+ // // return checkFlowNodeReturnThisField(flowGraph);
+ // }
+
+ Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1);
+ // check whether prefix appears in the list of parameters
+ Set<MethodInvokeNode> minSet = mapMethodDescToMethodInvokeNodeSet.get(md);
+ found: for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
+ MethodInvokeNode min = (MethodInvokeNode) iterator.next();
+ Map<Integer, NTuple<Descriptor>> map = mapMethodInvokeNodeToArgIdxMap.get(min);
+ Set<Integer> keySet = map.keySet();
+ // System.out.println("min=" + min.printNode(0));
+
+ for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
+ Integer argIdx = (Integer) iterator2.next();
+ NTuple<Descriptor> argTuple = map.get(argIdx);
+
+ if (!(!md.isStatic() && argIdx == 0)) {
+ // 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);
+ System.out.println("ARG CASE=" + locTuple);
+ for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) {
+ GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
+ // NTuple<Location> locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple());
+ NTuple<Location> globalReachlocTuple = subGlobalReachalbeNode.getLocTuple();
+ for (int i = 0; i < globalReachlocTuple.size(); i++) {
+ if (globalReachlocTuple.get(i).equals(lastLocationOfPrefix)) {
+ System.out.println("ARG " + argTuple + " IS MATCHED WITH="
+ + lastLocationOfPrefix);
+ System.out.println("here5?!");
+
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // ClassDescriptor cd;
+ // if (lastLocationOfPrefix.getLocDescriptor() instanceof VarDescriptor) {
+ // cd = ((VarDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc();
+ // } else {
+ // // it is a field descriptor
+ // cd = ((FieldDescriptor) lastLocationOfPrefix.getLocDescriptor()).getType().getClassDesc();
+ // }
+ //
+ // GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
+ // Set<GlobalFlowNode> subGlobalReachableSet = subGlobalFlowGraph.getReachableNodeSetFrom(node);
+ //
+ // System.out.println("TRY TO FIND lastLocationOfPrefix=" + lastLocationOfPrefix);
+ // for (Iterator iterator2 = subGlobalReachableSet.iterator(); iterator2.hasNext();) {
+ // GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator2.next();
+ // // NTuple<Location> locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple());
+ // NTuple<Location> locTuple = subGlobalReachalbeNode.getLocTuple();
+ //
+ // for (int i = 0; i < locTuple.size(); i++) {
+ // if (locTuple.get(i).equals(lastLocationOfPrefix)) {
+ // return true;
+ // }
+ // }
+ //
+ // Location lastLoc = locTuple.get(locTuple.size() - 1);
+ // Descriptor enclosingDescriptor = lastLoc.getDescriptor();
+ //
+ // if (enclosingDescriptor != null && enclosingDescriptor.equals(cd)) {
+ // System.out.println("# WHY HERE?");
+ // System.out.println("subGlobalReachalbeNode=" + subGlobalReachalbeNode);
+ // return true;
+ // }
+ // }