3edbd818ce63d00d942e194ea5b0396d52d32712
[IRC.git] / Robust / src / Analysis / SSJava / FlowDownCheck.java
1 package Analysis.SSJava;
2
3 import java.util.ArrayList;
4 import java.util.HashSet;
5 import java.util.Hashtable;
6 import java.util.Iterator;
7 import java.util.List;
8 import java.util.Set;
9 import java.util.StringTokenizer;
10 import java.util.Vector;
11
12 import IR.AnnotationDescriptor;
13 import IR.ClassDescriptor;
14 import IR.Descriptor;
15 import IR.FieldDescriptor;
16 import IR.MethodDescriptor;
17 import IR.NameDescriptor;
18 import IR.Operation;
19 import IR.State;
20 import IR.SymbolTable;
21 import IR.TypeDescriptor;
22 import IR.VarDescriptor;
23 import IR.Tree.ArrayAccessNode;
24 import IR.Tree.AssignmentNode;
25 import IR.Tree.BlockExpressionNode;
26 import IR.Tree.BlockNode;
27 import IR.Tree.BlockStatementNode;
28 import IR.Tree.CastNode;
29 import IR.Tree.CreateObjectNode;
30 import IR.Tree.DeclarationNode;
31 import IR.Tree.ExpressionNode;
32 import IR.Tree.FieldAccessNode;
33 import IR.Tree.IfStatementNode;
34 import IR.Tree.Kind;
35 import IR.Tree.LiteralNode;
36 import IR.Tree.LoopNode;
37 import IR.Tree.MethodInvokeNode;
38 import IR.Tree.NameNode;
39 import IR.Tree.OpNode;
40 import IR.Tree.ReturnNode;
41 import IR.Tree.SubBlockNode;
42 import IR.Tree.TertiaryNode;
43 import IR.Tree.TreeNode;
44
45 public class FlowDownCheck {
46
47   static State state;
48   static SSJavaAnalysis ssjava;
49
50   HashSet toanalyze;
51
52   // mapping from 'descriptor' to 'composite location'
53   Hashtable<Descriptor, CompositeLocation> d2loc;
54
55   // mapping from 'locID' to 'class descriptor'
56   Hashtable<String, ClassDescriptor> fieldLocName2cd;
57
58   public FlowDownCheck(SSJavaAnalysis ssjava, State state) {
59     this.ssjava = ssjava;
60     this.state = state;
61     this.toanalyze = new HashSet();
62     this.d2loc = new Hashtable<Descriptor, CompositeLocation>();
63     this.fieldLocName2cd = new Hashtable<String, ClassDescriptor>();
64     init();
65   }
66
67   public void init() {
68
69     // construct mapping from the location name to the class descriptor
70     // assume that the location name is unique through the whole program
71
72     Set<ClassDescriptor> cdSet = ssjava.getCd2lattice().keySet();
73     for (Iterator iterator = cdSet.iterator(); iterator.hasNext();) {
74       ClassDescriptor cd = (ClassDescriptor) iterator.next();
75       SSJavaLattice<String> lattice = ssjava.getCd2lattice().get(cd);
76       Set<String> fieldLocNameSet = lattice.getKeySet();
77
78       for (Iterator iterator2 = fieldLocNameSet.iterator(); iterator2.hasNext();) {
79         String fieldLocName = (String) iterator2.next();
80         fieldLocName2cd.put(fieldLocName, cd);
81       }
82
83     }
84
85   }
86
87   public void flowDownCheck() {
88     SymbolTable classtable = state.getClassSymbolTable();
89
90     // phase 1 : checking declaration node and creating mapping of 'type
91     // desciptor' & 'location'
92     toanalyze.addAll(classtable.getValueSet());
93     toanalyze.addAll(state.getTaskSymbolTable().getValueSet());
94     while (!toanalyze.isEmpty()) {
95       Object obj = toanalyze.iterator().next();
96       ClassDescriptor cd = (ClassDescriptor) obj;
97       toanalyze.remove(cd);
98
99       if (!cd.isInterface()) {
100         checkDeclarationInClass(cd);
101         for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
102           MethodDescriptor md = (MethodDescriptor) method_it.next();
103           try {
104             checkDeclarationInMethodBody(cd, md);
105           } catch (Error e) {
106             System.out.println("Error in " + md);
107             throw e;
108           }
109         }
110       }
111
112     }
113
114     // phase2 : checking assignments
115     toanalyze.addAll(classtable.getValueSet());
116     toanalyze.addAll(state.getTaskSymbolTable().getValueSet());
117     while (!toanalyze.isEmpty()) {
118       Object obj = toanalyze.iterator().next();
119       ClassDescriptor cd = (ClassDescriptor) obj;
120       toanalyze.remove(cd);
121
122       checkClass(cd);
123       for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
124         MethodDescriptor md = (MethodDescriptor) method_it.next();
125         try {
126           checkMethodBody(cd, md);
127         } catch (Error e) {
128           System.out.println("Error in " + md);
129           throw e;
130         }
131       }
132     }
133
134   }
135
136   public Hashtable getMap() {
137     return d2loc;
138   }
139
140   private void checkDeclarationInMethodBody(ClassDescriptor cd, MethodDescriptor md) {
141     BlockNode bn = state.getMethodBody(md);
142     for (int i = 0; i < md.numParameters(); i++) {
143       // process annotations on method parameters
144       VarDescriptor vd = (VarDescriptor) md.getParameter(i);
145       assignLocationOfVarDescriptor(vd, md, md.getParameterTable(), bn);
146     }
147     checkDeclarationInBlockNode(md, md.getParameterTable(), bn);
148   }
149
150   private void checkDeclarationInBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn) {
151     bn.getVarTable().setParent(nametable);
152     for (int i = 0; i < bn.size(); i++) {
153       BlockStatementNode bsn = bn.get(i);
154       checkDeclarationInBlockStatementNode(md, bn.getVarTable(), bsn);
155     }
156   }
157
158   private void checkDeclarationInBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
159       BlockStatementNode bsn) {
160
161     switch (bsn.kind()) {
162     case Kind.SubBlockNode:
163       checkDeclarationInSubBlockNode(md, nametable, (SubBlockNode) bsn);
164       return;
165
166     case Kind.DeclarationNode:
167       checkDeclarationNode(md, nametable, (DeclarationNode) bsn);
168       break;
169
170     case Kind.LoopNode:
171       checkDeclarationInLoopNode(md, nametable, (LoopNode) bsn);
172       break;
173     }
174   }
175
176   private void checkDeclarationInLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln) {
177
178     if (ln.getType() == LoopNode.FORLOOP) {
179       // check for loop case
180       ClassDescriptor cd = md.getClassDesc();
181       BlockNode bn = ln.getInitializer();
182       for (int i = 0; i < bn.size(); i++) {
183         BlockStatementNode bsn = bn.get(i);
184         checkDeclarationInBlockStatementNode(md, nametable, bsn);
185       }
186     }
187
188     // check loop body
189     checkDeclarationInBlockNode(md, nametable, ln.getBody());
190   }
191
192   private void checkMethodBody(ClassDescriptor cd, MethodDescriptor md) {
193     BlockNode bn = state.getMethodBody(md);
194     checkLocationFromBlockNode(md, md.getParameterTable(), bn);
195   }
196
197   private CompositeLocation checkLocationFromBlockNode(MethodDescriptor md, SymbolTable nametable,
198       BlockNode bn) {
199
200     bn.getVarTable().setParent(nametable);
201     // it will return the lowest location in the block node
202     CompositeLocation lowestLoc = null;
203     for (int i = 0; i < bn.size(); i++) {
204       BlockStatementNode bsn = bn.get(i);
205       CompositeLocation bLoc = checkLocationFromBlockStatementNode(md, bn.getVarTable(), bsn);
206       if (lowestLoc == null) {
207         lowestLoc = bLoc;
208       } else {
209         if (!bLoc.isEmpty()) {
210           if (CompositeLattice.isGreaterThan(lowestLoc, bLoc)) {
211             lowestLoc = bLoc;
212           }
213         }
214       }
215     }
216     return lowestLoc;
217   }
218
219   private CompositeLocation checkLocationFromBlockStatementNode(MethodDescriptor md,
220       SymbolTable nametable, BlockStatementNode bsn) {
221
222     CompositeLocation compLoc = null;
223     switch (bsn.kind()) {
224     case Kind.BlockExpressionNode:
225       compLoc = checkLocationFromBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn);
226       break;
227
228     case Kind.DeclarationNode:
229       compLoc = checkLocationFromDeclarationNode(md, nametable, (DeclarationNode) bsn);
230       break;
231
232     case Kind.IfStatementNode:
233       compLoc = checkLocationFromIfStatementNode(md, nametable, (IfStatementNode) bsn);
234       break;
235
236     case Kind.LoopNode:
237       compLoc = checkLocationFromLoopNode(md, nametable, (LoopNode) bsn);
238       break;
239
240     case Kind.ReturnNode:
241       compLoc = checkLocationFromReturnNode(md, nametable, (ReturnNode) bsn);
242       break;
243
244     case Kind.SubBlockNode:
245       compLoc = checkLocationFromSubBlockNode(md, nametable, (SubBlockNode) bsn);
246       break;
247
248     // case Kind.ContinueBreakNode:
249     // checkLocationFromContinueBreakNode(md, nametable,(ContinueBreakNode)
250     // bsn);
251     // return null;
252     }
253     return compLoc;
254   }
255
256   private CompositeLocation checkLocationFromReturnNode(MethodDescriptor md, SymbolTable nametable,
257       ReturnNode rn) {
258     ClassDescriptor cd = md.getClassDesc();
259     CompositeLocation loc = new CompositeLocation();
260
261     ExpressionNode returnExp = rn.getReturnExpression();
262
263     if (rn == null || hasOnlyLiteralValue(returnExp)) {
264       // when it returns literal value, return node has "bottom" location no
265       // matter what it is going to return.
266       loc.addLocation(Location.createBottomLocation(md));
267     } else {
268       loc = checkLocationFromExpressionNode(md, nametable, returnExp, loc);
269     }
270     return loc;
271   }
272
273   private boolean hasOnlyLiteralValue(ExpressionNode returnExp) {
274     if (returnExp.kind() == Kind.LiteralNode) {
275       return true;
276     } else {
277       return false;
278     }
279   }
280
281   private CompositeLocation checkLocationFromLoopNode(MethodDescriptor md, SymbolTable nametable,
282       LoopNode ln) {
283
284     ClassDescriptor cd = md.getClassDesc();
285     if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
286
287       CompositeLocation condLoc =
288           checkLocationFromExpressionNode(md, nametable, ln.getCondition(), new CompositeLocation());
289       addTypeLocation(ln.getCondition().getType(), (condLoc));
290
291       CompositeLocation bodyLoc = checkLocationFromBlockNode(md, nametable, ln.getBody());
292
293       if (!CompositeLattice.isGreaterThan(condLoc, bodyLoc)) {
294         // loop condition should be higher than loop body
295         throw new Error(
296             "The location of the while-condition statement is lower than the loop body at "
297                 + cd.getSourceFileName() + ":" + ln.getCondition().getNumLine());
298       }
299
300       return bodyLoc;
301
302     } else {
303       // check for loop case
304       BlockNode bn = ln.getInitializer();
305       bn.getVarTable().setParent(nametable);
306
307       // calculate glb location of condition and update statements
308       CompositeLocation condLoc =
309           checkLocationFromExpressionNode(md, bn.getVarTable(), ln.getCondition(),
310               new CompositeLocation());
311       addTypeLocation(ln.getCondition().getType(), condLoc);
312
313       CompositeLocation updateLoc =
314           checkLocationFromBlockNode(md, bn.getVarTable(), ln.getUpdate());
315
316       Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
317       glbInputSet.add(condLoc);
318       glbInputSet.add(updateLoc);
319
320       CompositeLocation glbLocOfForLoopCond = CompositeLattice.calculateGLB(glbInputSet);
321
322       // check location of 'forloop' body
323       CompositeLocation blockLoc = checkLocationFromBlockNode(md, bn.getVarTable(), ln.getBody());
324
325       if (blockLoc == null) {
326         // when there is no statement in the loop body
327         return glbLocOfForLoopCond;
328       }
329
330       if (!CompositeLattice.isGreaterThan(glbLocOfForLoopCond, blockLoc)) {
331         throw new Error(
332             "The location of the for-condition statement is lower than the for-loop body at "
333                 + cd.getSourceFileName() + ":" + ln.getCondition().getNumLine());
334       }
335       return blockLoc;
336     }
337
338   }
339
340   private CompositeLocation checkLocationFromSubBlockNode(MethodDescriptor md,
341       SymbolTable nametable, SubBlockNode sbn) {
342     CompositeLocation compLoc = checkLocationFromBlockNode(md, nametable, sbn.getBlockNode());
343     return compLoc;
344   }
345
346   private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
347       SymbolTable nametable, IfStatementNode isn) {
348
349     ClassDescriptor localCD = md.getClassDesc();
350     Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
351
352     CompositeLocation condLoc =
353         checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation());
354
355     addTypeLocation(isn.getCondition().getType(), condLoc);
356     glbInputSet.add(condLoc);
357
358     CompositeLocation locTrueBlock = checkLocationFromBlockNode(md, nametable, isn.getTrueBlock());
359     glbInputSet.add(locTrueBlock);
360
361     // here, the location of conditional block should be higher than the
362     // location of true/false blocks
363
364     if (!CompositeLattice.isGreaterThan(condLoc, locTrueBlock)) {
365       // error
366       throw new Error(
367           "The location of the if-condition statement is lower than the conditional block at "
368               + localCD.getSourceFileName() + ":" + isn.getCondition().getNumLine());
369     }
370
371     if (isn.getFalseBlock() != null) {
372       CompositeLocation locFalseBlock =
373           checkLocationFromBlockNode(md, nametable, isn.getFalseBlock());
374       glbInputSet.add(locFalseBlock);
375
376       if (!CompositeLattice.isGreaterThan(condLoc, locFalseBlock)) {
377         // error
378         throw new Error(
379             "The location of the if-condition statement is lower than the conditional block at "
380                 + localCD.getSourceFileName() + ":" + isn.getCondition().getNumLine());
381       }
382
383     }
384
385     // return GLB location of condition, true, and false block
386     CompositeLocation glbLoc = CompositeLattice.calculateGLB(glbInputSet);
387
388     return glbLoc;
389   }
390
391   private CompositeLocation checkLocationFromDeclarationNode(MethodDescriptor md,
392       SymbolTable nametable, DeclarationNode dn) {
393
394     VarDescriptor vd = dn.getVarDescriptor();
395
396     CompositeLocation destLoc = d2loc.get(vd);
397
398     ClassDescriptor localCD = md.getClassDesc();
399     if (dn.getExpression() != null) {
400       CompositeLocation expressionLoc =
401           checkLocationFromExpressionNode(md, nametable, dn.getExpression(),
402               new CompositeLocation());
403       addTypeLocation(dn.getExpression().getType(), expressionLoc);
404
405       if (expressionLoc != null) {
406         // checking location order
407         if (!CompositeLattice.isGreaterThan(expressionLoc, destLoc)) {
408           throw new Error("The value flow from " + expressionLoc + " to " + destLoc
409               + " does not respect location hierarchy on the assignment " + dn.printNode(0)
410               + " at " + md.getClassDesc().getSourceFileName() + "::" + dn.getNumLine());
411         }
412       }
413       return expressionLoc;
414
415     } else {
416
417       // if (destLoc instanceof Location) {
418       // CompositeLocation comp = new CompositeLocation();
419       // comp.addLocation(destLoc);
420       // return comp;
421       // } else {
422       // return (CompositeLocation) destLoc;
423       // }
424       return destLoc;
425
426     }
427
428   }
429
430   private void checkDeclarationInSubBlockNode(MethodDescriptor md, SymbolTable nametable,
431       SubBlockNode sbn) {
432     checkDeclarationInBlockNode(md, nametable.getParent(), sbn.getBlockNode());
433   }
434
435   private CompositeLocation checkLocationFromBlockExpressionNode(MethodDescriptor md,
436       SymbolTable nametable, BlockExpressionNode ben) {
437     CompositeLocation compLoc =
438         checkLocationFromExpressionNode(md, nametable, ben.getExpression(), null);
439     // addTypeLocation(ben.getExpression().getType(), compLoc);
440     return compLoc;
441   }
442
443   private CompositeLocation checkLocationFromExpressionNode(MethodDescriptor md,
444       SymbolTable nametable, ExpressionNode en, CompositeLocation loc) {
445
446     CompositeLocation compLoc = null;
447     switch (en.kind()) {
448
449     case Kind.AssignmentNode:
450       compLoc = checkLocationFromAssignmentNode(md, nametable, (AssignmentNode) en, loc);
451       break;
452
453     case Kind.FieldAccessNode:
454       compLoc = checkLocationFromFieldAccessNode(md, nametable, (FieldAccessNode) en, loc);
455       break;
456
457     case Kind.NameNode:
458       compLoc = checkLocationFromNameNode(md, nametable, (NameNode) en, loc);
459       break;
460
461     case Kind.OpNode:
462       compLoc = checkLocationFromOpNode(md, nametable, (OpNode) en);
463       break;
464
465     case Kind.CreateObjectNode:
466       compLoc = checkLocationFromCreateObjectNode(md, nametable, (CreateObjectNode) en);
467       break;
468
469     case Kind.ArrayAccessNode:
470       compLoc = checkLocationFromArrayAccessNode(md, nametable, (ArrayAccessNode) en);
471       break;
472
473     case Kind.LiteralNode:
474       compLoc = checkLocationFromLiteralNode(md, nametable, (LiteralNode) en, loc);
475       break;
476
477     case Kind.MethodInvokeNode:
478       compLoc = checkLocationFromMethodInvokeNode(md, nametable, (MethodInvokeNode) en);
479       break;
480
481     case Kind.TertiaryNode:
482       compLoc = checkLocationFromTertiaryNode(md, nametable, (TertiaryNode) en);
483       break;
484
485     case Kind.CastNode:
486       compLoc = checkLocationFromCastNode(md, nametable, (CastNode) en);
487       break;
488
489     // case Kind.InstanceOfNode:
490     // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
491     // return null;
492
493     // case Kind.ArrayInitializerNode:
494     // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en,
495     // td);
496     // return null;
497
498     // case Kind.ClassTypeNode:
499     // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
500     // return null;
501
502     // case Kind.OffsetNode:
503     // checkOffsetNode(md, nametable, (OffsetNode)en, td);
504     // return null;
505
506     default:
507       return null;
508
509     }
510     // addTypeLocation(en.getType(), compLoc);
511     return compLoc;
512
513   }
514
515   private CompositeLocation checkLocationFromCastNode(MethodDescriptor md, SymbolTable nametable,
516       CastNode cn) {
517
518     ExpressionNode en = cn.getExpression();
519     return checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation());
520
521   }
522
523   private CompositeLocation checkLocationFromTertiaryNode(MethodDescriptor md,
524       SymbolTable nametable, TertiaryNode tn) {
525     ClassDescriptor cd = md.getClassDesc();
526
527     CompositeLocation condLoc =
528         checkLocationFromExpressionNode(md, nametable, tn.getCond(), new CompositeLocation());
529     addTypeLocation(tn.getCond().getType(), condLoc);
530     CompositeLocation trueLoc =
531         checkLocationFromExpressionNode(md, nametable, tn.getTrueExpr(), new CompositeLocation());
532     addTypeLocation(tn.getTrueExpr().getType(), trueLoc);
533     CompositeLocation falseLoc =
534         checkLocationFromExpressionNode(md, nametable, tn.getFalseExpr(), new CompositeLocation());
535     addTypeLocation(tn.getFalseExpr().getType(), falseLoc);
536
537     // check if condLoc is higher than trueLoc & falseLoc
538     if (!CompositeLattice.isGreaterThan(condLoc, trueLoc)) {
539       throw new Error(
540           "The location of the condition expression is lower than the true expression at "
541               + cd.getSourceFileName() + ":" + tn.getCond().getNumLine());
542     }
543
544     if (!CompositeLattice.isGreaterThan(condLoc, falseLoc)) {
545       throw new Error(
546           "The location of the condition expression is lower than the true expression at "
547               + cd.getSourceFileName() + ":" + tn.getCond().getNumLine());
548     }
549
550     // then, return glb of trueLoc & falseLoc
551     Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
552     glbInputSet.add(trueLoc);
553     glbInputSet.add(falseLoc);
554
555     return CompositeLattice.calculateGLB(glbInputSet);
556   }
557
558   private CompositeLocation checkLocationFromMethodInvokeNode(MethodDescriptor md,
559       SymbolTable nametable, MethodInvokeNode min) {
560
561     // Location baseLoc = null;
562     // if (min.getBaseName() != null) {
563     // Descriptor d = nametable.get(min.getBaseName().getSymbol());
564     // if (d instanceof VarDescriptor) {
565     // CompositeLocation varLoc = (CompositeLocation) ((VarDescriptor)
566     // d).getType().getExtension();
567     // return varLoc;
568     // } else {
569     // // it is field descriptor
570     // assert (d instanceof FieldDescriptor);
571     // CompositeLocation fieldLoc =
572     // (CompositeLocation) min.getExpression().getType().getExtension();
573     // return fieldLoc;
574     // }
575     // } else {
576     // // method invocation starting from this
577     // MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
578     // System.out.println("md=" + md + " lattice=" + methodLattice);
579     // String thisLocId = methodLattice.getThisLoc();
580     // baseLoc = new Location(md, thisLocId);
581     // }
582     // System.out.println("BASE LOC=" + baseLoc);
583
584     if (min.numArgs() > 1) {
585       // caller needs to guarantee that it passes arguments in regarding to
586       // callee's hierarchy
587       for (int i = 0; i < min.numArgs(); i++) {
588         ExpressionNode en = min.getArg(i);
589         CompositeLocation callerArg1 =
590             checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation());
591
592         ClassDescriptor calleecd = min.getMethod().getClassDesc();
593         VarDescriptor calleevd = (VarDescriptor) min.getMethod().getParameter(i);
594         CompositeLocation calleeLoc1 = d2loc.get(calleevd);
595
596         if (!callerArg1.get(0).isTop()) {
597           // here, check if ordering relations among caller's args respect
598           // ordering relations in-between callee's args
599           for (int currentIdx = 0; currentIdx < min.numArgs(); currentIdx++) {
600             if (currentIdx != i) { // skip itself
601               ExpressionNode argExp = min.getArg(currentIdx);
602
603               CompositeLocation callerArg2 =
604                   checkLocationFromExpressionNode(md, nametable, argExp, new CompositeLocation());
605
606               VarDescriptor calleevd2 = (VarDescriptor) min.getMethod().getParameter(currentIdx);
607               CompositeLocation calleeLoc2 = d2loc.get(calleevd2);
608
609               boolean callerResult = CompositeLattice.isGreaterThan(callerArg1, callerArg2);
610               boolean calleeResult = CompositeLattice.isGreaterThan(calleeLoc1, calleeLoc2);
611
612               if (calleeResult && !callerResult) {
613                 // If calleeLoc1 is higher than calleeLoc2
614                 // then, caller should have same ordering relation in-bet
615                 // callerLoc1 & callerLoc2
616
617                 throw new Error("Caller doesn't respect ordering relations among method arguments:"
618                     + md.getClassDesc().getSourceFileName() + ":" + min.getNumLine());
619               }
620
621             }
622           }
623         }
624
625       }
626
627     }
628
629     // all arguments should be higher than the location of return value
630
631     Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
632     for (int i = 0; i < min.numArgs(); i++) {
633       ExpressionNode en = min.getArg(i);
634       CompositeLocation callerArg =
635           checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation());
636       inputGLBSet.add(callerArg);
637     }
638
639     if (inputGLBSet.size() > 0) {
640       return CompositeLattice.calculateGLB(inputGLBSet);
641     } else {
642       // if there are no arguments,
643       // method invocation from the same class
644       CompositeLocation compLoc = new CompositeLocation();
645       return compLoc;
646     }
647
648   }
649
650   private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md,
651       SymbolTable nametable, ArrayAccessNode aan) {
652
653     // return glb location of array itself and index
654
655     ClassDescriptor cd = md.getClassDesc();
656
657     Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
658
659     CompositeLocation arrayLoc =
660         checkLocationFromExpressionNode(md, nametable, aan.getExpression(), new CompositeLocation());
661     addTypeLocation(aan.getExpression().getType(), arrayLoc);
662     glbInputSet.add(arrayLoc);
663     CompositeLocation indexLoc =
664         checkLocationFromExpressionNode(md, nametable, aan.getIndex(), new CompositeLocation());
665     glbInputSet.add(indexLoc);
666     addTypeLocation(aan.getIndex().getType(), indexLoc);
667
668     CompositeLocation glbLoc = CompositeLattice.calculateGLB(glbInputSet);
669     return glbLoc;
670   }
671
672   private CompositeLocation checkLocationFromCreateObjectNode(MethodDescriptor md,
673       SymbolTable nametable, CreateObjectNode con) {
674
675     ClassDescriptor cd = md.getClassDesc();
676
677     // check arguments
678     Set<CompositeLocation> glbInputSet = new HashSet<CompositeLocation>();
679     for (int i = 0; i < con.numArgs(); i++) {
680       ExpressionNode en = con.getArg(i);
681       CompositeLocation argLoc =
682           checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation());
683       glbInputSet.add(argLoc);
684       addTypeLocation(en.getType(), argLoc);
685     }
686
687     // check array initializers
688     // if ((con.getArrayInitializer() != null)) {
689     // checkLocationFromArrayInitializerNode(md, nametable,
690     // con.getArrayInitializer());
691     // }
692
693     if (glbInputSet.size() > 0) {
694       return CompositeLattice.calculateGLB(glbInputSet);
695     }
696
697     CompositeLocation compLoc = new CompositeLocation();
698     compLoc.addLocation(Location.createTopLocation(md));
699     return compLoc;
700
701   }
702
703   private CompositeLocation checkLocationFromOpNode(MethodDescriptor md, SymbolTable nametable,
704       OpNode on) {
705
706     ClassDescriptor cd = md.getClassDesc();
707     CompositeLocation leftLoc = new CompositeLocation();
708     leftLoc = checkLocationFromExpressionNode(md, nametable, on.getLeft(), leftLoc);
709     // addTypeLocation(on.getLeft().getType(), leftLoc);
710
711     CompositeLocation rightLoc = new CompositeLocation();
712     if (on.getRight() != null) {
713       rightLoc = checkLocationFromExpressionNode(md, nametable, on.getRight(), rightLoc);
714       // addTypeLocation(on.getRight().getType(), rightLoc);
715     }
716
717     // System.out.println("checking op node=" + on.printNode(0));
718     // System.out.println("left loc=" + leftLoc + " from " +
719     // on.getLeft().getClass());
720     // System.out.println("right loc=" + rightLoc + " from " +
721     // on.getRight().getClass());
722
723     Operation op = on.getOp();
724
725     switch (op.getOp()) {
726
727     case Operation.UNARYPLUS:
728     case Operation.UNARYMINUS:
729     case Operation.LOGIC_NOT:
730       // single operand
731       return leftLoc;
732
733     case Operation.LOGIC_OR:
734     case Operation.LOGIC_AND:
735     case Operation.COMP:
736     case Operation.BIT_OR:
737     case Operation.BIT_XOR:
738     case Operation.BIT_AND:
739     case Operation.ISAVAILABLE:
740     case Operation.EQUAL:
741     case Operation.NOTEQUAL:
742     case Operation.LT:
743     case Operation.GT:
744     case Operation.LTE:
745     case Operation.GTE:
746     case Operation.ADD:
747     case Operation.SUB:
748     case Operation.MULT:
749     case Operation.DIV:
750     case Operation.MOD:
751     case Operation.LEFTSHIFT:
752     case Operation.RIGHTSHIFT:
753     case Operation.URIGHTSHIFT:
754
755       Set<CompositeLocation> inputSet = new HashSet<CompositeLocation>();
756       inputSet.add(leftLoc);
757       inputSet.add(rightLoc);
758       CompositeLocation glbCompLoc = CompositeLattice.calculateGLB(inputSet);
759       return glbCompLoc;
760
761     default:
762       throw new Error(op.toString());
763     }
764
765   }
766
767   private CompositeLocation checkLocationFromLiteralNode(MethodDescriptor md,
768       SymbolTable nametable, LiteralNode en, CompositeLocation loc) {
769
770     // literal value has the top location so that value can be flowed into any
771     // location
772     Location literalLoc = Location.createTopLocation(md);
773     loc.addLocation(literalLoc);
774     return loc;
775
776   }
777
778   private CompositeLocation checkLocationFromNameNode(MethodDescriptor md, SymbolTable nametable,
779       NameNode nn, CompositeLocation loc) {
780
781     NameDescriptor nd = nn.getName();
782     if (nd.getBase() != null) {
783       loc = checkLocationFromExpressionNode(md, nametable, nn.getExpression(), loc);
784       // addTypeLocation(nn.getExpression().getType(), loc);
785     } else {
786       String varname = nd.toString();
787
788       if (varname.equals("this")) {
789         // 'this' itself!
790         MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
791         Location locElement = new Location(md, methodLattice.getThisLoc());
792         loc.addLocation(locElement);
793         return loc;
794       }
795       Descriptor d = (Descriptor) nametable.get(varname);
796
797       // CompositeLocation localLoc = null;
798       if (d instanceof VarDescriptor) {
799         VarDescriptor vd = (VarDescriptor) d;
800         // localLoc = d2loc.get(vd);
801         // the type of var descriptor has a composite location!
802         loc = (CompositeLocation) vd.getType().getExtension();
803       } else if (d instanceof FieldDescriptor) {
804         // the type of field descriptor has a location!
805         FieldDescriptor fd = (FieldDescriptor) d;
806
807         // the location of field access starts from this, followed by field
808         // location
809         MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
810         Location thisLoc = new Location(md, localLattice.getThisLoc());
811         loc.addLocation(thisLoc);
812         Location fieldLoc = (Location) fd.getType().getExtension();
813         loc.addLocation(fieldLoc);
814       }
815     }
816
817     return loc;
818   }
819
820   private CompositeLocation checkLocationFromFieldAccessNode(MethodDescriptor md,
821       SymbolTable nametable, FieldAccessNode fan, CompositeLocation loc) {
822
823     ExpressionNode left = fan.getExpression();
824     loc = checkLocationFromExpressionNode(md, nametable, left, loc);
825     // addTypeLocation(left.getType(), loc);
826
827     if (!left.getType().isPrimitive()) {
828       FieldDescriptor fd = fan.getField();
829       Location fieldLoc = (Location) fd.getType().getExtension();
830       loc.addLocation(fieldLoc);
831     }
832
833     return loc;
834   }
835
836   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
837       SymbolTable nametable, AssignmentNode an, CompositeLocation loc) {
838
839     ClassDescriptor cd = md.getClassDesc();
840
841     boolean postinc = true;
842     if (an.getOperation().getBaseOp() == null
843         || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation()
844             .getBaseOp().getOp() != Operation.POSTDEC))
845       postinc = false;
846
847     CompositeLocation destLocation =
848         checkLocationFromExpressionNode(md, nametable, an.getDest(), new CompositeLocation());
849
850     CompositeLocation srcLocation = new CompositeLocation();
851     if (!postinc) {
852       srcLocation = new CompositeLocation();
853       srcLocation = checkLocationFromExpressionNode(md, nametable, an.getSrc(), srcLocation);
854       // System.out.println("an=" + an.printNode(0) + " an.getSrc()=" +
855       // an.getSrc().getClass()
856       // + " at " + cd.getSourceFileName() + "::" + an.getNumLine());
857       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation)) {
858         throw new Error("The value flow from " + srcLocation + " to " + destLocation
859             + " does not respect location hierarchy on the assignment " + an.printNode(0) + " at "
860             + cd.getSourceFileName() + "::" + an.getNumLine());
861       }
862     } else {
863       destLocation =
864           srcLocation = checkLocationFromExpressionNode(md, nametable, an.getDest(), srcLocation);
865
866       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation)) {
867         throw new Error("Location " + destLocation
868             + " is not allowed to have the value flow that moves within the same location at "
869             + cd.getSourceFileName() + "::" + an.getNumLine());
870       }
871
872     }
873
874     return destLocation;
875   }
876
877   private void assignLocationOfVarDescriptor(VarDescriptor vd, MethodDescriptor md,
878       SymbolTable nametable, TreeNode n) {
879
880     ClassDescriptor cd = md.getClassDesc();
881     Vector<AnnotationDescriptor> annotationVec = vd.getType().getAnnotationMarkers();
882
883     // currently enforce every variable to have corresponding location
884     if (annotationVec.size() == 0) {
885       throw new Error("Location is not assigned to variable " + vd.getSymbol() + " in the method "
886           + md.getSymbol() + " of the class " + cd.getSymbol());
887     }
888
889     if (annotationVec.size() > 1) { // variable can have at most one location
890       throw new Error(vd.getSymbol() + " has more than one location.");
891     }
892
893     AnnotationDescriptor ad = annotationVec.elementAt(0);
894
895     if (ad.getType() == AnnotationDescriptor.SINGLE_ANNOTATION) {
896
897       if (ad.getMarker().equals(SSJavaAnalysis.LOC)) {
898         String locDec = ad.getValue(); // check if location is defined
899
900         if (locDec.startsWith(SSJavaAnalysis.DELTA)) {
901           DeltaLocation deltaLoc = parseDeltaDeclaration(md, n, locDec);
902           d2loc.put(vd, deltaLoc);
903           addTypeLocation(vd.getType(), deltaLoc);
904         } else {
905           CompositeLocation compLoc = parseLocationDeclaration(md, n, locDec);
906           d2loc.put(vd, compLoc);
907           addTypeLocation(vd.getType(), compLoc);
908         }
909
910       }
911     }
912
913   }
914
915   private DeltaLocation parseDeltaDeclaration(MethodDescriptor md, TreeNode n, String locDec) {
916
917     int deltaCount = 0;
918     int dIdx = locDec.indexOf(SSJavaAnalysis.DELTA);
919     while (dIdx >= 0) {
920       deltaCount++;
921       int beginIdx = dIdx + 6;
922       locDec = locDec.substring(beginIdx, locDec.length() - 1);
923       dIdx = locDec.indexOf(SSJavaAnalysis.DELTA);
924     }
925
926     CompositeLocation compLoc = parseLocationDeclaration(md, n, locDec);
927     DeltaLocation deltaLoc = new DeltaLocation(compLoc, deltaCount);
928
929     return deltaLoc;
930   }
931
932   private CompositeLocation parseLocationDeclaration(MethodDescriptor md, TreeNode n, String locDec) {
933
934     CompositeLocation compLoc = new CompositeLocation();
935
936     StringTokenizer tokenizer = new StringTokenizer(locDec, ",");
937     List<String> locIdList = new ArrayList<String>();
938     while (tokenizer.hasMoreTokens()) {
939       String locId = tokenizer.nextToken();
940       locIdList.add(locId);
941     }
942
943     // at least,one location element needs to be here!
944     assert (locIdList.size() > 0);
945
946     // assume that loc with idx 0 comes from the local lattice
947     // loc with idx 1 comes from the field lattice
948
949     String localLocId = locIdList.get(0);
950     SSJavaLattice<String> localLattice = CompositeLattice.getLatticeByDescriptor(md);
951     Location localLoc = new Location(md, localLocId);
952     if (localLattice == null || (!localLattice.containsKey(localLocId))) {
953       throw new Error("Location " + localLocId
954           + " is not defined in the local variable lattice at "
955           + md.getClassDesc().getSourceFileName() + "::" + n.getNumLine() + ".");
956     }
957     compLoc.addLocation(localLoc);
958
959     for (int i = 1; i < locIdList.size(); i++) {
960       String locName = locIdList.get(i);
961       ClassDescriptor cd = fieldLocName2cd.get(locName);
962
963       SSJavaLattice<String> fieldLattice = CompositeLattice.getLatticeByDescriptor(cd);
964
965       if (fieldLattice == null || (!fieldLattice.containsKey(locName))) {
966         throw new Error("Location " + locName + " is not defined in the field lattice at "
967             + cd.getSourceFileName() + ".");
968       }
969
970       Location fieldLoc = new Location(cd, locName);
971       compLoc.addLocation(fieldLoc);
972     }
973
974     return compLoc;
975
976   }
977
978   private void checkDeclarationNode(MethodDescriptor md, SymbolTable nametable, DeclarationNode dn) {
979     VarDescriptor vd = dn.getVarDescriptor();
980     assignLocationOfVarDescriptor(vd, md, nametable, dn);
981   }
982
983   private void checkClass(ClassDescriptor cd) {
984     // Check to see that methods respects ss property
985     for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
986       MethodDescriptor md = (MethodDescriptor) method_it.next();
987       checkMethodDeclaration(cd, md);
988     }
989   }
990
991   private void checkDeclarationInClass(ClassDescriptor cd) {
992     // Check to see that fields are okay
993     for (Iterator field_it = cd.getFields(); field_it.hasNext();) {
994       FieldDescriptor fd = (FieldDescriptor) field_it.next();
995       checkFieldDeclaration(cd, fd);
996     }
997   }
998
999   private void checkMethodDeclaration(ClassDescriptor cd, MethodDescriptor md) {
1000     // TODO
1001   }
1002
1003   private void checkFieldDeclaration(ClassDescriptor cd, FieldDescriptor fd) {
1004
1005     Vector<AnnotationDescriptor> annotationVec = fd.getType().getAnnotationMarkers();
1006
1007     // currently enforce every field to have corresponding location
1008     if (annotationVec.size() == 0) {
1009       throw new Error("Location is not assigned to the field " + fd.getSymbol() + " of the class "
1010           + cd.getSymbol());
1011     }
1012
1013     if (annotationVec.size() > 1) {
1014       // variable can have at most one location
1015       throw new Error("Field " + fd.getSymbol() + " of class " + cd
1016           + " has more than one location.");
1017     }
1018
1019     AnnotationDescriptor ad = annotationVec.elementAt(0);
1020
1021     if (ad.getType() == AnnotationDescriptor.SINGLE_ANNOTATION) {
1022
1023       if (ad.getMarker().equals(SSJavaAnalysis.LOC)) {
1024         String locationID = ad.getValue();
1025         // check if location is defined
1026         SSJavaLattice<String> lattice = ssjava.getClassLattice(cd);
1027         if (lattice == null || (!lattice.containsKey(locationID))) {
1028           throw new Error("Location " + locationID
1029               + " is not defined in the field lattice of class " + cd.getSymbol() + " at"
1030               + cd.getSourceFileName() + ".");
1031         }
1032         Location loc = new Location(cd, locationID);
1033         // d2loc.put(fd, loc);
1034         addTypeLocation(fd.getType(), loc);
1035
1036       }
1037     }
1038
1039   }
1040
1041   private void addTypeLocation(TypeDescriptor type, CompositeLocation loc) {
1042     if (type != null) {
1043       type.setExtension(loc);
1044     }
1045   }
1046
1047   private void addTypeLocation(TypeDescriptor type, Location loc) {
1048     if (type != null) {
1049       type.setExtension(loc);
1050     }
1051   }
1052
1053   static class CompositeLattice {
1054
1055     public static boolean isGreaterThan(CompositeLocation loc1, CompositeLocation loc2) {
1056
1057       int baseCompareResult = compareBaseLocationSet(loc1, loc2);
1058       if (baseCompareResult == ComparisonResult.EQUAL) {
1059         if (compareDelta(loc1, loc2) == ComparisonResult.GREATER) {
1060           return true;
1061         } else {
1062           return false;
1063         }
1064       } else if (baseCompareResult == ComparisonResult.GREATER) {
1065         return true;
1066       } else {
1067         return false;
1068       }
1069
1070     }
1071
1072     private static int compareDelta(CompositeLocation dLoc1, CompositeLocation dLoc2) {
1073
1074       int deltaCount1 = 0;
1075       int deltaCount2 = 0;
1076       if (dLoc1 instanceof DeltaLocation) {
1077         deltaCount1 = ((DeltaLocation) dLoc1).getNumDelta();
1078       }
1079
1080       if (dLoc2 instanceof DeltaLocation) {
1081         deltaCount2 = ((DeltaLocation) dLoc2).getNumDelta();
1082       }
1083       if (deltaCount1 < deltaCount2) {
1084         return ComparisonResult.GREATER;
1085       } else if (deltaCount1 == deltaCount2) {
1086         return ComparisonResult.EQUAL;
1087       } else {
1088         return ComparisonResult.LESS;
1089       }
1090
1091     }
1092
1093     private static int compareBaseLocationSet(CompositeLocation compLoc1, CompositeLocation compLoc2) {
1094
1095       // if compLoc1 is greater than compLoc2, return true
1096       // else return false;
1097
1098       // compare one by one in according to the order of the tuple
1099       int numOfTie = 0;
1100       for (int i = 0; i < compLoc1.getSize(); i++) {
1101         Location loc1 = compLoc1.get(i);
1102         if (i >= compLoc2.getSize()) {
1103           throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
1104               + " because they are not comparable.");
1105         }
1106         Location loc2 = compLoc2.get(i);
1107
1108         if (!loc1.getDescriptor().equals(loc2.getDescriptor())) {
1109           throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
1110               + " because they are not comparable.");
1111         }
1112
1113         Descriptor d1 = loc1.getDescriptor();
1114         Descriptor d2 = loc2.getDescriptor();
1115
1116         SSJavaLattice<String> lattice1 = getLatticeByDescriptor(d1);
1117         SSJavaLattice<String> lattice2 = getLatticeByDescriptor(d2);
1118
1119         if (!lattice1.equals(lattice2)) {
1120           throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
1121               + " because they are not comparable.");
1122         }
1123
1124         if (loc1.getLocIdentifier().equals(loc2.getLocIdentifier())) {
1125           // check if the current location is the spinning location
1126           if (lattice1.getSpinLocSet().contains(loc1.getLocIdentifier())) {
1127             return ComparisonResult.GREATER;
1128           }
1129           numOfTie++;
1130           continue;
1131         } else if (lattice1.isGreaterThan(loc1.getLocIdentifier(), loc2.getLocIdentifier())) {
1132           return ComparisonResult.GREATER;
1133         } else {
1134           return ComparisonResult.LESS;
1135         }
1136
1137       }
1138
1139       if (numOfTie == compLoc1.getSize()) {
1140
1141         if (numOfTie != compLoc2.getSize()) {
1142           throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2
1143               + " because they are not comparable.");
1144         }
1145
1146         return ComparisonResult.EQUAL;
1147       }
1148
1149       return ComparisonResult.LESS;
1150
1151     }
1152
1153     public static CompositeLocation calculateGLB(Set<CompositeLocation> inputSet) {
1154
1155       // System.out.println("Calculating GLB=" + inputSet);
1156       CompositeLocation glbCompLoc = new CompositeLocation();
1157
1158       // calculate GLB of the first(priority) element
1159       Set<String> priorityLocIdentifierSet = new HashSet<String>();
1160       Descriptor priorityDescriptor = null;
1161
1162       Hashtable<String, Set<CompositeLocation>> locId2CompLocSet =
1163           new Hashtable<String, Set<CompositeLocation>>();
1164       // mapping from the priority loc ID to its full representation by the
1165       // composite location
1166
1167       for (Iterator iterator = inputSet.iterator(); iterator.hasNext();) {
1168         CompositeLocation compLoc = (CompositeLocation) iterator.next();
1169         Location priorityLoc = compLoc.get(0);
1170         String priorityLocId = priorityLoc.getLocIdentifier();
1171         priorityLocIdentifierSet.add(priorityLocId);
1172
1173         if (locId2CompLocSet.contains(priorityLocId)) {
1174           locId2CompLocSet.get(priorityLocId).add(compLoc);
1175         } else {
1176           Set<CompositeLocation> newSet = new HashSet<CompositeLocation>();
1177           newSet.add(compLoc);
1178           locId2CompLocSet.put(priorityLocId, newSet);
1179         }
1180
1181         // check if priority location are coming from the same lattice
1182         if (priorityDescriptor == null) {
1183           priorityDescriptor = priorityLoc.getDescriptor();
1184         } else if (!priorityDescriptor.equals(priorityLoc.getDescriptor())) {
1185           throw new Error("Failed to calculate GLB of " + inputSet
1186               + " because they are from different lattices.");
1187         }
1188       }
1189
1190       SSJavaLattice<String> locOrder = getLatticeByDescriptor(priorityDescriptor);
1191       String glbOfPriorityLoc = locOrder.getGLB(priorityLocIdentifierSet);
1192
1193       glbCompLoc.addLocation(new Location(priorityDescriptor, glbOfPriorityLoc));
1194
1195       Set<CompositeLocation> compSet = locId2CompLocSet.get(glbOfPriorityLoc);
1196
1197       if (compSet.size() == 1) {
1198         // if GLB(x1,x2)==x1 or x2 : GLB case 2,3
1199         CompositeLocation comp = compSet.iterator().next();
1200         for (int i = 1; i < comp.getSize(); i++) {
1201           glbCompLoc.addLocation(comp.get(i));
1202         }
1203       } else if (compSet.size() == 0) {
1204         // when GLB(x1,x2)!=x1 and !=x2 : GLB case 4
1205         // mean that the result is already lower than <x1,y1> and <x2,y2>
1206         // assign TOP to the rest of the location elements
1207         CompositeLocation inputComp = inputSet.iterator().next();
1208         for (int i = 1; i < inputComp.getSize(); i++) {
1209           glbCompLoc.addLocation(Location.createTopLocation(inputComp.get(i).getDescriptor()));
1210         }
1211       } else {
1212         // when GLB(x1,x2)==x1 and x2 : GLB case 1
1213         // if more than one location shares the same priority GLB
1214         // need to calculate the rest of GLB loc
1215
1216         int compositeLocSize = compSet.iterator().next().getSize();
1217
1218         Set<String> glbInputSet = new HashSet<String>();
1219         Descriptor currentD = null;
1220         for (int i = 1; i < compositeLocSize; i++) {
1221           for (Iterator iterator = compSet.iterator(); iterator.hasNext();) {
1222             CompositeLocation compositeLocation = (CompositeLocation) iterator.next();
1223             Location currentLoc = compositeLocation.get(i);
1224             currentD = currentLoc.getDescriptor();
1225             // making set of the current location sharing the same idx
1226             glbInputSet.add(currentLoc.getLocIdentifier());
1227           }
1228           // calculate glb for the current lattice
1229
1230           SSJavaLattice<String> currentLattice = getLatticeByDescriptor(currentD);
1231           String currentGLBLocId = currentLattice.getGLB(glbInputSet);
1232           glbCompLoc.addLocation(new Location(currentD, currentGLBLocId));
1233         }
1234
1235       }
1236
1237       return glbCompLoc;
1238
1239     }
1240
1241     static SSJavaLattice<String> getLatticeByDescriptor(Descriptor d) {
1242
1243       SSJavaLattice<String> lattice = null;
1244
1245       if (d instanceof ClassDescriptor) {
1246         lattice = ssjava.getCd2lattice().get(d);
1247       } else if (d instanceof MethodDescriptor) {
1248         if (ssjava.getMd2lattice().containsKey(d)) {
1249           lattice = ssjava.getMd2lattice().get(d);
1250         } else {
1251           // use default lattice for the method
1252           lattice = ssjava.getCd2methodDefault().get(((MethodDescriptor) d).getClassDesc());
1253         }
1254       }
1255
1256       return lattice;
1257     }
1258
1259   }
1260
1261   class ComparisonResult {
1262
1263     public static final int GREATER = 0;
1264     public static final int EQUAL = 1;
1265     public static final int LESS = 2;
1266     int result;
1267
1268   }
1269
1270 }