From 3a53b44ad7d4e38376af04573dcfa7ddd596d96a Mon Sep 17 00:00:00 2001 From: yeom Date: Fri, 22 Apr 2011 01:08:26 +0000 Subject: [PATCH] changes: make location an extension of type descriptor and have an additional mapping from Flatnode to labeled statement. Note that the labeled statement might be handled differently when Sonny implements continue/break with labels --- .../Analysis/SSJava/CompositeLocation.java | 8 +- .../SSJava/DefinitelyWrittenCheck.java | 116 +++++++---- Robust/src/Analysis/SSJava/FlowDownCheck.java | 183 ++++++++++-------- Robust/src/Analysis/SSJava/Location.java | 3 +- .../src/Analysis/SSJava/SSJavaAnalysis.java | 11 +- Robust/src/IR/Flat/BuildFlat.java | 4 + Robust/src/IR/State.java | 2 + 7 files changed, 194 insertions(+), 133 deletions(-) diff --git a/Robust/src/Analysis/SSJava/CompositeLocation.java b/Robust/src/Analysis/SSJava/CompositeLocation.java index b9eb5f86..1f9c6a6e 100644 --- a/Robust/src/Analysis/SSJava/CompositeLocation.java +++ b/Robust/src/Analysis/SSJava/CompositeLocation.java @@ -8,7 +8,7 @@ import java.util.Set; import IR.ClassDescriptor; -public class CompositeLocation extends Location { +public class CompositeLocation extends Location{ protected NTuple locTuple; @@ -72,9 +72,9 @@ public class CompositeLocation extends Location { return cd2loc; } - + public NTuple getBaseLocationTuple() { - + NTuple baseLocationTuple = new NTuple(); int tupleSize = locTuple.size(); for (int i = 0; i < tupleSize; i++) { @@ -89,7 +89,7 @@ public class CompositeLocation extends Location { } } return baseLocationTuple; - + } public Set getBaseLocationSet() { diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 8f743a8a..bd7ed906 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -8,17 +8,20 @@ import java.util.Set; import Analysis.Loops.LoopFinder; import Analysis.Loops.Loops; import IR.ClassDescriptor; +import IR.Descriptor; import IR.FieldDescriptor; import IR.MethodDescriptor; import IR.Operation; import IR.State; import IR.SymbolTable; +import IR.VarDescriptor; import IR.Flat.FKind; import IR.Flat.FlatFieldNode; import IR.Flat.FlatLiteralNode; import IR.Flat.FlatMethod; import IR.Flat.FlatNode; import IR.Flat.FlatOpNode; +import IR.Flat.FlatSetFieldNode; import IR.Flat.TempDescriptor; public class DefinitelyWrittenCheck { @@ -26,14 +29,13 @@ public class DefinitelyWrittenCheck { static State state; HashSet toanalyze; - // maintains analysis results in the form of > - private Hashtable>> definitelyWrittenResults; + private Hashtable>> definitelyWrittenResults; public DefinitelyWrittenCheck(State state) { this.state = state; this.toanalyze = new HashSet(); this.definitelyWrittenResults = - new Hashtable>>(); + new Hashtable>>(); } public void definitelyWrittenCheck() { @@ -46,26 +48,34 @@ public class DefinitelyWrittenCheck { Object obj = toanalyze.iterator().next(); ClassDescriptor cd = (ClassDescriptor) obj; toanalyze.remove(cd); + if (cd.isClassLibrary()) { // doesn't care about class libraries now - continue; +// continue; } for (Iterator method_it = cd.getMethods(); method_it.hasNext();) { MethodDescriptor md = (MethodDescriptor) method_it.next(); FlatMethod fm = state.getMethodFlat(md); - - LoopFinder loopFinder = new LoopFinder(fm); - Loops loops = loopFinder.getRootloop(fm); - Set loopSet = loops.nestedLoops(); - - for (Iterator iterator = loopSet.iterator(); iterator.hasNext();) { - Loops rootLoops = (Loops) iterator.next(); - Set loopEntranceSet = rootLoops.loopEntrances(); - for (Iterator iterator2 = loopEntranceSet.iterator(); iterator2.hasNext();) { - FlatNode loopEnter = (FlatNode) iterator2.next(); - definitelyWrittenForward(loopEnter); + if(fm!=null){ + LoopFinder loopFinder = new LoopFinder(fm); + Loops loops = loopFinder.getRootloop(fm); + Set loopSet = loops.nestedLoops(); + + for (Iterator iterator = loopSet.iterator(); iterator.hasNext();) { + Loops rootLoops = (Loops) iterator.next(); + Set loopEntranceSet = rootLoops.loopEntrances(); + for (Iterator iterator2 = loopEntranceSet.iterator(); iterator2.hasNext();) { + FlatNode loopEnter = (FlatNode) iterator2.next(); + + String flatNodeLabel = (String) state.fn2labelMap.get(loopEnter); + if (flatNodeLabel != null && flatNodeLabel.equals("ssjava")) { + System.out.println("encounting ss loop:" + loopEnter); + definitelyWrittenForward(loopEnter); + } + } } } + } } @@ -133,12 +143,12 @@ public class DefinitelyWrittenCheck { lhs = fon.getDest(); rhs = fon.getLeft(); // read(rhs) - Hashtable> map = - definitelyWrittenResults.get(fn); + Hashtable> map = definitelyWrittenResults.get(fn); if (map != null) { if (map.get(rhs).get(fn).booleanValue()) { - throw new Error("variable " + rhs - + " was not overwritten in-between the same read statement by the out-most loop."); + // throw new Error("variable " + rhs + // + + // " was not overwritten in-between the same read statement by the out-most loop."); } } @@ -189,15 +199,13 @@ public class DefinitelyWrittenCheck { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove(fn); - Hashtable> prev = - definitelyWrittenResults.get(fn); + Hashtable> prev = definitelyWrittenResults.get(fn); - Hashtable> curr = - new Hashtable>(); + Hashtable> curr = + new Hashtable>(); for (int i = 0; i < fn.numPrev(); i++) { FlatNode nn = fn.getPrev(i); - Hashtable> dwIn = - definitelyWrittenResults.get(nn); + Hashtable> dwIn = definitelyWrittenResults.get(nn); if (dwIn != null) { mergeResults(curr, dwIn); } @@ -217,12 +225,12 @@ public class DefinitelyWrittenCheck { } } - private void mergeResults(Hashtable> curr, - Hashtable> in) { + private void mergeResults(Hashtable> curr, + Hashtable> in) { - Set inKeySet = in.keySet(); + Set inKeySet = in.keySet(); for (Iterator iterator = inKeySet.iterator(); iterator.hasNext();) { - TempDescriptor inKey = (TempDescriptor) iterator.next(); + Descriptor inKey = (Descriptor) iterator.next(); Hashtable inPair = in.get(inKey); Set pairKeySet = inPair.keySet(); @@ -250,13 +258,13 @@ public class DefinitelyWrittenCheck { } private void definitelyWritten_nodeActions(FlatNode fn, - Hashtable> curr, FlatNode entrance) { + Hashtable> curr, FlatNode entrance) { if (fn == entrance) { - Set keySet = curr.keySet(); + Set keySet = curr.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - TempDescriptor key = (TempDescriptor) iterator.next(); + Descriptor key = (Descriptor) iterator.next(); Hashtable pair = curr.get(key); if (pair != null) { Set pairKeySet = pair.keySet(); @@ -278,8 +286,10 @@ public class DefinitelyWrittenCheck { FlatOpNode fon = (FlatOpNode) fn; lhs = fon.getDest(); + rhs = fon.getLeft(); + System.out.println("\nfon=" + fon); + if (fon.getOp().getOp() == Operation.ASSIGN) { - rhs = fon.getLeft(); // read(rhs) Hashtable gen = curr.get(rhs); @@ -287,6 +297,7 @@ public class DefinitelyWrittenCheck { gen = new Hashtable(); curr.put(rhs, gen); } + System.out.println("READ LOC=" + rhs.getType().getExtension()); Boolean currentStatus = gen.get(fn); if (currentStatus == null) { @@ -295,6 +306,7 @@ public class DefinitelyWrittenCheck { } // write(lhs) curr.put(lhs, new Hashtable()); + System.out.println("WRITING LOC=" + lhs.getType().getExtension()); } break; @@ -306,30 +318,48 @@ public class DefinitelyWrittenCheck { // write(lhs) curr.put(lhs, new Hashtable()); + System.out.println("WRITING LOC=" + lhs.getType().getExtension()); + } break; - case FKind.FlatFieldNode: { + case FKind.FlatFieldNode: + case FKind.FlatElementNode: { FlatFieldNode ffn = (FlatFieldNode) fn; - lhs = ffn.getDst(); - rhs = ffn.getSrc(); + lhs = ffn.getSrc(); fld = ffn.getField(); - } - break; - - case FKind.FlatElementNode: { + // read field + Hashtable gen = curr.get(fld); + if (gen == null) { + gen = new Hashtable(); + curr.put(fld, gen); + } + Boolean currentStatus = gen.get(fn); + if (currentStatus == null) { + gen.put(fn, Boolean.FALSE); + } - } - break; + System.out.println("\nffn=" + ffn); + System.out.println("READ LOCfld=" + fld.getType().getExtension()); + System.out.println("READ LOClhs=" + lhs.getType().getExtension()); - case FKind.FlatSetFieldNode: { } break; + case FKind.FlatSetFieldNode: case FKind.FlatSetElementNode: { + FlatSetFieldNode fsfn = (FlatSetFieldNode) fn; + fld = fsfn.getField(); + + // write(field) + curr.put(fld, new Hashtable()); + + System.out.println("\nfsfn=" + fsfn); + System.out.println("WRITELOC LOC=" + fld.getType().getExtension()); + } break; diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 6b5faa2c..ffee22f2 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -20,7 +20,6 @@ import IR.SymbolTable; import IR.TypeDescriptor; import IR.VarDescriptor; import IR.Tree.ArrayAccessNode; -import IR.Tree.ArrayInitializerNode; import IR.Tree.AssignmentNode; import IR.Tree.BlockExpressionNode; import IR.Tree.BlockNode; @@ -160,6 +159,10 @@ public class FlowDownCheck { } + public Hashtable getMap() { + return td2loc; + } + private void checkDeclarationInMethodBody(ClassDescriptor cd, MethodDescriptor md) { BlockNode bn = state.getMethodBody(md); for (int i = 0; i < md.numParameters(); i++) { @@ -237,32 +240,38 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromBlockStatementNode(MethodDescriptor md, SymbolTable nametable, BlockStatementNode bsn) { + CompositeLocation compLoc = null; switch (bsn.kind()) { case Kind.BlockExpressionNode: - return checkLocationFromBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn); + compLoc = checkLocationFromBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn); + break; case Kind.DeclarationNode: - return checkLocationFromDeclarationNode(md, nametable, (DeclarationNode) bsn); + compLoc = checkLocationFromDeclarationNode(md, nametable, (DeclarationNode) bsn); + break; case Kind.IfStatementNode: - return checkLocationFromIfStatementNode(md, nametable, (IfStatementNode) bsn); + compLoc = checkLocationFromIfStatementNode(md, nametable, (IfStatementNode) bsn); + break; case Kind.LoopNode: - return checkLocationFromLoopNode(md, nametable, (LoopNode) bsn); + compLoc = checkLocationFromLoopNode(md, nametable, (LoopNode) bsn); + break; case Kind.ReturnNode: // checkLocationFromReturnNode(md, nametable, (ReturnNode) bsn); return null; case Kind.SubBlockNode: - return checkLocationFromSubBlockNode(md, nametable, (SubBlockNode) bsn); + compLoc = checkLocationFromSubBlockNode(md, nametable, (SubBlockNode) bsn); + break; - // case Kind.ContinueBreakNode: - // checkLocationFromContinueBreakNode(md, nametable,(ContinueBreakNode) - // bsn); - // return null; + // case Kind.ContinueBreakNode: + // checkLocationFromContinueBreakNode(md, nametable,(ContinueBreakNode) + // bsn); + // return null; } - return null; + return compLoc; } private CompositeLocation checkLocationFromLoopNode(MethodDescriptor md, SymbolTable nametable, @@ -274,6 +283,8 @@ public class FlowDownCheck { CompositeLocation condLoc = checkLocationFromExpressionNode(md, nametable, ln.getCondition(), new CompositeLocation( cd)); + addTypeLocation(ln.getCondition().getType(), (condLoc)); + CompositeLocation bodyLoc = checkLocationFromBlockNode(md, nametable, ln.getBody()); if (!CompositeLattice.isGreaterThan(condLoc, bodyLoc, cd)) { @@ -293,6 +304,8 @@ public class FlowDownCheck { CompositeLocation condLoc = checkLocationFromExpressionNode(md, bn.getVarTable(), ln.getCondition(), new CompositeLocation(cd)); + addTypeLocation(ln.getCondition().getType(), condLoc); + CompositeLocation updateLoc = checkLocationFromBlockNode(md, bn.getVarTable(), ln.getUpdate()); @@ -320,7 +333,8 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromSubBlockNode(MethodDescriptor md, SymbolTable nametable, SubBlockNode sbn) { - return checkLocationFromBlockNode(md, nametable, sbn.getBlockNode()); + CompositeLocation compLoc = checkLocationFromBlockNode(md, nametable, sbn.getBlockNode()); + return compLoc; } private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md, @@ -329,8 +343,10 @@ public class FlowDownCheck { ClassDescriptor localCD = md.getClassDesc(); Set glbInputSet = new HashSet(); - CompositeLocation condLoc = new CompositeLocation(localCD); - condLoc = checkLocationFromExpressionNode(md, nametable, isn.getCondition(), condLoc); + CompositeLocation condLoc = + checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation( + localCD)); + addTypeLocation(isn.getCondition().getType(), condLoc); glbInputSet.add(condLoc); CompositeLocation locTrueBlock = checkLocationFromBlockNode(md, nametable, isn.getTrueBlock()); @@ -350,7 +366,6 @@ public class FlowDownCheck { CompositeLocation locFalseBlock = checkLocationFromBlockNode(md, nametable, isn.getFalseBlock()); glbInputSet.add(locFalseBlock); - System.out.println(isn.getFalseBlock().printNode(0) + ":::falseLoc=" + locFalseBlock); if (!CompositeLattice.isGreaterThan(condLoc, locFalseBlock, localCD)) { // error @@ -375,9 +390,10 @@ public class FlowDownCheck { ClassDescriptor localCD = md.getClassDesc(); if (dn.getExpression() != null) { - CompositeLocation expressionLoc = new CompositeLocation(localCD); - expressionLoc = - checkLocationFromExpressionNode(md, nametable, dn.getExpression(), expressionLoc); + CompositeLocation expressionLoc = + checkLocationFromExpressionNode(md, nametable, dn.getExpression(), new CompositeLocation( + localCD)); + addTypeLocation(dn.getExpression().getType(), expressionLoc); if (expressionLoc != null) { // checking location order @@ -401,63 +417,79 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromBlockExpressionNode(MethodDescriptor md, SymbolTable nametable, BlockExpressionNode ben) { - return checkLocationFromExpressionNode(md, nametable, ben.getExpression(), null); + CompositeLocation compLoc = + checkLocationFromExpressionNode(md, nametable, ben.getExpression(), null); + addTypeLocation(ben.getExpression().getType(), compLoc); + return compLoc; } private CompositeLocation checkLocationFromExpressionNode(MethodDescriptor md, SymbolTable nametable, ExpressionNode en, CompositeLocation loc) { + CompositeLocation compLoc = null; switch (en.kind()) { case Kind.AssignmentNode: - return checkLocationFromAssignmentNode(md, nametable, (AssignmentNode) en, loc); + compLoc = checkLocationFromAssignmentNode(md, nametable, (AssignmentNode) en, loc); + break; case Kind.FieldAccessNode: - return checkLocationFromFieldAccessNode(md, nametable, (FieldAccessNode) en, loc); + compLoc = checkLocationFromFieldAccessNode(md, nametable, (FieldAccessNode) en, loc); + break; case Kind.NameNode: - return checkLocationFromNameNode(md, nametable, (NameNode) en, loc); + compLoc = checkLocationFromNameNode(md, nametable, (NameNode) en, loc); + break; case Kind.OpNode: - return checkLocationFromOpNode(md, nametable, (OpNode) en); + compLoc = checkLocationFromOpNode(md, nametable, (OpNode) en); + break; case Kind.CreateObjectNode: - return checkLocationFromCreateObjectNode(md, nametable, (CreateObjectNode) en); + compLoc = checkLocationFromCreateObjectNode(md, nametable, (CreateObjectNode) en); + break; case Kind.ArrayAccessNode: - return checkLocationFromArrayAccessNode(md, nametable, (ArrayAccessNode) en); + compLoc = checkLocationFromArrayAccessNode(md, nametable, (ArrayAccessNode) en); + break; case Kind.LiteralNode: - return checkLocationFromLiteralNode(md, nametable, (LiteralNode) en, loc); + compLoc = checkLocationFromLiteralNode(md, nametable, (LiteralNode) en, loc); + break; case Kind.MethodInvokeNode: - return checkLocationFromMethodInvokeNode(md, nametable, (MethodInvokeNode) en); + compLoc = checkLocationFromMethodInvokeNode(md, nametable, (MethodInvokeNode) en); + break; case Kind.TertiaryNode: - return checkLocationFromTertiaryNode(md, nametable, (TertiaryNode) en); + compLoc = checkLocationFromTertiaryNode(md, nametable, (TertiaryNode) en); + break; - // case Kind.InstanceOfNode: - // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td); - // return null; + // case Kind.InstanceOfNode: + // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td); + // return null; - // case Kind.ArrayInitializerNode: - // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en, - // td); - // return null; + // case Kind.ArrayInitializerNode: + // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en, + // td); + // return null; - // case Kind.ClassTypeNode: - // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td); - // return null; + // case Kind.ClassTypeNode: + // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td); + // return null; - // case Kind.OffsetNode: - // checkOffsetNode(md, nametable, (OffsetNode)en, td); - // return null; + // case Kind.OffsetNode: + // checkOffsetNode(md, nametable, (OffsetNode)en, td); + // return null; default: return null; } + addTypeLocation(en.getType(), compLoc); + return compLoc; + } private CompositeLocation checkLocationFromTertiaryNode(MethodDescriptor md, @@ -466,10 +498,13 @@ public class FlowDownCheck { CompositeLocation condLoc = checkLocationFromExpressionNode(md, nametable, tn.getCond(), new CompositeLocation(cd)); + addTypeLocation(tn.getCond().getType(), condLoc); CompositeLocation trueLoc = checkLocationFromExpressionNode(md, nametable, tn.getTrueExpr(), new CompositeLocation(cd)); + addTypeLocation(tn.getTrueExpr().getType(), trueLoc); CompositeLocation falseLoc = checkLocationFromExpressionNode(md, nametable, tn.getFalseExpr(), new CompositeLocation(cd)); + addTypeLocation(tn.getFalseExpr().getType(), falseLoc); // check if condLoc is higher than trueLoc & falseLoc if (!CompositeLattice.isGreaterThan(condLoc, trueLoc, cd)) { @@ -525,7 +560,7 @@ public class FlowDownCheck { boolean callerResult = CompositeLattice.isGreaterThan(callerArg1, callerArg2, cd); boolean calleeResult = CompositeLattice.isGreaterThan(calleeLoc1, calleeLoc2, calleecd); - + if (calleeResult && !callerResult) { // in callee, calleeLoc1 is higher than calleeLoc2 // then, caller should have same ordering relation in-bet @@ -551,6 +586,7 @@ public class FlowDownCheck { ExpressionNode en = min.getArg(i); CompositeLocation argLoc = checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation(cd)); + addTypeLocation(en.getType(), argLoc); argLocSet.add(argLoc); } @@ -577,11 +613,13 @@ public class FlowDownCheck { CompositeLocation arrayLoc = checkLocationFromExpressionNode(md, nametable, aan.getExpression(), new CompositeLocation( cd)); + addTypeLocation(aan.getExpression().getType(), arrayLoc); glbInputSet.add(arrayLoc); CompositeLocation indexLoc = checkLocationFromExpressionNode(md, nametable, aan.getIndex(), new CompositeLocation(cd)); glbInputSet.add(indexLoc); + addTypeLocation(aan.getIndex().getType(), indexLoc); CompositeLocation glbLoc = CompositeLattice.calculateGLB(cd, glbInputSet, cd); return glbLoc; @@ -599,6 +637,7 @@ public class FlowDownCheck { CompositeLocation argLoc = checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation(cd)); glbInputSet.add(argLoc); + addTypeLocation(en.getType(), argLoc); } // check array initializers @@ -617,30 +656,18 @@ public class FlowDownCheck { } - private CompositeLocation checkLocationFromArrayInitializerNode(MethodDescriptor md, - SymbolTable nametable, ArrayInitializerNode ain) { - - ClassDescriptor cd = md.getClassDesc(); - Vector vec_type = new Vector(); - for (int i = 0; i < ain.numVarInitializers(); ++i) { - checkLocationFromExpressionNode(md, nametable, ain.getVarInitializer(i), - new CompositeLocation(cd)); - vec_type.add(ain.getVarInitializer(i).getType()); - } - - return null; - } - private CompositeLocation checkLocationFromOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on) { ClassDescriptor cd = md.getClassDesc(); CompositeLocation leftLoc = new CompositeLocation(cd); leftLoc = checkLocationFromExpressionNode(md, nametable, on.getLeft(), leftLoc); + addTypeLocation(on.getLeft().getType(), leftLoc); CompositeLocation rightLoc = new CompositeLocation(cd); if (on.getRight() != null) { rightLoc = checkLocationFromExpressionNode(md, nametable, on.getRight(), rightLoc); + addTypeLocation(on.getRight().getType(), rightLoc); } System.out.println("checking op node=" + on.printNode(0)); @@ -711,6 +738,7 @@ public class FlowDownCheck { NameDescriptor nd = nn.getName(); if (nd.getBase() != null) { loc = checkLocationFromExpressionNode(md, nametable, nn.getExpression(), loc); + addTypeLocation(nn.getExpression().getType(), loc); } else { String varname = nd.toString(); @@ -738,17 +766,19 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromFieldAccessNode(MethodDescriptor md, SymbolTable nametable, FieldAccessNode fan, CompositeLocation loc) { + FieldDescriptor fd = fan.getField(); Location fieldLoc = td2loc.get(fd); loc.addLocation(fieldLoc); ExpressionNode left = fan.getExpression(); - return checkLocationFromExpressionNode(md, nametable, left, loc); + CompositeLocation compLoc = checkLocationFromExpressionNode(md, nametable, left, loc); + addTypeLocation(left.getType(), compLoc); + return compLoc; } private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, CompositeLocation loc) { - ClassDescriptor cd = md.getClassDesc(); boolean postinc = true; @@ -780,34 +810,12 @@ public class FlowDownCheck { } } + addTypeLocation(an.getSrc().getType(), srcLocation); + addTypeLocation(an.getDest().getType(), destLocation); return destLocation; } - private Location createCompositeLocation(FieldAccessNode fan, Location loc) { - - FieldDescriptor field = fan.getField(); - ClassDescriptor fieldCD = field.getClassDescriptor(); - - assert (field.getType().getAnnotationMarkers().size() == 1); - - AnnotationDescriptor locAnnotation = field.getType().getAnnotationMarkers().elementAt(0); - if (locAnnotation.getType() == AnnotationDescriptor.SINGLE_ANNOTATION) { - // single location - - } else { - // delta location - } - - // Location localLoc=new Location(field.getClassDescriptor(),field.get) - - // System.out.println("creatingComposite's field="+field+" localLoc="+localLoc); - ExpressionNode leftNode = fan.getExpression(); - System.out.println("creatingComposite's leftnode=" + leftNode.printNode(0)); - - return loc; - } - private void assignLocationOfVarDescriptor(VarDescriptor vd, MethodDescriptor md, SymbolTable nametable, TreeNode n) { @@ -840,6 +848,7 @@ public class FlowDownCheck { Location loc = new Location(cd, locationID); td2loc.put(vd, loc); + addTypeLocation(vd.getType(), loc); } else if (ad.getType() == AnnotationDescriptor.SINGLE_ANNOTATION) { if (ad.getMarker().equals(SSJavaAnalysis.DELTA)) { @@ -893,7 +902,7 @@ public class FlowDownCheck { } td2loc.put(vd, compLoc); - System.out.println("vd=" + vd + " is assigned by " + compLoc); + addTypeLocation(vd.getType(), compLoc); } } @@ -954,6 +963,7 @@ public class FlowDownCheck { Location localLoc = new Location(cd, locationID); td2loc.put(fd, localLoc); + addTypeLocation(fd.getType(), localLoc); } else if (ad.getType() == AnnotationDescriptor.SINGLE_ANNOTATION) { if (ad.getMarker().equals(SSJavaAnalysis.DELTA)) { @@ -981,12 +991,19 @@ public class FlowDownCheck { } compLoc.addLocation(deltaLoc); td2loc.put(fd, compLoc); + addTypeLocation(fd.getType(), compLoc); } } } + private void addTypeLocation(TypeDescriptor type, Location loc) { + if (type != null) { + type.setExtension(loc); + } + } + static class CompositeLattice { public static boolean isGreaterThan(Location loc1, Location loc2, ClassDescriptor priorityCD) { diff --git a/Robust/src/Analysis/SSJava/Location.java b/Robust/src/Analysis/SSJava/Location.java index 741b4448..7f04ce9a 100644 --- a/Robust/src/Analysis/SSJava/Location.java +++ b/Robust/src/Analysis/SSJava/Location.java @@ -1,8 +1,9 @@ package Analysis.SSJava; import IR.ClassDescriptor; +import IR.TypeExtension; -public class Location { +public class Location implements TypeExtension { public static final int TOP = 1; public static final int NORMAL = 2; diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index 05796ea4..6206b147 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -1,14 +1,21 @@ package Analysis.SSJava; +import java.util.Hashtable; + import IR.State; +import IR.Flat.TempDescriptor; +import IR.Tree.TreeNode; public class SSJavaAnalysis { public static final String DELTA = "delta"; State state; + FlowDownCheck flowDownChecker; + Hashtable td2Loc; public SSJavaAnalysis(State state) { this.state = state; + this.td2Loc = new Hashtable(); } public void doCheck() { @@ -17,8 +24,8 @@ public class SSJavaAnalysis { } public void doFlowDownCheck() { - FlowDownCheck checker = new FlowDownCheck(state); - checker.flowDownCheck(); + flowDownChecker = new FlowDownCheck(state); + flowDownChecker.flowDownCheck(); } public void doLoopCheck() { diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index db932b10..789c2e45 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -299,6 +299,10 @@ public class BuildFlat { NodePair np=flattenBlockStatementNode(bn.get(i)); FlatNode np_begin=np.getBegin(); FlatNode np_end=np.getEnd(); + if(bn.getLabel()!=null){ + // interim implementation to have the labeled statement + state.fn2labelMap.put(np_begin, bn.getLabel()); + } if (begin==null) { begin=np_begin; } diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index 303d3e39..cd46ba60 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -41,6 +41,7 @@ public class State { this.classpath=new Vector(); this.cd2locationOrderMap=new Hashtable(); this.cd2locationPropertyMap=new Hashtable(); + this.fn2labelMap=new Hashtable(); this.lines=0; } @@ -209,6 +210,7 @@ public class State { private int arraycount=0; public Hashtable cd2locationOrderMap; public Hashtable cd2locationPropertyMap; + public Hashtable fn2labelMap; public boolean OPTIMIZE=false; public boolean LINENUM=false; -- 2.34.1