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;
import IR.TypeDescriptor;
import IR.TypeExtension;
import IR.VarDescriptor;
+import IR.Flat.FlatNode;
import IR.Tree.ArrayAccessNode;
import IR.Tree.AssignmentNode;
import IR.Tree.BlockExpressionNode;
}
Vector<AnnotationDescriptor> methodAnnotations = md.getModifiers().getAnnotations();
- // second, check return location annotation
- if (!md.getReturnType().isVoid()) {
- CompositeLocation returnLocComp = null;
-
- boolean hasReturnLocDeclaration = false;
- 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);
- hasReturnLocDeclaration = true;
- }
+ CompositeLocation returnLocComp = null;
+
+ boolean hasReturnLocDeclaration = false;
+ 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);
+ hasReturnLocDeclaration = true;
+ } else if (an.getMarker().equals(ssjava.THISLOC)) {
+ String thisLoc = an.getValue();
+ ssjava.getMethodLattice(md).setThisLoc(thisLoc);
}
}
+ }
+ // second, check return location annotation
+ if (!md.getReturnType().isVoid()) {
if (!hasReturnLocDeclaration) {
// if developer does not define method lattice
// search return location in the method default lattice
md2ReturnLoc.put(md, returnLocComp);
- // check this location
+ }
+
+ if (!md.getReturnType().isVoid()) {
MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
String thisLocId = methodLattice.getThisLoc();
- if (thisLocId == null) {
+ if ((!md.isStatic()) && 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);
-
- // System.out.println("### ReturnLocGenerator=" + md);
- // System.out.println("### md2ReturnLoc.get(md)=" + md2ReturnLoc.get(md));
-
md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md
+ " of " + cd.getSourceFileName()));
}
// check 'for loop' case
BlockNode bn = ln.getInitializer();
bn.getVarTable().setParent(nametable);
-
+ // need to check initialization node
+// checkLocationFromBlockNode(md, bn.getVarTable(), bn, constraint);
+ for(int i=0; i<bn.size(); i++) {
+ BlockStatementNode bsn=bn.get(i);
+ checkLocationFromBlockStatementNode(md, bn.getVarTable(),bsn, constraint);
+ }
+
// calculate glb location of condition and update statements
CompositeLocation condLoc =
checkLocationFromExpressionNode(md, bn.getVarTable(), ln.getCondition(),
}
if (!isOwned) {
throw new Error(
- "It is now allowed to create the reference alias from the reference not owned by the method at "
+ "It is not allowed to create the reference alias from the reference not owned by the method at "
+ generateErrorMessage(md.getClassDesc(), tn));
}
private void checkDeclarationInSubBlockNode(MethodDescriptor md, SymbolTable nametable,
SubBlockNode sbn) {
- checkDeclarationInBlockNode(md, nametable.getParent(), sbn.getBlockNode());
+ checkDeclarationInBlockNode(md, nametable, sbn.getBlockNode());
}
private CompositeLocation checkLocationFromBlockExpressionNode(MethodDescriptor md,
SymbolTable nametable, BlockExpressionNode ben, CompositeLocation constraint) {
+
CompositeLocation compLoc =
checkLocationFromExpressionNode(md, nametable, ben.getExpression(), null, constraint, false);
// addTypeLocation(ben.getExpression().getType(), compLoc);
CompositeLocation arrayLoc =
checkLocationFromExpressionNode(md, nametable, aan.getExpression(),
new CompositeLocation(), constraint, isLHS);
+
// addTypeLocation(aan.getExpression().getType(), arrayLoc);
CompositeLocation indexLoc =
checkLocationFromExpressionNode(md, nametable, aan.getIndex(), new CompositeLocation(),
inputSet.add(rightLoc);
CompositeLocation glbCompLoc =
CompositeLattice.calculateGLB(inputSet, generateErrorMessage(cd, on));
- // System.out.println("# glbCompLoc=" + glbCompLoc);
return glbCompLoc;
default:
loc.addLocation(fieldLoc);
} else if (d == null) {
// access static field
- ClassDescriptor cd = nn.getClassDesc();
+ FieldDescriptor fd = nn.getField();
MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
String globalLocId = localLattice.getGlobalLoc();
+ generateErrorMessage(md.getClassDesc(), nn));
}
loc.addLocation(new Location(md, globalLocId));
+
+ Location fieldLoc = (Location) fd.getType().getExtension();
+ loc.addLocation(fieldLoc);
+
return loc;
}
// fan.printNode(0));
// System.out.println("### left=" + left.printNode(0));
- if (left.getType().isArray()) {
- // array.length case: return the location of the array
- return loc;
- } else if (!left.getType().isPrimitive()) {
+ if (!left.getType().isPrimitive()) {
+
+ if (fd.getSymbol().equals("length")) {
+ // array.length access, return the location of the array
+ return loc;
+ }
+
Location fieldLoc = getFieldLocation(fd);
loc.addLocation(fieldLoc);
}
- // System.out.println("### field loc=" + loc);
return loc;
}
+ " at " + cd.getSourceFileName() + "::" + an.getNumLine());
}
+ if (srcLocation.equals(destLocation)) {
+ // keep it for definitely written analysis
+ Set<FlatNode> flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an);
+ for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) {
+ FlatNode fn = (FlatNode) iterator.next();
+ ssjava.addSameHeightWriteFlatNode(fn);
+ }
+
+ }
+
} else {
destLocation =
rhsLocation =
}
+ if (srcLocation.equals(destLocation)) {
+ // keep it for definitely written analysis
+ Set<FlatNode> flatNodeSet = ssjava.getBuildFlat().getFlatNodeSet(an);
+ for (Iterator iterator = flatNodeSet.iterator(); iterator.hasNext();) {
+ FlatNode fn = (FlatNode) iterator.next();
+ ssjava.addSameHeightWriteFlatNode(fn);
+ }
+ }
+
}
return destLocation;