From 3ad6a49a28d6768a6bbbd38c3fea80bc4ea59b16 Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 3 Mar 2011 19:33:42 +0000 Subject: [PATCH] add grammar for the definition of location hierarchy. location hierarchy is stored in the lattice data structure. class descriptor has a lattice object since each class maintains its own location hierarchy, --- Robust/src/IR/ClassDescriptor.java | 14 ++++ Robust/src/IR/Tree/BuildIR.java | 17 ++++- Robust/src/Lex/Keyword.java | 2 + Robust/src/Lex/Lexer.java | 2 +- Robust/src/Parse/java14.cup | 38 +++++++++-- Robust/src/Util/Lattice.java | 103 +++++++++++++++++++++++++++++ 6 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 Robust/src/Util/Lattice.java diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index 26e57df0..d1fa7b49 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -1,6 +1,7 @@ package IR; import java.util.*; import IR.Tree.*; +import Util.Lattice; public class ClassDescriptor extends Descriptor { private static int UIDCount=1; // start from 1 instead of 0 for multicore gc @@ -38,6 +39,9 @@ public class ClassDescriptor extends Descriptor { SymbolTable enumdescs; HashMap enumConstantTbl; int enumconstantid = 0; + + // for SSJava + Lattice locOrder; public ClassDescriptor(String classname, boolean isInterface) { this("", classname, isInterface); @@ -57,6 +61,7 @@ public class ClassDescriptor extends Descriptor { superIFdesc = new SymbolTable(); this.innerdescs = new SymbolTable(); this.enumdescs = new SymbolTable(); + this.locOrder=new Lattice(); } public int getId() { @@ -370,4 +375,13 @@ public class ClassDescriptor extends Descriptor { public Modifiers getModifier() { return this.modifiers; } + + public Lattice getLocOrder(){ + return this.locOrder; + } + + public void setLocOrder(Lattice locOrder){ + this.locOrder=locOrder; + } + } diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index fd12e968..4b505b0a 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,5 +1,6 @@ package IR.Tree; import IR.*; +import Util.Lattice; import java.util.*; @@ -473,11 +474,25 @@ public class BuildIR { } else if (isNode(decl, "static_block")) { parseStaticBlockDecl(cn, decl.getChild("static_block_declaration")); } else if (isNode(decl,"block")) { - } else throw new Error(); + } else if (isNode(decl,"location_order_declaration")) { + parseLocationOrder(cn,decl.getChild("location_order_list")); + } else throw new Error(); } } } + private void parseLocationOrder(ClassDescriptor cn, ParseNode pn){ + ParseNodeVector pnv=pn.getChildren(); + Lattice locOrder=new Lattice(); + for(int i=0; i { + private Hashtable> table; + int size; + + public Lattice() { + table = new Hashtable>(); + } + + public boolean put(T key, T value) { + Set s; + if (table.containsKey(key)) { + s = table.get(key); + } else { + s = new HashSet(); + table.put(key, s); + } + if (!s.contains(value)) { + size++; + s.add(value); + return true; + } else + return false; + } + + public Set get(T key) { + return table.get(key); + } + + public boolean containsKey(T o) { + return table.containsKey(o); + } + + public boolean isGreaterThan(T a, T b) { + + Set neighborSet = get(a); + System.out.println("neightborSet of " + a + "=" + neighborSet); + + if (neighborSet == null) { + return false; + } else if (neighborSet.contains(b)) { + return true; + } else { + boolean reachable = false; + for (Iterator iterator = neighborSet.iterator(); iterator.hasNext();) { + T neighbor = iterator.next(); + reachable = reachable || isGreaterThan(neighbor, b); + } + return reachable; + } + } + + public T getGLB(Set inputSet) { + + Set lowerSet = new HashSet(); + + // get lower set of input locations + for (Iterator iterator = inputSet.iterator(); iterator.hasNext();) { + T element = iterator.next(); + lowerSet.addAll(getLowerSet(element, new HashSet())); + } + + // calculate the greatest element of lower set + // find an element A, where every lower bound B of lowerSet, B iterator = lowerSet.iterator(); iterator.hasNext();) { + T lowerElement = iterator.next(); + boolean isGreaterThanAll = true; + for (Iterator iterator2 = lowerSet.iterator(); iterator2.hasNext();) { + T e = iterator2.next(); + if (!lowerElement.equals(e)) { + if (!isGreaterThan(lowerElement, e)) { + isGreaterThanAll = false; + break; + } + } + } + if (isGreaterThanAll) { + return lowerElement; + } + } + return null; + } + + public Set getLowerSet(T element, Set lowerSet) { + + Set neighborSet = get(element); + if (neighborSet != null) { + lowerSet.addAll(neighborSet); + for (Iterator iterator = neighborSet.iterator(); iterator.hasNext();) { + T neighbor = iterator.next(); + lowerSet = getLowerSet(neighbor, lowerSet); + } + } + return lowerSet; + } + +} -- 2.34.1