+ private void constructHierarchyGraph() {
+
+ LinkedList<MethodDescriptor> methodDescList =
+ (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
+
+ while (!methodDescList.isEmpty()) {
+ MethodDescriptor md = methodDescList.removeLast();
+ if (state.SSJAVADEBUG) {
+ HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
+ System.out.println();
+ System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
+ constructHierarchyGraph(md, hierarchyGraph);
+ mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
+
+ }
+ }
+
+ setupToAnalyze();
+ while (!toAnalyzeIsEmpty()) {
+ ClassDescriptor cd = toAnalyzeNext();
+ HierarchyGraph graph = getHierarchyGraph(cd);
+ for (Iterator iter = cd.getFields(); iter.hasNext();) {
+ FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
+ if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
+ graph.getHNode(fieldDesc);
+ }
+ }
+ }
+
+ Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ Descriptor key = (Descriptor) iterator.next();
+ HierarchyGraph graph = getHierarchyGraph(key);
+
+ Set<HNode> nodeToBeConnected = new HashSet<HNode>();
+ for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ if (!node.isSkeleton() && !node.isCombinationNode()) {
+ if (graph.getIncomingNodeSet(node).size() == 0) {
+ nodeToBeConnected.add(node);
+ }
+ }
+ }
+
+ for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
+ graph.addEdge(graph.getHNode(TOPDESC), node);
+ }
+
+ }
+
+ }
+
+ private void constructHierarchyGraph2() {
+
+ // do fixed-point analysis
+
+ LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
+
+ // Collections.sort(descriptorListToAnalyze, new
+ // Comparator<MethodDescriptor>() {
+ // public int compare(MethodDescriptor o1, MethodDescriptor o2) {
+ // return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
+ // }
+ // });
+
+ // current descriptors to visit in fixed-point interprocedural analysis,
+ // prioritized by dependency in the call graph
+ methodDescriptorsToVisitStack.clear();
+
+ Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
+ methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
+
+ while (!descriptorListToAnalyze.isEmpty()) {
+ MethodDescriptor md = descriptorListToAnalyze.removeFirst();
+ methodDescriptorsToVisitStack.add(md);
+ }
+
+ // analyze scheduled methods until there are no more to visit
+ while (!methodDescriptorsToVisitStack.isEmpty()) {
+ // start to analyze leaf node
+ MethodDescriptor md = methodDescriptorsToVisitStack.pop();
+
+ HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
+ // MethodSummary methodSummary = new MethodSummary(md);
+
+ // MethodLocationInfo methodInfo = new MethodLocationInfo(md);
+ // curMethodInfo = methodInfo;
+
+ System.out.println();
+ System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
+
+ constructHierarchyGraph(md, hierarchyGraph);
+
+ HierarchyGraph prevHierarchyGraph = getHierarchyGraph(md);
+ // MethodSummary prevMethodSummary = getMethodSummary(md);
+
+ if (!hierarchyGraph.equals(prevHierarchyGraph)) {
+
+ mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
+ // mapDescToLocationSummary.put(md, methodSummary);
+
+ // results for callee changed, so enqueue dependents caller for
+ // further analysis
+ Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
+ while (depsItr.hasNext()) {
+ MethodDescriptor methodNext = depsItr.next();
+ if (!methodDescriptorsToVisitStack.contains(methodNext)
+ && methodDescriptorToVistSet.contains(methodNext)) {
+ methodDescriptorsToVisitStack.add(methodNext);
+ }
+ }
+
+ }
+
+ }
+
+ setupToAnalyze();
+ while (!toAnalyzeIsEmpty()) {
+ ClassDescriptor cd = toAnalyzeNext();
+ HierarchyGraph graph = getHierarchyGraph(cd);
+ for (Iterator iter = cd.getFields(); iter.hasNext();) {
+ FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
+ if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
+ graph.getHNode(fieldDesc);
+ }
+ }
+ }
+
+ Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ Descriptor key = (Descriptor) iterator.next();
+ HierarchyGraph graph = getHierarchyGraph(key);
+
+ Set<HNode> nodeToBeConnected = new HashSet<HNode>();
+ for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ if (!node.isSkeleton() && !node.isCombinationNode()) {
+ if (graph.getIncomingNodeSet(node).size() == 0) {
+ nodeToBeConnected.add(node);
+ }
+ }
+ }
+
+ for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
+ HNode node = (HNode) iterator2.next();
+ System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
+ graph.addEdge(graph.getHNode(TOPDESC), node);
+ }
+
+ }
+
+ }
+
+ private HierarchyGraph getHierarchyGraph(Descriptor d) {
+ if (!mapDescriptorToHierarchyGraph.containsKey(d)) {
+ mapDescriptorToHierarchyGraph.put(d, new HierarchyGraph(d));
+ }
+ return mapDescriptorToHierarchyGraph.get(d);
+ }
+
+ private void constructHierarchyGraph(MethodDescriptor md, HierarchyGraph methodGraph) {
+
+ // visit each node of method flow graph
+ FlowGraph fg = getFlowGraph(md);
+ // Set<FlowNode> nodeSet = fg.getNodeSet();
+
+ Set<FlowEdge> edgeSet = fg.getEdgeSet();
+
+ Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
+ for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
+ Descriptor desc = (Descriptor) iterator.next();
+ methodGraph.getHNode(desc).setSkeleton(true);
+ }
+
+ // for the method lattice, we need to look at the first element of
+ // NTuple<Descriptor>
+ boolean hasGlobalAccess = false;
+ // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+ // FlowNode originalSrcNode = (FlowNode) iterator.next();
+ for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+ FlowEdge edge = (FlowEdge) iterator.next();
+
+ FlowNode originalSrcNode = fg.getFlowNode(edge.getInitTuple());
+ Set<FlowNode> sourceNodeSet = new HashSet<FlowNode>();
+ if (originalSrcNode instanceof FlowReturnNode) {
+ FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
+ System.out.println("rnode=" + rnode);
+ Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
+ for (Iterator iterator2 = tupleSet.iterator(); iterator2.hasNext();) {
+ NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator2.next();
+ sourceNodeSet.add(fg.getFlowNode(nTuple));
+ System.out.println("&&&SOURCE fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
+ }
+ } else {
+ sourceNodeSet.add(originalSrcNode);
+ }
+
+ // System.out.println("---sourceNodeSet=" + sourceNodeSet + " from originalSrcNode="
+ // + originalSrcNode);
+
+ for (Iterator iterator3 = sourceNodeSet.iterator(); iterator3.hasNext();) {
+ FlowNode srcNode = (FlowNode) iterator3.next();
+
+ NTuple<Descriptor> srcNodeTuple = srcNode.getDescTuple();
+ Descriptor srcLocalDesc = srcNodeTuple.get(0);
+
+ if (srcLocalDesc instanceof InterDescriptor
+ && ((InterDescriptor) srcLocalDesc).getMethodArgIdxPair() != null) {
+
+ if (srcNode.getCompositeLocation() == null) {
+ continue;
+ }
+ }
+
+ // if the srcNode is started with the global descriptor
+ // need to set as a skeleton node
+ if (!hasGlobalAccess && srcNode.getDescTuple().startsWith(GLOBALDESC)) {
+ hasGlobalAccess = true;
+ }
+
+ // Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(originalSrcNode);
+ // for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
+ // FlowEdge outEdge = (FlowEdge) iterator2.next();
+ // FlowNode originalDstNode = outEdge.getDst();
+ FlowNode originalDstNode = fg.getFlowNode(edge.getEndTuple());
+
+ Set<FlowNode> dstNodeSet = new HashSet<FlowNode>();
+ if (originalDstNode instanceof FlowReturnNode) {
+ FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
+ // System.out.println("\n-returnNode=" + rnode);
+ Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
+ for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) {
+ NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator4.next();
+ dstNodeSet.add(fg.getFlowNode(nTuple));
+ System.out.println("&&&DST fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
+ }
+ } else {
+ dstNodeSet.add(originalDstNode);
+ }
+ // System.out.println("---dstNodeSet=" + dstNodeSet);
+ for (Iterator iterator4 = dstNodeSet.iterator(); iterator4.hasNext();) {
+ FlowNode dstNode = (FlowNode) iterator4.next();
+
+ NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
+ Descriptor dstLocalDesc = dstNodeTuple.get(0);
+
+ if (dstLocalDesc instanceof InterDescriptor
+ && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) {
+ if (dstNode.getCompositeLocation() == null) {
+ System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode);
+ continue;
+ }
+ }
+
+ // if (outEdge.getInitTuple().equals(srcNodeTuple)
+ // && outEdge.getEndTuple().equals(dstNodeTuple)) {
+
+ NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
+ NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
+
+ // //////////////////////////
+ // inheritance check
+ if (mapMethodDescToHighestOverriddenMethodDesc.containsKey(md)) {
+
+ MethodDescriptor highestOverriddenMethodDesc =
+ mapMethodDescToHighestOverriddenMethodDesc.get(md);
+
+ if (srcCurTuple.get(srcCurTuple.size() - 1).getSymbol().startsWith(PCLOC)) {
+ }
+
+ }
+ // //////////////////////////
+
+ System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple
+ + " srcNode=" + srcNode + " dstNode=" + dstNode);
+
+ // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple);
+ // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple);
+
+ if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
+ && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
+
+ // value flows between fields
+ Descriptor desc = srcCurTuple.get(0);
+ ClassDescriptor classDesc;
+
+ if (desc.equals(GLOBALDESC)) {
+ classDesc = md.getClassDesc();
+ } else {
+ VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
+ classDesc = varDesc.getType().getClassDesc();
+ }
+ extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
+
+ } else if ((srcCurTuple.size() == 1 && dstCurTuple.size() == 1)
+ || ((srcCurTuple.size() > 1 || dstCurTuple.size() > 1) && !srcCurTuple.get(0).equals(
+ dstCurTuple.get(0)))) {
+
+ // value flow between a primitive local var - a primitive local var or local var -
+ // field
+
+ Descriptor srcDesc = srcCurTuple.get(0);
+ Descriptor dstDesc = dstCurTuple.get(0);
+
+ methodGraph.addEdge(srcDesc, dstDesc);
+
+ if (fg.isParamDesc(srcDesc)) {
+ methodGraph.setParamHNode(srcDesc);
+ }
+ if (fg.isParamDesc(dstDesc)) {
+ methodGraph.setParamHNode(dstDesc);
+ }
+
+ }
+
+ // }
+ // }
+
+ }
+
+ }
+
+ }
+
+ // If the method accesses static fields
+ // set hasGloabalAccess true in the method summary.
+ if (hasGlobalAccess) {
+ getMethodSummary(md).setHasGlobalAccess();
+ }
+ methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
+
+ if (ssjava.getMethodContainingSSJavaLoop().equals(md)) {
+ // if the current method contains the event loop
+ // we need to set all nodes of the hierarchy graph as a skeleton node
+ Set<HNode> hnodeSet = methodGraph.getNodeSet();
+ for (Iterator iterator = hnodeSet.iterator(); iterator.hasNext();) {
+ HNode hnode = (HNode) iterator.next();
+ hnode.setSkeleton(true);
+ }
+ }
+
+ }
+
+ private NTuple<Descriptor> translateBaseTuple(FlowNode flowNode, NTuple<Descriptor> inTuple) {
+
+ if (flowNode.getBaseTuple() != null) {
+
+ NTuple<Descriptor> translatedTuple = new NTuple<Descriptor>();
+
+ NTuple<Descriptor> baseTuple = flowNode.getBaseTuple();
+
+ for (int i = 0; i < baseTuple.size(); i++) {
+ translatedTuple.add(baseTuple.get(i));
+ }
+
+ for (int i = 1; i < inTuple.size(); i++) {
+ translatedTuple.add(inTuple.get(i));
+ }
+
+ System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple);
+ return translatedTuple;
+
+ } else {
+ return inTuple;
+ }
+
+ }
+
+ private MethodSummary getMethodSummary(MethodDescriptor md) {
+ if (!mapDescToLocationSummary.containsKey(md)) {
+ mapDescToLocationSummary.put(md, new MethodSummary(md));
+ }
+ return (MethodSummary) mapDescToLocationSummary.get(md);
+ }
+
+ private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
+
+ String classSymbol = cd.getSymbol();
+ int idx = classSymbol.lastIndexOf("$");
+ if (idx != -1) {
+ classSymbol = classSymbol.substring(idx + 1);
+ }
+
+ String pattern = "class " + classSymbol + " ";
+ if (strLine.indexOf(pattern) != -1) {
+ mapDescToDefinitionLine.put(cd, lineNum);
+ }
+ }
+
+ private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
+ int lineNum) {
+ for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
+ MethodDescriptor md = (MethodDescriptor) iterator.next();
+ String pattern = md.getMethodDeclaration();
+ if (strLine.indexOf(pattern) != -1) {
+ mapDescToDefinitionLine.put(md, lineNum);
+ methodSet.remove(md);
+ return;
+ }
+ }
+
+ }
+
+ private void readOriginalSourceFiles() {
+
+ SymbolTable classtable = state.getClassSymbolTable();
+
+ Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
+ classDescSet.addAll(classtable.getValueSet());
+
+ try {
+ // inefficient implement. it may re-visit the same file if the file
+ // contains more than one class definitions.
+ for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
+ ClassDescriptor cd = (ClassDescriptor) iterator.next();
+
+ Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
+ methodSet.addAll(cd.getMethodTable().getValueSet());
+
+ String sourceFileName = cd.getSourceFileName();
+ Vector<String> lineVec = new Vector<String>();
+
+ mapFileNameToLineVector.put(sourceFileName, lineVec);
+
+ BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
+ String strLine;
+ int lineNum = 1;
+ lineVec.add(""); // the index is started from 1.
+ while ((strLine = in.readLine()) != null) {
+ lineVec.add(lineNum, strLine);
+ addMapClassDefinitionToLineNum(cd, strLine, lineNum);
+ addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
+ lineNum++;
+ }
+
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private String generateLatticeDefinition(Descriptor desc) {
+
+ Set<String> sharedLocSet = new HashSet<String>();
+
+ SSJavaLattice<String> lattice = getLattice(desc);
+ String rtr = "@LATTICE(\"";
+
+ Map<String, Set<String>> map = lattice.getTable();
+ Set<String> keySet = map.keySet();
+ boolean first = true;
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ String key = (String) iterator.next();
+ if (!key.equals(lattice.getTopItem())) {
+ Set<String> connectedSet = map.get(key);
+
+ if (connectedSet.size() == 1) {
+ if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
+ if (!first) {
+ rtr += ",";
+ } else {
+ rtr += "LOC,";
+ first = false;
+ }
+ rtr += key;
+ if (lattice.isSharedLoc(key)) {
+ rtr += "," + key + "*";
+ }
+ }
+ }
+
+ for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
+ String loc = (String) iterator2.next();
+ if (!loc.equals(lattice.getBottomItem())) {
+ if (!first) {
+ rtr += ",";
+ } else {
+ rtr += "LOC,";
+ first = false;
+ }
+ rtr += loc + "<" + key;
+ if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
+ rtr += "," + key + "*";
+ sharedLocSet.add(key);
+ }
+ if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
+ rtr += "," + loc + "*";
+ sharedLocSet.add(loc);
+ }
+
+ }
+ }
+ }
+ }
+
+ 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)) {
+ 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) + "\")";
+ }
+ }
+
+ if (!md.isStatic()) {
+ rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")";
+ }
+ rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
+
+ } else {
+ rtr += "\")";
+ }
+
+ return rtr;
+ }
+
+ private void generateAnnoatedCode() {
+
+ readOriginalSourceFiles();
+
+ setupToAnalyze();
+ while (!toAnalyzeIsEmpty()) {
+ ClassDescriptor cd = toAnalyzeNext();
+
+ setupToAnalazeMethod(cd);
+
+ String sourceFileName = cd.getSourceFileName();
+
+ if (cd.isInterface()) {
+ continue;
+ }
+
+ int classDefLine = mapDescToDefinitionLine.get(cd);
+ Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
+
+ LocationSummary fieldLocSummary = getLocationSummary(cd);
+
+ String fieldLatticeDefStr = generateLatticeDefinition(cd);
+ String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
+ sourceVec.set(classDefLine, annoatedSrc);
+
+ // generate annotations for field declarations
+ // Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
+ Map<String, String> mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName();
+
+ for (Iterator iter = cd.getFields(); iter.hasNext();) {
+ FieldDescriptor fd = (FieldDescriptor) iter.next();
+
+ String locAnnotationStr;
+ // CompositeLocation inferLoc = inferLocMap.get(fd);
+ String locName = mapFieldNameToLocName.get(fd.getSymbol());
+
+ if (locName != null) {
+ // infer loc is null if the corresponding field is static and final
+ // locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
+ locAnnotationStr = "@LOC(\"" + locName + "\")";
+ int fdLineNum = fd.getLineNum();
+ String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
+ String fieldDeclaration = fd.toString();
+ fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
+ String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
+ sourceVec.set(fdLineNum, annoatedStr);
+ }
+
+ }
+
+ while (!toAnalyzeMethodIsEmpty()) {
+ MethodDescriptor md = toAnalyzeMethodNext();
+
+ if (!ssjava.needTobeAnnotated(md)) {
+ continue;
+ }
+
+ SSJavaLattice<String> methodLattice = md2lattice.get(md);
+ if (methodLattice != null) {
+
+ int methodDefLine = md.getLineNum();
+
+ // MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
+ // Map<Descriptor, CompositeLocation> methodInferLocMap =
+ // methodLocInfo.getMapDescToInferLocation();
+
+ MethodSummary methodSummary = getMethodSummary(md);
+
+ Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
+ methodSummary.getMapVarDescToInferCompositeLocation();
+ System.out.println("-----md=" + md);
+ System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
+
+ Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
+
+ Set<String> localLocElementSet = methodLattice.getElementSet();
+
+ for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
+ Descriptor localVarDesc = (Descriptor) iterator.next();
+ System.out.println("-------localVarDesc=" + localVarDesc);
+ CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc);
+
+ String localLocIdentifier = inferLoc.get(0).getLocIdentifier();
+ if (!localLocElementSet.contains(localLocIdentifier)) {
+ methodLattice.put(localLocIdentifier);
+ }
+
+ String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
+
+ if (!isParameter(md, localVarDesc)) {
+ 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
+ + " generateVarDeclaration((VarDescriptor) localVarDesc)="
+ + generateVarDeclaration((VarDescriptor) localVarDesc));
+ assert (idx != -1);
+ String annoatedStr =
+ orgSourceLine.substring(0, idx) + locAnnotationStr + " "
+ + orgSourceLine.substring(idx);
+ sourceVec.set(varLineNum, annoatedStr);
+ }
+ } else {
+ String methodDefStr = sourceVec.get(methodDefLine);
+
+ int idx =
+ getParamLocation(methodDefStr,
+ generateVarDeclaration((VarDescriptor) localVarDesc));
+ System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc
+ + " idx=" + idx);
+ assert (idx != -1);
+
+ String annoatedStr =
+ methodDefStr.substring(0, idx) + locAnnotationStr + " "
+ + methodDefStr.substring(idx);
+ sourceVec.set(methodDefLine, annoatedStr);
+ }
+
+ }
+
+ // check if the lattice has to have the location type for the this
+ // reference...
+
+ // boolean needToAddthisRef = hasThisReference(md);
+ // if (localLocElementSet.contains("this")) {
+ // methodLattice.put("this");
+ // }
+
+ String methodLatticeDefStr = generateLatticeDefinition(md);
+ String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
+ sourceVec.set(methodDefLine, annoatedStr);
+
+ }
+ }
+
+ }
+
+ codeGen();
+ }
+
+ private boolean hasThisReference(MethodDescriptor md) {
+
+ FlowGraph fg = getFlowGraph(md);
+ Set<FlowNode> nodeSet = fg.getNodeSet();
+ for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+ FlowNode flowNode = (FlowNode) iterator.next();
+ if (flowNode.getDescTuple().get(0).equals(md.getThis())) {
+ return true;
+ }
+ }
+
+ return false;