X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FIR%2FTree%2FBuildIR.java;h=9e2da3b6433d75d1179f9aa9da285d9e7a54663e;hp=5293f865966e5832f565bff97c965f27a70bfb17;hb=b00cb94ef0988049d74095035f02ed8f241eab77;hpb=36bac4fbcfabb5d2d2cbba32f6d42cd1f1c20f10 diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 5293f865..9e2da3b6 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,8 +1,8 @@ package IR.Tree; import IR.*; +import Util.Lattice; import java.util.*; - public class BuildIR { State state; @@ -13,8 +13,18 @@ public class BuildIR { this.m_taskexitnum = 0; } - public void buildtree(ParseNode pn, Set toanalyze) { - parseFile(pn, toanalyze); + public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) { + parseFile(pn, toanalyze,sourcefile); + + // numering the interfaces + int if_num = 0; + Iterator it_classes = state.getClassSymbolTable().getValueSet().iterator(); + while(it_classes.hasNext()) { + ClassDescriptor cd = (ClassDescriptor)it_classes.next(); + if(cd.isInterface()) { + cd.setInterfaceId(if_num++); + } + } } Vector singleimports; @@ -22,16 +32,17 @@ public class BuildIR { NameDescriptor packages; /** Parse the classes in this file */ - public void parseFile(ParseNode pn, Set toanalyze) { + public void parseFile(ParseNode pn, Set toanalyze,String sourcefile) { singleimports=new Vector(); multiimports=new Vector(); - + ParseNode ipn=pn.getChild("imports").getChild("import_decls_list"); if (ipn!=null) { ParseNodeVector pnv=ipn.getChildren(); for(int i=0; i locOrder = + new Lattice("_top_","_bottom_"); + Set spinLocSet=new HashSet(); + for (int i = 0; i < pnv.size(); i++) { + ParseNode loc = pnv.elementAt(i); + if(isNode(loc,"location_property")){ + String spinLoc=loc.getChildren().elementAt(0).getLabel(); + spinLocSet.add(spinLoc); + }else{ + String lowerLoc=loc.getChildren().elementAt(0).getLabel(); + String higherLoc= loc.getChildren().elementAt(1).getLabel(); + locOrder.put(higherLoc, lowerLoc); + if (locOrder.isIntroducingCycle(higherLoc)) { + throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc + + " introduces a cycle."); + } + } + } + if(spinLocSet.size()>0){ + //checking if location is actually defined in the hierarchy + for (Iterator iterator = spinLocSet.iterator(); iterator.hasNext();) { + String locID = (String) iterator.next(); + if(!locOrder.containsKey(locID)){ + throw new Error("Error: The spinning location '"+ + locID + "' is not defined in the hierarchy of the class '"+cd +"'."); + } + } + state.addLocationPropertySet(cd, spinLocSet); + } + state.addLocationOrder(cd, locOrder); + } + private void parseClassMember(ClassDescriptor cn, ParseNode pn) { ParseNode fieldnode=pn.getChild("field"); - if (fieldnode!=null) { parseFieldDecl(cn,fieldnode.getChild("field_declaration")); return; @@ -268,13 +545,66 @@ public class BuildIR { parseMethodDecl(cn,methodnode.getChild("method_declaration")); return; } + ParseNode innerclassnode=pn.getChild("inner_class_declaration"); + if (innerclassnode!=null) { + parseInnerClassDecl(cn,innerclassnode); + return; + } + ParseNode enumnode=pn.getChild("enum_declaration"); + if (enumnode!=null) { + parseEnumDecl(cn,enumnode); + return; + } ParseNode flagnode=pn.getChild("flag"); if (flagnode!=null) { parseFlagDecl(cn, flagnode.getChild("flag_declaration")); return; } + // in case there are empty node + ParseNode emptynode=pn.getChild("empty"); + if(emptynode != null) { + return; + } throw new Error(); } + + private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) { + ClassDescriptor icn=new ClassDescriptor(pn.getChild("name").getTerminal(), false); + icn.setAsInnerClass(); + icn.setSurroundingClass(cn.getSymbol()); + icn.setSurrounding(cn); + cn.addInnerClass(icn); + if (!isEmpty(pn.getChild("super").getTerminal())) { + /* parse superclass name */ + ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name"); + NameDescriptor nd=parseName(snn); + icn.setSuper(nd.toString()); + } else { + if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)|| + icn.getSymbol().equals(TypeUtil.TagClass))) + icn.setSuper(TypeUtil.ObjectClass); + } + // check inherited interfaces + if (!isEmpty(pn.getChild("superIF").getTerminal())) { + /* parse inherited interface name */ + ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list"); + ParseNodeVector pnv=snlist.getChildren(); + for(int i=0; i annotations=modifiers.getAnnotations(); + for(int i=0; i slv = new Vector(); + for(int j=0; j