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=037232e00e796f25ff48437aa91bf3263d4a2034;hb=b00cb94ef0988049d74095035f02ed8f241eab77;hpb=bd0bd51667474cbd33cd50cb1cb0a2d67c030bd4;ds=sidebyside diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 037232e0..9e2da3b6 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,9 +1,8 @@ package IR.Tree; import IR.*; - +import Util.Lattice; import java.util.*; - public class BuildIR { State state; @@ -14,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; @@ -23,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."); + } } - } else if (isNode(decl,"block")) { - } else throw new Error(); + } + 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) { @@ -487,29 +547,24 @@ public class BuildIR { } ParseNode innerclassnode=pn.getChild("inner_class_declaration"); if (innerclassnode!=null) { - if(state.MGC){ - parseInnerClassDecl(cn,innerclassnode); - return; - } else { - // TODO add version for noraml Java later - throw new Error("Error: inner class in Class " + cn.getSymbol() + " is not supported yet"); - } + parseInnerClassDecl(cn,innerclassnode); + return; } ParseNode enumnode=pn.getChild("enum_declaration"); if (enumnode!=null) { - if(state.MGC){ - parseEnumDecl(cn,enumnode); - return; - } else { - // TODO add version for noraml Java later - throw new Error("Error: enumerated type in Class " + cn.getSymbol() + " is not supported yet"); - } + 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(); } @@ -606,7 +661,7 @@ public class BuildIR { private void parseFieldDecl(ClassDescriptor cn,ParseNode pn) { ParseNode mn=pn.getChild("modifier"); Modifiers m=parseModifiersList(mn); - if((state.MGC) && cn.isInterface()) { + if(cn.isInterface()) { // TODO add version for normal Java later // Can only be PUBLIC or STATIC or FINAL if((m.isAbstract()) || (m.isAtomic()) || (m.isNative()) @@ -620,6 +675,7 @@ public class BuildIR { ParseNode tn=pn.getChild("type"); TypeDescriptor t=parseTypeDescriptor(tn); + assignAnnotationsToType(m,t); ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list"); ParseNodeVector pnv=vn.getChildren(); boolean isglobal=pn.getChild("global")!=null; @@ -636,12 +692,61 @@ public class BuildIR { ParseNode epn=vardecl.getChild("initializer"); ExpressionNode en=null; - if (epn!=null) - en=parseExpression(epn.getFirstChild()); + if (epn!=null) { + en=parseExpression(epn.getFirstChild()); + en.setNumLine(epn.getFirstChild().getLine()); + if(m.isStatic()) { + // for static field, the initializer should be considered as a + // static block + boolean isfirst = false; + MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks"); + if(md == null) { + // the first static block for this class + Modifiers m_i=new Modifiers(); + m_i.addModifier(Modifiers.STATIC); + md = new MethodDescriptor(m_i, "staticblocks", false); + md.setAsStaticBlock(); + isfirst = true; + } + if(isfirst) { + cn.addMethod(md); + } + cn.incStaticBlocks(); + BlockNode bn=new BlockNode(); + NameNode nn=new NameNode(new NameDescriptor(identifier)); + nn.setNumLine(en.getNumLine()); + AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1)); + an.setNumLine(pn.getLine()); + bn.addBlockStatement(new BlockExpressionNode(an)); + if(isfirst) { + state.addTreeCode(md,bn); + } else { + BlockNode obn = state.getMethodBody(md); + for(int ii = 0; ii < bn.size(); ii++) { + BlockStatementNode bsn = bn.get(ii); + obn.addBlockStatement(bsn); + } + state.addTreeCode(md, obn); + bn = null; + } + en = null; + } + } cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal)); } } + + private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type){ + Vector annotations=modifiers.getAnnotations(); + for(int i=0; i