assignLocationOfVarDescriptor(vd, md, md.getParameterTable(), bn);
paramList.add(d2loc.get(vd));
}
+ Vector<AnnotationDescriptor> methodAnnotations = md.getModifiers().getAnnotations();
// second, check return location annotation
if (!md.getReturnType().isVoid()) {
CompositeLocation returnLocComp = null;
- Vector<AnnotationDescriptor> methodAnnotations = md.getModifiers().getAnnotations();
- if (methodAnnotations != null) {
- for (int i = 0; i < methodAnnotations.size(); i++) {
- AnnotationDescriptor an = methodAnnotations.elementAt(i);
- if (an.getMarker().equals(ssjava.RETURNLOC)) {
- // developer explicitly defines method lattice
- String returnLocDeclaration = an.getValue();
- returnLocComp = parseLocationDeclaration(md, null, returnLocDeclaration);
- md2ReturnLoc.put(md, returnLocComp);
+
+ String rtrStr = ssjava.getMethodLattice(md).getReturnLoc();
+ if (rtrStr != null) {
+ returnLocComp = new CompositeLocation(new Location(md, rtrStr));
+ } else {
+ if (methodAnnotations != null) {
+ for (int i = 0; i < methodAnnotations.size(); i++) {
+ AnnotationDescriptor an = methodAnnotations.elementAt(i);
+ if (an.getMarker().equals(ssjava.RETURNLOC)) {
+ // this case, developer explicitly defines method lattice
+ String returnLocDeclaration = an.getValue();
+ returnLocComp = parseLocationDeclaration(md, null, returnLocDeclaration);
+ }
+ }
+ } else {
+ // if developer does not define method lattice
+ // search return location in the method default lattice
+ if (returnLocComp == null) {
+ MethodLattice<String> methodDefaultLattice = ssjava.getMethodDefaultLattice(cd);
+ if (methodDefaultLattice.getReturnLoc() != null) {
+ returnLocComp =
+ parseLocationDeclaration(md, null, methodDefaultLattice.getReturnLoc());
+ }
}
- }
- }
- if (returnLocComp == null) {
- MethodLattice<String> methodDefaultLattice = ssjava.getMethodDefaultLattice(cd);
- if (methodDefaultLattice.getReturnLoc() != null) {
- returnLocComp = parseLocationDeclaration(md, null, methodDefaultLattice.getReturnLoc());
- md2ReturnLoc.put(md, returnLocComp);
}
}
- if (!md2ReturnLoc.containsKey(md)) {
+ if (returnLocComp == null) {
throw new Error("Return location is not specified for the method " + md + " at "
+ cd.getSourceFileName());
}
+ md2ReturnLoc.put(md, returnLocComp);
+
// check this location
MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
String thisLocId = methodLattice.getThisLoc();
CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
paramList.add(0, thisLoc);
- md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), paramList,
- generateErrorMessage(cd, null)));
+ System.out.println("### ReturnLocGenerator=" + md);
+ System.out.println("### md2ReturnLoc.get(md)=" + md2ReturnLoc.get(md));
+ md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), paramList, md + " of "
+ + cd.getSourceFileName()));
}
- // third, check declarations inside of method
+ // fourth, check declarations inside of method
checkDeclarationInBlockNode(md, md.getParameterTable(), bn);
CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md);
int compareResult =
- CompositeLattice.compare(returnValueLoc, declaredReturnLoc,
+ CompositeLattice.compare(returnValueLoc, declaredReturnLoc, false,
generateErrorMessage(md.getClassDesc(), rn));
if (compareResult == ComparisonResult.LESS || compareResult == ComparisonResult.INCOMPARABLE) {
SymbolTable nametable, MethodInvokeNode min, CompositeLocation loc,
CompositeLocation constraint) {
- checkCalleeConstraints(md, nametable, min, constraint);
-
CompositeLocation baseLocation = null;
if (min.getExpression() != null) {
baseLocation =
baseLocation = new CompositeLocation(new Location(md, thisLocId));
}
+ checkCalleeConstraints(md, nametable, min, baseLocation, constraint);
+
if (!min.getMethod().getReturnType().isVoid()) {
// If method has a return value, compute the highest possible return
// location in the caller's perspective
}
private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable,
- MethodInvokeNode min, CompositeLocation constraint) {
+ MethodInvokeNode min, CompositeLocation callerBaseLoc, CompositeLocation constraint) {
- if (min.numArgs() > 1) {
+ MethodDescriptor calleemd = min.getMethod();
+
+ MethodLattice<String> calleeLattice = ssjava.getMethodLattice(calleemd);
+ CompositeLocation calleeThisLoc =
+ new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc()));
+
+ List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
+ List<CompositeLocation> calleeParamList = new ArrayList<CompositeLocation>();
+
+ if (min.numArgs() > 0) {
// caller needs to guarantee that it passes arguments in regarding to
// callee's hierarchy
+
+ // setup caller args set
+ // first, add caller's base(this) location
+ callerArgList.add(callerBaseLoc);
+ // second, add caller's arguments
for (int i = 0; i < min.numArgs(); i++) {
ExpressionNode en = min.getArg(i);
- CompositeLocation callerArg1 =
+ CompositeLocation callerArgLoc =
checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation(), constraint,
false);
+ callerArgList.add(callerArgLoc);
+ }
+
+ // setup callee params set
+ // first, add callee's this location
+ calleeParamList.add(calleeThisLoc);
+ // second, add callee's parameters
+ for (int i = 0; i < calleemd.numParameters(); i++) {
+ VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
+ CompositeLocation calleeLoc = d2loc.get(calleevd);
+ calleeParamList.add(calleeLoc);
+ }
+
+ // here, check if ordering relations among caller's args respect
+ // ordering relations in-between callee's args
+ CHECK: for (int i = 0; i < calleeParamList.size(); i++) {
+ CompositeLocation calleeLoc1 = calleeParamList.get(i);
+ CompositeLocation callerLoc1 = callerArgList.get(i);
+
+ for (int j = 0; j < calleeParamList.size(); j++) {
+ if (i != j) {
+ CompositeLocation calleeLoc2 = calleeParamList.get(j);
+ CompositeLocation callerLoc2 = callerArgList.get(j);
+
+ if (callerLoc1.get(callerLoc1.getSize() - 1).isTop()
+ || callerLoc2.get(callerLoc2.getSize() - 1).isTop()) {
+ continue CHECK;
+ }
+
+ int callerResult =
+ CompositeLattice.compare(callerLoc1, callerLoc2, true,
+ generateErrorMessage(md.getClassDesc(), min));
+ int calleeResult =
+ CompositeLattice.compare(calleeLoc1, calleeLoc2, true,
+ generateErrorMessage(md.getClassDesc(), min));
+
+ if (calleeResult == ComparisonResult.GREATER
+ && callerResult != ComparisonResult.GREATER) {
+ // If calleeLoc1 is higher than calleeLoc2
+ // then, caller should have same ordering relation in-bet
+ // callerLoc1 & callerLoc2
+
+ String paramName1, paramName2;
+
+ if (i == 0) {
+ paramName1 = "'THIS'";
+ } else {
+ paramName1 = "'parameter " + calleemd.getParamName(i - 1) + "'";
+ }
- VarDescriptor calleevd = (VarDescriptor) min.getMethod().getParameter(i);
- CompositeLocation calleeLoc1 = d2loc.get(calleevd);
-
- if (!callerArg1.get(0).isTop()) {
- // here, check if ordering relations among caller's args respect
- // ordering relations in-between callee's args
- for (int currentIdx = 0; currentIdx < min.numArgs(); currentIdx++) {
- if (currentIdx != i) { // skip itself
- ExpressionNode argExp = min.getArg(currentIdx);
-
- CompositeLocation callerArg2 =
- checkLocationFromExpressionNode(md, nametable, argExp, new CompositeLocation(),
- constraint, false);
-
- VarDescriptor calleevd2 = (VarDescriptor) min.getMethod().getParameter(currentIdx);
- CompositeLocation calleeLoc2 = d2loc.get(calleevd2);
-
- int callerResult =
- CompositeLattice.compare(callerArg1, callerArg2,
- generateErrorMessage(md.getClassDesc(), min));
- int calleeResult =
- CompositeLattice.compare(calleeLoc1, calleeLoc2,
- generateErrorMessage(md.getClassDesc(), min));
-
- if (calleeResult == ComparisonResult.GREATER
- && callerResult != ComparisonResult.GREATER) {
- // If calleeLoc1 is higher than calleeLoc2
- // then, caller should have same ordering relation in-bet
- // callerLoc1 & callerLoc2
-
- throw new Error("Caller doesn't respect ordering relations among method arguments:"
- + md.getClassDesc().getSourceFileName() + ":" + min.getNumLine());
+ if (j == 0) {
+ paramName2 = "'THIS'";
+ } else {
+ paramName2 = "'parameter " + calleemd.getParamName(j - 1) + "'";
}
+ throw new Error(
+ "Caller doesn't respect an ordering relation among method arguments: callee expects that "
+ + paramName1 + " should be higher than " + paramName2 + " in " + calleemd
+ + " at " + md.getClassDesc().getSourceFileName() + ":" + min.getNumLine());
}
}
- }
+ }
}
}
Location locElement = new Location(md, thisLocId);
loc.addLocation(locElement);
return loc;
+
}
Descriptor d = (Descriptor) nametable.get(varname);
System.out.println("rhsLocation=" + rhsLocation);
System.out.println("constraint=" + constraint);
- if (constraint != null) {
- inputGLBSet.add(rhsLocation);
- inputGLBSet.add(constraint);
- srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an));
- } else {
- srcLocation = rhsLocation;
+ srcLocation = rhsLocation;
+
+ if (!rhsLocation.get(rhsLocation.getSize() - 1).isTop()) {
+ if (constraint != null) {
+ inputGLBSet.add(rhsLocation);
+ inputGLBSet.add(constraint);
+ srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an));
+ }
}
if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
public static boolean isGreaterThan(CompositeLocation loc1, CompositeLocation loc2, String msg) {
System.out.println("\nisGreaterThan=" + loc1 + " " + loc2 + " msg=" + msg);
- int baseCompareResult = compareBaseLocationSet(loc1, loc2, true, msg);
+ int baseCompareResult = compareBaseLocationSet(loc1, loc2, true, false, msg);
if (baseCompareResult == ComparisonResult.EQUAL) {
if (compareDelta(loc1, loc2) == ComparisonResult.GREATER) {
return true;
}
- public static int compare(CompositeLocation loc1, CompositeLocation loc2, String msg) {
+ public static int compare(CompositeLocation loc1, CompositeLocation loc2, boolean ignore,
+ String msg) {
System.out.println("compare=" + loc1 + " " + loc2);
- int baseCompareResult = compareBaseLocationSet(loc1, loc2, false, msg);
+ int baseCompareResult = compareBaseLocationSet(loc1, loc2, false, ignore, msg);
if (baseCompareResult == ComparisonResult.EQUAL) {
return compareDelta(loc1, loc2);
}
private static int compareBaseLocationSet(CompositeLocation compLoc1,
- CompositeLocation compLoc2, boolean awareSharedLoc, String msg) {
+ CompositeLocation compLoc2, boolean awareSharedLoc, boolean ignore, String msg) {
// if compLoc1 is greater than compLoc2, return true
// else return false;
for (int i = 0; i < compLoc1.getSize(); i++) {
Location loc1 = compLoc1.get(i);
if (i >= compLoc2.getSize()) {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- }
- Location loc2 = compLoc2.get(i);
-
- Descriptor d1 = loc1.getDescriptor();
- Descriptor d2 = loc2.getDescriptor();
-
- Descriptor descriptor;
-
- if (d1 instanceof ClassDescriptor && d2 instanceof ClassDescriptor) {
-
- if (d1.equals(d2)) {
- descriptor = d1;
- } else {
- // identifying which one is parent class
- Set<Descriptor> d1SubClassesSet = ssjava.tu.getSubClasses((ClassDescriptor) d1);
- Set<Descriptor> d2SubClassesSet = ssjava.tu.getSubClasses((ClassDescriptor) d2);
-
- if (d1 == null && d2 == null) {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- } else if (d1SubClassesSet != null && d1SubClassesSet.contains(d2)) {
- descriptor = d1;
- } else if (d2SubClassesSet != null && d2SubClassesSet.contains(d1)) {
- descriptor = d2;
- } else {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- }
- }
-
- } else if (d1 instanceof MethodDescriptor && d2 instanceof MethodDescriptor) {
-
- if (d1.equals(d2)) {
- descriptor = d1;
+ if (ignore) {
+ return ComparisonResult.INCOMPARABLE;
} else {
-
- // identifying which one is parent class
- MethodDescriptor md1 = (MethodDescriptor) d1;
- MethodDescriptor md2 = (MethodDescriptor) d2;
-
- if (!md1.matches(md2)) {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- }
-
- Set<Descriptor> d1SubClassesSet =
- ssjava.tu.getSubClasses(((MethodDescriptor) d1).getClassDesc());
- Set<Descriptor> d2SubClassesSet =
- ssjava.tu.getSubClasses(((MethodDescriptor) d2).getClassDesc());
-
- if (d1 == null && d2 == null) {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- } else if (d1 != null && d1SubClassesSet.contains(d2)) {
- descriptor = d1;
- } else if (d2 != null && d2SubClassesSet.contains(d1)) {
- descriptor = d2;
- } else {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
- }
+ throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
+ + " because they are not comparable at " + msg);
}
-
- } else {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
}
+ Location loc2 = compLoc2.get(i);
- // SSJavaLattice<String> lattice1 = getLatticeByDescriptor(d1);
- // SSJavaLattice<String> lattice2 = getLatticeByDescriptor(d2);
-
+ Descriptor descriptor = getCommonParentDescriptor(loc1, loc2, msg);
SSJavaLattice<String> lattice = getLatticeByDescriptor(descriptor);
- // check if the spin location is appeared only at the end of the
+ // check if the shared location is appeared only at the end of the
// composite location
- if (lattice.getSpinLocSet().contains(loc1.getLocIdentifier())) {
+ if (lattice.getSharedLocSet().contains(loc1.getLocIdentifier())) {
if (i != (compLoc1.getSize() - 1)) {
throw new Error("The shared location " + loc1.getLocIdentifier()
+ " cannot be appeared in the middle of composite location at" + msg);
}
}
- if (lattice.getSpinLocSet().contains(loc2.getLocIdentifier())) {
+ if (lattice.getSharedLocSet().contains(loc2.getLocIdentifier())) {
if (i != (compLoc2.getSize() - 1)) {
- throw new Error("The spin location " + loc2.getLocIdentifier()
+ throw new Error("The shared location " + loc2.getLocIdentifier()
+ " cannot be appeared in the middle of composite location at " + msg);
}
}
// note that the spinning location only can be appeared in the last
// part of the composite location
if (awareSharedLoc && numOfTie == compLoc1.getSize()
- && lattice.getSpinLocSet().contains(loc1.getLocIdentifier())) {
+ && lattice.getSharedLocSet().contains(loc1.getLocIdentifier())) {
return ComparisonResult.GREATER;
}
continue;
if (numOfTie == compLoc1.getSize()) {
if (numOfTie != compLoc2.getSize()) {
- throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
- + " because they are not comparable at " + msg);
+
+ if (ignore) {
+ return ComparisonResult.INCOMPARABLE;
+ } else {
+ throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
+ + " because they are not comparable at " + msg);
+ }
+
}
return ComparisonResult.EQUAL;
public static CompositeLocation calculateGLB(Set<CompositeLocation> inputSet, String errMsg) {
- System.out.println("Calculating GLB=" + inputSet);
+ System.out.println("Calculating GLB=" + inputSet);
CompositeLocation glbCompLoc = new CompositeLocation();
// calculate GLB of the first(priority) element
paramIdx2paramType = new Hashtable<Integer, Integer>();
for (int i = 0; i < params.size(); i++) {
CompositeLocation param = params.get(i);
- int compareResult = CompositeLattice.compare(param, returnLoc, msg);
+ int compareResult = CompositeLattice.compare(param, returnLoc, true, msg);
int type;
if (compareResult == ComparisonResult.GREATER) {