X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FIR%2FTree%2FBuildIR.java;h=a12dcf0a36aa0595d9c70d0598a4969b12f15c0b;hb=b9299937e1f902199ac28e203cf5fea92b5ba427;hp=663f23955cd7aba87584a28ed29bb8968207990d;hpb=f1136ecd8d324adcf8aa8dcf83f2b38c39eb8fd6;p=IRC.git diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 663f2395..a12dcf0a 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,21 +1,26 @@ package IR.Tree; import IR.*; import Util.Lattice; -import java.util.*; +import Util.Pair; +import java.io.File; +import java.util.*; +import java.io.*; +import java.lang.Throwable; public class BuildIR { State state; - + private boolean isRunningRecursiveInnerClass; private int m_taskexitnum; public BuildIR(State state) { this.state=state; this.m_taskexitnum = 0; + this.isRunningRecursiveInnerClass = false; } public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) { - parseFile(pn, toanalyze,sourcefile); - + parseFile(pn, toanalyze, sourcefile); + // numering the interfaces int if_num = 0; Iterator it_classes = state.getClassSymbolTable().getValueSet().iterator(); @@ -27,147 +32,191 @@ public class BuildIR { } } - Vector singleimports; - Vector multiimports; - NameDescriptor packages; + //This is all single imports and a subset of the + //multi imports that have been resolved. + ChainHashMap mandatoryImports; + //maps class names in file to full name + //Note may map a name to an ERROR. + ChainHashMap multiimports; + String packageName; + + String currsourcefile; + Set analyzeset; + + void pushChainMaps() { + mandatoryImports=mandatoryImports.makeChild(); + multiimports=multiimports.makeChild(); + } + + void popChainMaps() { + mandatoryImports=mandatoryImports.getParent(); + multiimports=multiimports.getParent(); + } /** Parse the classes in this file */ - 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 import the package directory as a multi-import and it'll + //automatically recognize files in the same directory. + addMultiImport(sourcefile, packageName, true); } + 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 +"'."); - } + ParseNode decl=pnv.elementAt(i); + if (isNode(decl,"member")) { + parseClassMember(cn,decl); + } else if (isNode(decl,"constructor")) { + parseConstructorDecl(cn,decl.getChild("constructor_declaration")); + } else if (isNode(decl, "static_block")) { + parseStaticBlockDecl(cn, decl.getChild("static_block_declaration")); + } else if (isNode(decl,"block")) { + } else throw new Error(); } - state.addLocationPropertySet(cd, spinLocSet); } - state.addLocationOrder(cd, locOrder); } - + private void parseClassMember(ClassDescriptor cn, ParseNode pn) { ParseNode fieldnode=pn.getChild("field"); if (fieldnode!=null) { + //System.out.println( pn.PPrint( 0, true ) ); parseFieldDecl(cn,fieldnode.getChild("field_declaration")); return; } @@ -548,9 +731,15 @@ public class BuildIR { parseInnerClassDecl(cn,innerclassnode); return; } + ParseNode innerinterfacenode=pn.getChild("interface_declaration"); + if (innerinterfacenode!=null) { + parseInterfaceDecl(innerinterfacenode, cn); + return; + } + ParseNode enumnode=pn.getChild("enum_declaration"); if (enumnode!=null) { - parseEnumDecl(cn,enumnode); + ClassDescriptor ecn=parseEnumDecl(cn,enumnode); return; } ParseNode flagnode=pn.getChild("flag"); @@ -563,23 +752,36 @@ public class BuildIR { if(emptynode != null) { return; } + System.out.println("Unrecognized node:"+pn.PPrint(2,true)); throw new Error(); } - + +//10/9/2011 changed this function to enable creation of default constructor for inner classes. +//the change was refactoring this function with the corresponding version for normal classes. sganapat private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) { - ClassDescriptor icn=new ClassDescriptor(pn.getChild("name").getTerminal(), false); - icn.setAsInnerClass(); + String basename=pn.getChild("name").getTerminal(); + String classname=cn.getClassName()+"$"+basename; + + if (cn.getPackage()==null) + cn.getSingleImportMappings().put(basename,classname); + else + cn.getSingleImportMappings().put(basename,cn.getPackage()+"."+classname); + + ClassDescriptor icn=new ClassDescriptor(cn.getPackage(), classname, false); + pushChainMaps(); + icn.setImports(mandatoryImports, multiimports); icn.setSurroundingClass(cn.getSymbol()); icn.setSurrounding(cn); cn.addInnerClass(icn); - if (!isEmpty(pn.getChild("super").getTerminal())) { + + if (!isEmpty(pn.getChild("super").getTerminal())) { /* parse superclass name */ ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name"); - NameDescriptor nd=parseName(snn); + NameDescriptor nd=parseClassName(snn); icn.setSuper(nd.toString()); } else { if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)|| - icn.getSymbol().equals(TypeUtil.TagClass))) + icn.getSymbol().equals(TypeUtil.TagClass))) icn.setSuper(TypeUtil.ObjectClass); } // check inherited interfaces @@ -590,17 +792,40 @@ public class BuildIR { for(int i=0; i annotations=modifiers.getAnnotations(); for(int i=0; i