}
// second, check return location annotation
- if (!md.getReturnType().isVoid()) {
+ if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) {
if (!hasReturnLocDeclaration) {
// if developer does not define method lattice
// search return location in the method default lattice
}
- if (!md.getReturnType().isVoid()) {
+ if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) {
MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
String thisLocId = methodLattice.getThisLoc();
- if ((!md.isStatic()) && thisLocId == null) {
- throw new Error("Method '" + md + "' does not have the definition of 'this' location at "
- + md.getClassDesc().getSourceFileName());
+ if ((!md.isStatic())) {
+
+ if (thisLocId == null) {
+ throw new Error("Method '" + md + "' does not have the definition of 'this' location at "
+ + md.getClassDesc().getSourceFileName());
+ }
+
+ CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
+ paramList.add(0, thisLoc);
+
}
- CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
- paramList.add(0, thisLoc);
+
md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md
+ " of " + cd.getSourceFileName()));
+
}
// fourth, check declarations inside of method
private CompositeLocation checkLocationFromReturnNode(MethodDescriptor md, SymbolTable nametable,
ReturnNode rn, CompositeLocation constraint) {
+ if (ssjava.getMethodContainingSSJavaLoop().equals(md)) {
+ return new CompositeLocation();
+ }
+
ExpressionNode returnExp = rn.getReturnExpression();
+ CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md);
+
CompositeLocation returnValueLoc;
if (returnExp != null) {
returnValueLoc =
// generateErrorMessage(md.getClassDesc(), rn));
// }
+ if (constraint != null) {
+
+ // Set<CompositeLocation> inputGLB = new HashSet<CompositeLocation>();
+ // inputGLB.add(returnValueLoc);
+ // inputGLB.add(constraint);
+ // returnValueLoc =
+ // CompositeLattice.calculateGLB(inputGLB,
+ // generateErrorMessage(md.getClassDesc(), rn));
+
+ // if (!returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()) {
+ // if (!CompositeLattice.isGreaterThan(constraint, returnValueLoc,
+ // generateErrorMessage(md.getClassDesc(), rn))) {
+ // System.out.println("returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()="
+ // + returnValueLoc.get(returnValueLoc.getSize() - 1).isTop());
+ // throw new Error("The value flow from " + constraint + " to " +
+ // returnValueLoc
+ // + " does not respect location hierarchy on the assignment " +
+ // rn.printNode(0)
+ // + " at " + md.getClassDesc().getSourceFileName() + "::" +
+ // rn.getNumLine());
+ // }
+ // }
+
+ if (!CompositeLattice.isGreaterThan(constraint, declaredReturnLoc,
+ generateErrorMessage(md.getClassDesc(), rn))) {
+ throw new Error("The value flow from " + constraint + " to " + declaredReturnLoc
+ + " does not respect location hierarchy on the assignment " + rn.printNode(0)
+ + " at " + md.getClassDesc().getSourceFileName() + "::" + rn.getNumLine());
+ }
+
+ }
+
// check if return value is equal or higher than RETRUNLOC of method
// declaration annotation
- CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md);
int compareResult =
CompositeLattice.compare(returnValueLoc, declaredReturnLoc, false,
private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) {
+ System.out.println("checkLocationFromIfStatementNode=" + isn);
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(),
constraint, false);
- // addLocationType(isn.getCondition().getType(), condLoc);
+ System.out.println("-######old constraint=" + constraint);
constraint = generateNewConstraint(constraint, condLoc);
+ System.out.println("-######new constraint=" + constraint);
checkLocationFromBlockNode(md, nametable, isn.getTrueBlock(), constraint);
if (isn.getFalseBlock() != null) {
for (int idx = 0; idx < callerArgList.size(); idx++) {
CompositeLocation argLocation = callerArgList.get(idx);
- // need to check that param is higher than PCLOC
+ // if the PC location is lower than an argument location
+ // then, need to check that the callee's the initial location for the PC is also lower
+ // than the corresponding parameter location
+
if (!argLocation.get(0).isTop()
&& CompositeLattice.compare(argLocation, constraint, true,
- generateErrorMessage(cd, min)) == ComparisonResult.GREATER) {
+ generateErrorMessage(cd, min)) == ComparisonResult.LESS) {
CompositeLocation paramLocation = calleeParamList.get(idx);
int paramCompareResult =
- CompositeLattice.compare(calleePCLOC, paramLocation, true,
+ CompositeLattice.compare(paramLocation, calleePCLOC, true,
generateErrorMessage(cd, min));
-
- if (paramCompareResult == ComparisonResult.GREATER) {
+ // CompositeLattice.compare(calleePCLOC, paramLocation, true,
+ // generateErrorMessage(cd, min));
+
+ System.out.println("-CHECKPCLOC:");
+ System.out.println("---ARG LOC="
+ + argLocation
+ + " callerPCLOC="
+ + constraint
+ + " result="
+ + CompositeLattice.compare(argLocation, constraint, true,
+ generateErrorMessage(cd, min)));
+ System.out.println("---PARAM LOC=" + paramLocation + " calleePCLOC=" + calleePCLOC
+ + " paramCompareResult=" + paramCompareResult);
+
+ if (!(paramLocation.get(0).equals(calleePCLOC.get(0)) && calleePCLOC.getSize() > 1)
+ && paramCompareResult != ComparisonResult.LESS) {
throw new Error(
"The program counter location "
+ constraint
checkCalleeConstraints(md, nametable, min, baseLocation, constraint);
- // checkCallerArgumentLocationConstraints(md, nametable, min,
- // baseLocation, constraint);
+ checkCallerArgumentLocationConstraints(md, nametable, min, baseLocation, constraint);
if (!min.getMethod().getReturnType().isVoid()) {
// If method has a return value, compute the highest possible return
MethodDescriptor calleemd = min.getMethod();
+ if (calleemd.isStatic()) {
+ return;
+ }
+
List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
List<CompositeLocation> calleeParamList = new ArrayList<CompositeLocation>();
generateErrorMessage(md.getClassDesc(), min));
}
- if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg)) {
+ Location argLastLoc = callerArgLoc.get(callerArgLoc.getSize() - 1);
+ Location paramLastLoc = paramLocation.get(paramLocation.getSize() - 1);
+
+ if (argLastLoc.equals(paramLastLoc) && ssjava.isSharedLocation(argLastLoc)
+ && ssjava.isSharedLocation(paramLastLoc)) {
+ continue;
+ }
+
+ // if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg)) {
+ if (CompositeLattice.compare(callerArgLoc, paramLocation, true, errorMsg) == ComparisonResult.LESS) {
throw new Error("Caller argument '" + min.getArg(i).printNode(0) + " : " + callerArgLoc
+ "' should be higher than corresponding callee's parameter : " + paramLocation
+ " at " + errorMsg);
List<CompositeLocation> argList = new ArrayList<CompositeLocation>();
// by default, method has a THIS parameter
- if (!md.isStatic()) {
+ if (!min.getMethod().isStatic()) {
argList.add(baseLocation);
}
argList.add(callerArg);
}
- // System.out.println("\n## computeReturnLocation=" + min.getMethod() +
- // " argList=" + argList);
+ // System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList);
CompositeLocation ceilLoc = md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList);
// System.out.println("## ReturnLocation=" + ceilLoc);
MethodLattice<String> calleeLattice = ssjava.getMethodLattice(calleemd);
- CompositeLocation calleeThisLoc =
- new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc()));
+ System.out.println("checkCalleeConstraints=" + calleemd + " calleeLattice.getThisLoc()="
+ + calleeLattice.getThisLoc());
List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
List<CompositeLocation> calleeParamList = new ArrayList<CompositeLocation>();
// setup callee params set
// first, add callee's this location
- if (!calleemd.isStatic())
+ if (!calleemd.isStatic()) {
+ CompositeLocation calleeThisLoc =
+ new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc()));
calleeParamList.add(calleeThisLoc);
+ }
// second, add callee's parameters
for (int i = 0; i < calleemd.numParameters(); i++) {
VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
String paramName1, paramName2;
- if (i == 0) {
- paramName1 = "'THIS'";
+ if (!calleemd.isStatic()) {
+ if (i == 0) {
+ paramName1 = "'THIS'";
+ } else {
+ paramName1 = "'parameter " + calleemd.getParamName(i - 1) + "'";
+ }
} else {
- paramName1 = "'parameter " + calleemd.getParamName(i - 1) + "'";
+ paramName1 = "'parameter " + calleemd.getParamName(i) + "'";
}
- if (j == 0) {
- paramName2 = "'THIS'";
+ if (!calleemd.isStatic()) {
+ if (j == 0 && !calleemd.isStatic()) {
+ paramName2 = "'THIS'";
+ } else {
+ paramName2 = "'parameter " + calleemd.getParamName(j - 1) + "'";
+ }
} else {
- paramName2 = "'parameter " + calleemd.getParamName(j - 1) + "'";
+ paramName2 = "'parameter " + calleemd.getParamName(j) + "'";
}
throw new Error(
private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md,
SymbolTable nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean isLHS) {
-
+ // System.out.println("aan=" + aan.printNode(0) + " line#=" + aan.getNumLine());
ClassDescriptor cd = md.getClassDesc();
CompositeLocation arrayLoc =
}
}
+
return loc;
}
inputGLB.add(loc);
loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan));
+
return loc;
}
private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
+
ClassDescriptor cd = md.getClassDesc();
Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
// generateErrorMessage(cd, an));
}
+ // System.out.println("src=" + srcLocation + " dest=" + destLocation + " const=" +
+ // constraint);
+
if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
String context = "";
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
}
}
- // System.out.println("GLB=" + glbCompLoc);
+ System.out.println("GLB=" + glbCompLoc + "\n");
return glbCompLoc;
}