X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FFlowDownCheck.java;h=85b36731c909080f71cf361ad6e092edd00b47cb;hb=34e201e35ec38f4d644a5279a9fa6d9a4ca1e08d;hp=a851b020e2125457c9b34f63f18e84fcda44d63a;hpb=d396c42d2a86460c7e220d21e5219049c177c5cf;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index a851b020..85b36731 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -6,7 +6,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.StringTokenizer; @@ -227,8 +226,7 @@ public class FlowDownCheck { if (state.SSJAVADEBUG) { System.out.println("SSJAVA: Checking Flow-down Rules: " + md); } - CompositeLocation calleePCLOC = - new CompositeLocation(new Location(md, ssjava.getMethodLattice(md).getPCLoc())); + CompositeLocation calleePCLOC = ssjava.getPCLocation(md); checkMethodBody(cd, md, calleePCLOC); } } @@ -327,8 +325,8 @@ public class FlowDownCheck { String globalLoc = an.getValue(); ssjava.getMethodLattice(md).setGlobalLoc(globalLoc); } else if (an.getMarker().equals(ssjava.PCLOC)) { - String pcLoc = an.getValue(); - ssjava.getMethodLattice(md).setPCLoc(pcLoc); + String pcLocDeclaration = an.getValue(); + ssjava.setPCLocation(md, parseLocationDeclaration(md, null, pcLocDeclaration)); } } } @@ -905,7 +903,7 @@ public class FlowDownCheck { CompositeLocation constraint) { ClassDescriptor cd = md.getClassDesc(); - MethodDescriptor calleeMD = min.getMethod(); + MethodDescriptor calleeMethodDesc = min.getMethod(); NameDescriptor baseName = min.getBaseName(); boolean isSystemout = false; @@ -913,8 +911,9 @@ public class FlowDownCheck { isSystemout = baseName.getSymbol().equals("System.out"); } - if (!ssjava.isSSJavaUtil(calleeMD.getClassDesc()) && !ssjava.isTrustMethod(calleeMD) - && !calleeMD.getModifiers().isNative() && !isSystemout) { + if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc()) + && !ssjava.isTrustMethod(calleeMethodDesc) && !calleeMethodDesc.getModifiers().isNative() + && !isSystemout) { CompositeLocation baseLocation = null; if (min.getExpression() != null) { @@ -942,11 +941,14 @@ public class FlowDownCheck { // setup the location list of caller's arguments List callerArgList = new ArrayList(); + // setup the location list of callee's parameters + MethodLattice calleeLattice = ssjava.getMethodLattice(calleeMethodDesc); + List calleeParamList = new ArrayList(); + if (min.numArgs() > 0) { - // setup caller args set - // first, add caller's base(this) location - callerArgList.add(baseLocation); - // second, add caller's arguments + if (!calleeMethodDesc.isStatic()) { + callerArgList.add(baseLocation); + } for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); CompositeLocation callerArgLoc = @@ -954,21 +956,18 @@ public class FlowDownCheck { constraint, false); callerArgList.add(callerArgLoc); } - } - // setup the location list of callee's parameters - MethodDescriptor calleemd = min.getMethod(); - MethodLattice calleeLattice = ssjava.getMethodLattice(calleemd); - CompositeLocation calleeThisLoc = - new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc())); - List calleeParamList = new ArrayList(); - // 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); + if (!calleeMethodDesc.isStatic()) { + CompositeLocation calleeThisLoc = + new CompositeLocation(new Location(calleeMethodDesc, calleeLattice.getThisLoc())); + calleeParamList.add(calleeThisLoc); + } + + for (int i = 0; i < calleeMethodDesc.numParameters(); i++) { + VarDescriptor calleevd = (VarDescriptor) calleeMethodDesc.getParameter(i); + CompositeLocation calleeLoc = d2loc.get(calleevd); + calleeParamList.add(calleeLoc); + } } if (constraint != null) { @@ -977,30 +976,33 @@ public class FlowDownCheck { // annotation that declares the program counter that is higher than // corresponding parameter - CompositeLocation calleePCLOC = - new CompositeLocation(new Location(calleemd, calleeLattice.getPCLoc())); + CompositeLocation calleePCLOC = ssjava.getPCLocation(calleeMethodDesc); for (int idx = 0; idx < callerArgList.size(); idx++) { CompositeLocation argLocation = callerArgList.get(idx); - int compareResult = - CompositeLattice - .compare(constraint, argLocation, true, generateErrorMessage(cd, min)); - // need to check that param is higher than PCLOC - if (compareResult != ComparisonResult.GREATER) { + if (!argLocation.get(0).isTop() + && CompositeLattice.compare(argLocation, constraint, true, + generateErrorMessage(cd, min)) == ComparisonResult.GREATER) { CompositeLocation paramLocation = calleeParamList.get(idx); int paramCompareResult = - CompositeLattice.compare(paramLocation, calleePCLOC, true, + CompositeLattice.compare(calleePCLOC, paramLocation, true, generateErrorMessage(cd, min)); - if (paramCompareResult != ComparisonResult.GREATER) { - throw new Error("The program counter location " + constraint - + " is lower than the argument location " + argLocation - + ". Need to specify that the initial PC location of the callee is lower than " - + paramLocation + ":" + min.getNumLine()); + if (paramCompareResult == ComparisonResult.GREATER) { + throw new Error( + "The program counter location " + + constraint + + " is lower than the argument(idx=" + + idx + + ") location " + + argLocation + + ". Need to specify that the initial PC location of the callee, which is currently set to " + + calleePCLOC + ", is lower than " + paramLocation + " in the method " + + calleeMethodDesc.getSymbol() + ":" + min.getNumLine()); } } @@ -1160,11 +1162,10 @@ public class FlowDownCheck { private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, CompositeLocation callerBaseLoc, CompositeLocation constraint) { - // System.out.println("checkCalleeConstraints=" + min.printNode(0)); - MethodDescriptor calleemd = min.getMethod(); MethodLattice calleeLattice = ssjava.getMethodLattice(calleemd); + CompositeLocation calleeThisLoc = new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc())); @@ -1177,7 +1178,8 @@ public class FlowDownCheck { // setup caller args set // first, add caller's base(this) location - callerArgList.add(callerBaseLoc); + if (!calleemd.isStatic()) + callerArgList.add(callerBaseLoc); // second, add caller's arguments for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); @@ -1189,7 +1191,8 @@ public class FlowDownCheck { // setup callee params set // first, add callee's this location - calleeParamList.add(calleeThisLoc); + if (!calleemd.isStatic()) + calleeParamList.add(calleeThisLoc); // second, add callee's parameters for (int i = 0; i < calleemd.numParameters(); i++) { VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i); @@ -1497,26 +1500,28 @@ public class FlowDownCheck { } } + Set inputGLB = new HashSet(); if (left instanceof ArrayAccessNode) { ArrayAccessNode aan = (ArrayAccessNode) left; - left = aan.getExpression(); + CompositeLocation indexLoc = + checkLocationFromExpressionNode(md, nametable, aan.getIndex(), loc, constraint, false); + inputGLB.add(indexLoc); } loc = checkLocationFromExpressionNode(md, nametable, left, loc, constraint, false); - // System.out.println("### checkLocationFromFieldAccessNode=" + - // fan.printNode(0)); - // System.out.println("### left=" + left.printNode(0)); if (!left.getType().isPrimitive()) { - if (fd.getSymbol().equals("length")) { + if (!fd.getSymbol().equals("length")) { // array.length access, return the location of the array - return loc; + Location fieldLoc = getFieldLocation(fd); + loc.addLocation(fieldLoc); } - Location fieldLoc = getFieldLocation(fd); - loc.addLocation(fieldLoc); } + + inputGLB.add(loc); + loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan)); return loc; } @@ -1561,8 +1566,6 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) { - // System.out.println("\n# ASSIGNMENTNODE=" + an.printNode(0)); - ClassDescriptor cd = md.getClassDesc(); Set inputGLBSet = new HashSet(); @@ -1590,20 +1593,22 @@ public class FlowDownCheck { checkLocationFromExpressionNode(md, nametable, an.getSrc(), new CompositeLocation(), constraint, false); - srcLocation = rhsLocation; + if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) { + // if assignment contains OP+EQ operator, need to merge location types + // of LHS & RHS into the RHS + Set srcGLBSet = new HashSet(); + srcGLBSet.add(rhsLocation); + srcGLBSet.add(destLocation); + srcLocation = CompositeLattice.calculateGLB(srcGLBSet, generateErrorMessage(cd, an)); + } else { + srcLocation = rhsLocation; + } - // if (!rhsLocation.get(rhsLocation.getSize() - 1).isTop()) { if (constraint != null) { - inputGLBSet.add(rhsLocation); + inputGLBSet.add(srcLocation); inputGLBSet.add(constraint); srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an)); } - // } - - // System.out.println("dstLocation=" + destLocation); - // System.out.println("rhsLocation=" + rhsLocation); - // System.out.println("srcLocation=" + srcLocation); - // System.out.println("constraint=" + constraint); if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) { @@ -1641,10 +1646,6 @@ public class FlowDownCheck { srcLocation = rhsLocation; } - // System.out.println("srcLocation=" + srcLocation); - // System.out.println("rhsLocation=" + rhsLocation); - // System.out.println("constraint=" + constraint); - if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) { if (srcLocation.equals(destLocation)) {