X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FLocationInference.java;h=6404a8f9984fdc520736c8a12d0ebf077898cf04;hb=cdfc189fb3563488aa35b9faed2165a95aaee103;hp=c9877d8e611e19adf14d32137be2dcbb24cd819c;hpb=70aff04c5bb5a7b5f5693a72a29a1abf97004e8d;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index c9877d8e..6404a8f9 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -184,7 +184,14 @@ public class LocationInference { } private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) { - String pattern = "class " + cd.getSymbol() + " "; + + 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); } @@ -246,6 +253,8 @@ public class LocationInference { private String generateLatticeDefinition(Descriptor desc) { + Set sharedLocSet = new HashSet(); + SSJavaLattice lattice = getLattice(desc); String rtr = "@LATTICE(\""; @@ -266,6 +275,9 @@ public class LocationInference { first = false; } rtr += key; + if (lattice.isSharedLoc(key)) { + rtr += "," + key + "*"; + } } } @@ -279,6 +291,15 @@ public class LocationInference { 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); + } + } } } @@ -303,63 +324,60 @@ public class LocationInference { readOriginalSourceFiles(); setupToAnalyze(); - while (!toAnalyzeIsEmpty()) { ClassDescriptor cd = toAnalyzeNext(); setupToAnalazeMethod(cd); LocationInfo locInfo = mapClassToLocationInfo.get(cd); - String sourceFileName = cd.getSourceFileName(); + if (cd.isInterface()) { + continue; + } + int classDefLine = mapDescToDefinitionLine.get(cd); Vector sourceVec = mapFileNameToLineVector.get(sourceFileName); - if (locInfo != null) { + if (locInfo == null) { + locInfo = getLocationInfo(cd); + } - Map mapDescToInferLoc = locInfo.getMapDescToInferLocation(); - Set fieldDescSet = mapDescToInferLoc.keySet(); - for (Iterator iterator = fieldDescSet.iterator(); iterator.hasNext();) { - Descriptor fieldDesc = (Descriptor) iterator.next(); - String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier(); - if (!getLattice(cd).containsKey(locIdentifier)) { - getLattice(cd).put(locIdentifier); - } + for (Iterator iter = cd.getFields(); iter.hasNext();) { + Descriptor fieldDesc = (Descriptor) iter.next(); + String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier(); + if (!getLattice(cd).containsKey(locIdentifier)) { + getLattice(cd).put(locIdentifier); } + } - String fieldLatticeDefStr = generateLatticeDefinition(cd); - String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine); - sourceVec.set(classDefLine, annoatedSrc); - - // generate annotations for field declarations - LocationInfo fieldLocInfo = getLocationInfo(cd); - Map inferLocMap = fieldLocInfo.getMapDescToInferLocation(); - - for (Iterator iter = cd.getFields(); iter.hasNext();) { - FieldDescriptor fd = (FieldDescriptor) iter.next(); + String fieldLatticeDefStr = generateLatticeDefinition(cd); + String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine); + sourceVec.set(classDefLine, annoatedSrc); - String locAnnotationStr; - if (inferLocMap.containsKey(fd)) { - CompositeLocation inferLoc = inferLocMap.get(fd); - locAnnotationStr = generateLocationAnnoatation(inferLoc); - } else { - // if the field is not accssed by SS part, just assigns dummy - // location - locAnnotationStr = "@LOC(\"LOC\")"; - } - int fdLineNum = fd.getLineNum(); - String orgFieldDeclarationStr = sourceVec.get(fdLineNum); - String fieldDeclaration = fd.toString(); - fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1); + // generate annotations for field declarations + LocationInfo fieldLocInfo = getLocationInfo(cd); + Map inferLocMap = fieldLocInfo.getMapDescToInferLocation(); - int idx = orgFieldDeclarationStr.indexOf(fieldDeclaration); - String annoatedStr = - orgFieldDeclarationStr.substring(0, idx) + locAnnotationStr + " " - + orgFieldDeclarationStr.substring(idx); - sourceVec.set(fdLineNum, annoatedStr); + for (Iterator iter = cd.getFields(); iter.hasNext();) { + FieldDescriptor fd = (FieldDescriptor) iter.next(); + String locAnnotationStr; + if (inferLocMap.containsKey(fd)) { + CompositeLocation inferLoc = inferLocMap.get(fd); + locAnnotationStr = generateLocationAnnoatation(inferLoc); + } else { + // if the field is not accssed by SS part, just assigns dummy + // location + locAnnotationStr = "@LOC(\"LOC\")"; } + 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); } @@ -372,22 +390,23 @@ public class LocationInference { MethodLocationInfo methodLocInfo = getMethodLocationInfo(md); - Map inferLocMap = + Map methodInferLocMap = methodLocInfo.getMapDescToInferLocation(); - Set localVarDescSet = inferLocMap.keySet(); + Set localVarDescSet = methodInferLocMap.keySet(); for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) { Descriptor localVarDesc = (Descriptor) iterator.next(); - CompositeLocation inferLoc = inferLocMap.get(localVarDesc); + CompositeLocation inferLoc = methodInferLocMap.get(localVarDesc); String locAnnotationStr = generateLocationAnnoatation(inferLoc); if (!isParameter(md, localVarDesc)) { if (mapDescToDefinitionLine.containsKey(localVarDesc)) { int varLineNum = mapDescToDefinitionLine.get(localVarDesc); - String orgSourceLine = sourceVec.get(varLineNum); - int idx = orgSourceLine.indexOf(localVarDesc.toString()); + int idx = + orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc)); + assert (idx != -1); String annoatedStr = orgSourceLine.substring(0, idx) + locAnnotationStr + " " + orgSourceLine.substring(idx); @@ -395,7 +414,7 @@ public class LocationInference { } } else { String methodDefStr = sourceVec.get(methodDefLine); - int idx = methodDefStr.indexOf(localVarDesc.toString()); + int idx = methodDefStr.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc)); assert (idx != -1); String annoatedStr = methodDefStr.substring(0, idx) + locAnnotationStr + " " @@ -411,11 +430,26 @@ public class LocationInference { } } + } codeGen(); } + private String generateVarDeclaration(VarDescriptor varDesc) { + + TypeDescriptor td = varDesc.getType(); + String rtr = td.toString(); + if (td.isArray()) { + for (int i = 0; i < td.getArrayCount(); i++) { + rtr += "[]"; + } + } + rtr += " " + varDesc.getName(); + return rtr; + + } + private String generateLocationAnnoatation(CompositeLocation loc) { String rtr = "@LOC(\"";