+ /*
+ * private CompositeLocation inferRelationsFromCastNode(MethodDescriptor md,
+ * SymbolTable nametable, CastNode cn, CompositeLocation constraint) {
+ *
+ * ExpressionNode en = cn.getExpression(); return
+ * inferRelationsFromExpressionNode(md, nametable, en, new
+ * CompositeLocation(), constraint, false);
+ *
+ * }
+ *
+ * private CompositeLocation inferRelationsFromTertiaryNode(MethodDescriptor
+ * md, SymbolTable nametable, TertiaryNode tn, CompositeLocation constraint) {
+ * ClassDescriptor cd = md.getClassDesc();
+ *
+ * CompositeLocation condLoc = inferRelationsFromExpressionNode(md, nametable,
+ * tn.getCond(), new CompositeLocation(), constraint, false); //
+ * addLocationType(tn.getCond().getType(), condLoc); CompositeLocation trueLoc
+ * = inferRelationsFromExpressionNode(md, nametable, tn.getTrueExpr(), new
+ * CompositeLocation(), constraint, false); //
+ * addLocationType(tn.getTrueExpr().getType(), trueLoc); CompositeLocation
+ * falseLoc = inferRelationsFromExpressionNode(md, nametable,
+ * tn.getFalseExpr(), new CompositeLocation(), constraint, false); //
+ * addLocationType(tn.getFalseExpr().getType(), falseLoc);
+ *
+ * // locations from true/false branches can be TOP when there are only
+ * literal // values // in this case, we don't need to check flow down rule!
+ *
+ * // check if condLoc is higher than trueLoc & falseLoc if
+ * (!trueLoc.get(0).isTop() && !CompositeLattice.isGreaterThan(condLoc,
+ * trueLoc, generateErrorMessage(cd, tn))) { throw new Error(
+ * "The location of the condition expression is lower than the true expression at "
+ * + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); }
+ *
+ * if (!falseLoc.get(0).isTop() && !CompositeLattice.isGreaterThan(condLoc,
+ * falseLoc, generateErrorMessage(cd, tn.getCond()))) { throw new Error(
+ * "The location of the condition expression is lower than the true expression at "
+ * + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); }
+ *
+ * // then, return glb of trueLoc & falseLoc Set<CompositeLocation>
+ * glbInputSet = new HashSet<CompositeLocation>(); glbInputSet.add(trueLoc);
+ * glbInputSet.add(falseLoc);
+ *
+ * return CompositeLattice.calculateGLB(glbInputSet, generateErrorMessage(cd,
+ * tn)); }
+ *
+ * private CompositeLocation
+ * inferRelationsFromMethodInvokeNode(MethodDescriptor md, SymbolTable
+ * nametable, MethodInvokeNode min, CompositeLocation loc, CompositeLocation
+ * constraint) {
+ *
+ * CompositeLocation baseLocation = null; if (min.getExpression() != null) {
+ * baseLocation = inferRelationsFromExpressionNode(md, nametable,
+ * min.getExpression(), new CompositeLocation(), constraint, false); } else {
+ *
+ * if (min.getMethod().isStatic()) { String globalLocId =
+ * ssjava.getMethodLattice(md).getGlobalLoc(); if (globalLocId == null) {
+ * throw new
+ * Error("Method lattice does not define global variable location at " +
+ * generateErrorMessage(md.getClassDesc(), min)); } baseLocation = new
+ * CompositeLocation(new Location(md, globalLocId)); } else { String thisLocId
+ * = ssjava.getMethodLattice(md).getThisLoc(); baseLocation = new
+ * CompositeLocation(new Location(md, thisLocId)); } }
+ *
+ * checkCalleeConstraints(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 // location in the caller's
+ * perspective CompositeLocation ceilingLoc =
+ * computeCeilingLocationForCaller(md, nametable, min, baseLocation,
+ * constraint); return ceilingLoc; }
+ *
+ * return new CompositeLocation();
+ *
+ * }
+ *
+ * private void checkCallerArgumentLocationConstraints(MethodDescriptor md,
+ * SymbolTable nametable, MethodInvokeNode min, CompositeLocation
+ * callerBaseLoc, CompositeLocation constraint) { // if parameter location
+ * consists of THIS and FIELD location, // caller should pass an argument that
+ * is comparable to the declared // parameter location // and is not lower
+ * than the declared parameter location in the field // lattice.
+ *
+ * MethodDescriptor calleemd = min.getMethod();
+ *
+ * List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
+ * List<CompositeLocation> calleeParamList = new
+ * ArrayList<CompositeLocation>();
+ *
+ * MethodLattice<String> calleeLattice = ssjava.getMethodLattice(calleemd);
+ * Location calleeThisLoc = new Location(calleemd,
+ * calleeLattice.getThisLoc());
+ *
+ * for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en =
+ * min.getArg(i); CompositeLocation callerArgLoc =
+ * inferRelationsFromExpressionNode(md, nametable, en, new
+ * CompositeLocation(), constraint, false); callerArgList.add(callerArgLoc); }
+ *
+ * // setup callee params set for (int i = 0; i < calleemd.numParameters();
+ * i++) { VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
+ * CompositeLocation calleeLoc = d2loc.get(calleevd);
+ * calleeParamList.add(calleeLoc); }
+ *
+ * String errorMsg = generateErrorMessage(md.getClassDesc(), min);
+ *
+ * System.out.println("checkCallerArgumentLocationConstraints=" +
+ * min.printNode(0)); System.out.println("base location=" + callerBaseLoc);
+ *
+ * for (int i = 0; i < calleeParamList.size(); i++) { CompositeLocation
+ * calleeParamLoc = calleeParamList.get(i); if
+ * (calleeParamLoc.get(0).equals(calleeThisLoc) && calleeParamLoc.getSize() >
+ * 1) {
+ *
+ * // callee parameter location has field information CompositeLocation
+ * callerArgLoc = callerArgList.get(i);
+ *
+ * CompositeLocation paramLocation = translateCalleeParamLocToCaller(md,
+ * calleeParamLoc, callerBaseLoc, errorMsg);
+ *
+ * Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>(); if
+ * (constraint != null) { inputGLBSet.add(callerArgLoc);
+ * inputGLBSet.add(constraint); callerArgLoc =
+ * CompositeLattice.calculateGLB(inputGLBSet,
+ * generateErrorMessage(md.getClassDesc(), min)); }
+ *
+ * if (!CompositeLattice.isGreaterThan(callerArgLoc, paramLocation, errorMsg))
+ * { throw new Error("Caller argument '" + min.getArg(i).printNode(0) + " : "
+ * + callerArgLoc +
+ * "' should be higher than corresponding callee's parameter : " +
+ * paramLocation + " at " + errorMsg); }
+ *
+ * } }
+ *
+ * }
+ *
+ * private CompositeLocation translateCalleeParamLocToCaller(MethodDescriptor
+ * md, CompositeLocation calleeParamLoc, CompositeLocation callerBaseLocation,
+ * String errorMsg) {
+ *
+ * CompositeLocation translate = new CompositeLocation();
+ *
+ * for (int i = 0; i < callerBaseLocation.getSize(); i++) {
+ * translate.addLocation(callerBaseLocation.get(i)); }
+ *
+ * for (int i = 1; i < calleeParamLoc.getSize(); i++) {
+ * translate.addLocation(calleeParamLoc.get(i)); }
+ *
+ * System.out.println("TRANSLATED=" + translate + " from calleeParamLoc=" +
+ * calleeParamLoc);
+ *
+ * return translate; }
+ *
+ * private CompositeLocation computeCeilingLocationForCaller(MethodDescriptor
+ * md, SymbolTable nametable, MethodInvokeNode min, CompositeLocation
+ * baseLocation, CompositeLocation constraint) { List<CompositeLocation>
+ * argList = new ArrayList<CompositeLocation>();
+ *
+ * // by default, method has a THIS parameter argList.add(baseLocation);
+ *
+ * for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en =
+ * min.getArg(i); CompositeLocation callerArg =
+ * inferRelationsFromExpressionNode(md, nametable, en, new
+ * CompositeLocation(), constraint, false); argList.add(callerArg); }
+ *
+ * System.out.println("\n## computeReturnLocation=" + min.getMethod() +
+ * " argList=" + argList); CompositeLocation compLoc =
+ * md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList);
+ * DeltaLocation delta = new DeltaLocation(compLoc, 1);
+ * System.out.println("##computeReturnLocation=" + delta);
+ *
+ * return delta;
+ *
+ * }
+ *
+ * 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<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 callerArgLoc = inferRelationsFromExpressionNode(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);
+ * System.out.println("calleevd="+calleevd+" loc="+calleeLoc);
+ * 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; }
+ *
+ * System.out.println("calleeLoc1="+calleeLoc1);
+ * System.out.println("calleeLoc2="
+ * +calleeLoc2+"calleeParamList="+calleeParamList);
+ *
+ * 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) + "'"; }
+ *
+ * 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()); }
+ * }
+ *
+ * } }
+ *
+ * }
+ *
+ * }
+ *
+ * private CompositeLocation
+ * inferRelationsFromArrayAccessNode(MethodDescriptor md, SymbolTable
+ * nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean
+ * isLHS) {
+ *
+ * ClassDescriptor cd = md.getClassDesc();
+ *
+ * CompositeLocation arrayLoc = inferRelationsFromExpressionNode(md,
+ * nametable, aan.getExpression(), new CompositeLocation(), constraint,
+ * isLHS); // addTypeLocation(aan.getExpression().getType(), arrayLoc);
+ * CompositeLocation indexLoc = inferRelationsFromExpressionNode(md,
+ * nametable, aan.getIndex(), new CompositeLocation(), constraint, isLHS); //
+ * addTypeLocation(aan.getIndex().getType(), indexLoc);
+ *
+ * if (isLHS) { if (!CompositeLattice.isGreaterThan(indexLoc, arrayLoc,
+ * generateErrorMessage(cd, aan))) { throw new
+ * Error("Array index value is not higher than array location at " +
+ * generateErrorMessage(cd, aan)); } return arrayLoc; } else {
+ * Set<CompositeLocation> inputGLB = new HashSet<CompositeLocation>();
+ * inputGLB.add(arrayLoc); inputGLB.add(indexLoc); return
+ * CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(cd, aan)); }
+ *
+ * }
+ *
+ * private CompositeLocation
+ * inferRelationsFromCreateObjectNode(MethodDescriptor md, SymbolTable
+ * nametable, CreateObjectNode con) {
+ *
+ * ClassDescriptor cd = md.getClassDesc();
+ *
+ * CompositeLocation compLoc = new CompositeLocation();
+ * compLoc.addLocation(Location.createTopLocation(md)); return compLoc;
+ *
+ * }
+ */
+ private VarID inferRelationsFromOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,
+ VarID flowTo, BlockStatementNode implicitTag) {