X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FIR%2FTree%2FBuildIR.java;h=9e2da3b6433d75d1179f9aa9da285d9e7a54663e;hb=b00cb94ef0988049d74095035f02ed8f241eab77;hp=636821f7c8411cf4c607a008f210e1b82e3565a7;hpb=5851f34441c2c07c26db89e81372b1041ce2765b;p=IRC.git diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 636821f7..9e2da3b6 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,679 +1,1559 @@ package IR.Tree; import IR.*; +import Util.Lattice; import java.util.*; - public class BuildIR { - State state; - public BuildIR(State state) { - this.state=state; - } - public void buildtree() { - for(Iterator it=state.parsetrees.iterator();it.hasNext();) { - ParseNode pn=(ParseNode)it.next(); - parseFile(pn); - } + State state; + + private int m_taskexitnum; + + public BuildIR(State state) { + this.state=state; + this.m_taskexitnum = 0; + } + + 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++); + } } + } - /** Parse the classes in this file */ - public void parseFile(ParseNode pn) { - ParseNode tpn=pn.getChild("type_declaration_list"); - if (tpn!=null) { - ParseNodeVector pnv=tpn.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; + } + ParseNode methodnode=pn.getChild("method"); + if (methodnode!=null) { + 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