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
SymbolTable enumdescs;
HashMap<String, Integer> enumConstantTbl;
int enumconstantid = 0;
+
+ // for SSJava
+ Lattice<String> locOrder;
public ClassDescriptor(String classname, boolean isInterface) {
this("", classname, isInterface);
superIFdesc = new SymbolTable();
this.innerdescs = new SymbolTable();
this.enumdescs = new SymbolTable();
+ this.locOrder=new Lattice<String>();
}
public int getId() {
public Modifiers getModifier() {
return this.modifiers;
}
+
+ public Lattice<String> getLocOrder(){
+ return this.locOrder;
+ }
+
+ public void setLocOrder(Lattice<String> locOrder){
+ this.locOrder=locOrder;
+ }
+
}
package IR.Tree;
import IR.*;
+import Util.Lattice;
import java.util.*;
} 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<String> locOrder=new Lattice<String>();
+ for(int i=0; i<pnv.size(); i++) {
+ ParseNode loc=pnv.elementAt(i);
+ String lowerLoc=loc.getChildren().elementAt(0).getLabel();
+ String higherLoc=loc.getChildren().elementAt(1).getLabel();
+ locOrder.put(higherLoc, lowerLoc);
+ }
+ cn.setLocOrder(locOrder);
+ }
+
private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
ParseNode fieldnode=pn.getChild("field");
if (fieldnode!=null) {
// Keywords for interface of mgc
key_table.put("interface", new Integer(Sym.INTERFACE));
key_table.put("implements", new Integer(Sym.IMPLEMENTS));
+ // Keywords for Self-Stabilizing Java
+ key_table.put("locdef", new Integer(Sym.LOCDEF));
}
}
"import", "instanceof", "int",
"interface",
"isavailable",
- "long",
+ "locdef", "long",
"native", "new", "optional", "package", "private", "protected", "public",
"rblock", "return",
"scratch", "sese", "short", "static", "strictfp", "super", "switch", "synchronized",
terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
terminal ANDEQ, XOREQ, OREQ; // assignment_operator
terminal AT; // support annotations
+terminal LOCDEF; // declaration of location hierarchy
terminal java.lang.Number INTEGER_LITERAL;
terminal java.lang.Number FLOATING_POINT_LITERAL;
non terminal ParseNode constructor_declaration, constructor_declarator;
non terminal ParseNode constructor_body;
non terminal ParseNode explicit_constructor_invocation;
+// 19.8.6) Location Hierarchy Declarations
+non terminal ParseNode location_order_declaration, location_order_list, location_order;
// 19.9.1) Interface Declarations
non terminal ParseNode interface_declaration;
non terminal normal_interface_declaration, annotation_type_declaration;
:}
| block:block {:
RESULT=(new ParseNode("block")).addChild(block).getRoot();
-:}
+ :}
+ | location_order_declaration:lod {:
+ RESULT=(new ParseNode("location_order_declaration")).addChild(lod).getRoot();
+ :}
;
class_member_declaration ::=
//failure aware computation
flag_declaration:flag {:
RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
- :}
- |
+ :}
+ |
field_declaration:field {:
RESULT=(new ParseNode("field")).addChild(field).getRoot();
:}
// | SEMICOLON class_body_declarations_opt:cbdo
// ;
-
//Failure aware computation
flag_declaration ::=
FLAG IDENTIFIER:id SEMICOLON {:
// | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
;
+// 19.8.6) Location Hierarchy Declarations
+location_order_declaration ::= LOCDEF LBRACE location_order_list:lol RBRACE {:
+ RESULT=lol;
+ :}
+ ;
+location_order_list ::=
+ location_order:lo {:
+ ParseNode pn=new ParseNode("location_order_list");
+ pn.addChild(lo);
+ RESULT=pn;
+ :}
+ | location_order_list:lol COMMA location_order:lo {:
+ lol.addChild(lo);
+ RESULT=lol;
+ :}
+ ;
+location_order ::=
+ IDENTIFIER:loc1 LT IDENTIFIER:loc2{:
+ ParseNode pn=new ParseNode("location_order");
+ pn.addChild(loc1);
+ pn.addChild(loc2);
+ RESULT=pn;
+ :}
+ ;
+
// 19.9) Interfaces
// 19.9.1) Interface Declarations
--- /dev/null
+package Util;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+public class Lattice<T> {
+ private Hashtable<T, Set<T>> table;
+ int size;
+
+ public Lattice() {
+ table = new Hashtable<T, Set<T>>();
+ }
+
+ public boolean put(T key, T value) {
+ Set<T> s;
+ if (table.containsKey(key)) {
+ s = table.get(key);
+ } else {
+ s = new HashSet<T>();
+ table.put(key, s);
+ }
+ if (!s.contains(value)) {
+ size++;
+ s.add(value);
+ return true;
+ } else
+ return false;
+ }
+
+ public Set<T> get(T key) {
+ return table.get(key);
+ }
+
+ public boolean containsKey(T o) {
+ return table.containsKey(o);
+ }
+
+ public boolean isGreaterThan(T a, T b) {
+
+ Set<T> 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<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
+ T neighbor = iterator.next();
+ reachable = reachable || isGreaterThan(neighbor, b);
+ }
+ return reachable;
+ }
+ }
+
+ public T getGLB(Set<T> inputSet) {
+
+ Set<T> lowerSet = new HashSet<T>();
+
+ // get lower set of input locations
+ for (Iterator<T> iterator = inputSet.iterator(); iterator.hasNext();) {
+ T element = iterator.next();
+ lowerSet.addAll(getLowerSet(element, new HashSet<T>()));
+ }
+
+ // calculate the greatest element of lower set
+ // find an element A, where every lower bound B of lowerSet, B<A
+ for (Iterator<T> iterator = lowerSet.iterator(); iterator.hasNext();) {
+ T lowerElement = iterator.next();
+ boolean isGreaterThanAll = true;
+ for (Iterator<T> 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<T> getLowerSet(T element, Set<T> lowerSet) {
+
+ Set<T> neighborSet = get(element);
+ if (neighborSet != null) {
+ lowerSet.addAll(neighborSet);
+ for (Iterator<T> iterator = neighborSet.iterator(); iterator.hasNext();) {
+ T neighbor = iterator.next();
+ lowerSet = getLowerSet(neighbor, lowerSet);
+ }
+ }
+ return lowerSet;
+ }
+
+}