Changes to allow multiple source files & library support
authorbdemsky <bdemsky>
Wed, 5 Apr 2006 20:38:42 +0000 (20:38 +0000)
committerbdemsky <bdemsky>
Wed, 5 Apr 2006 20:38:42 +0000 (20:38 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/MethodDescriptor.java
Robust/src/IR/State.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/Modifiers.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeUtil.java
Robust/src/Main/Main.java

index fd2eff59dec0410f02a5e0467d9613ac95752dee..30b6129102d93db2993222769ad972844a2b4a26 100644 (file)
@@ -84,7 +84,8 @@ public class BuildCode {
                /* Classify parameters */
                MethodDescriptor md=(MethodDescriptor)methodit.next();
                FlatMethod fm=state.getMethodFlat(md);
-               generateFlatMethod(fm,outmethod);
+               if (!md.getModifiers().isNative())
+                   generateFlatMethod(fm,outmethod);
            }
        }
        outmethod.close();
index 211448f976ca0aaae62a7f71f86e0758af7f4236..195d707688900d21abf1785969d97e10c2e9749d 100644 (file)
@@ -32,6 +32,11 @@ public class MethodDescriptor extends Descriptor {
        thisvd=null;
     }
 
+
+    public Modifiers getModifiers() {
+       return modifier;
+    }
+    
     public boolean matches(MethodDescriptor md) {
        /* Check the name */
        if (!identifier.equals(md.identifier))
index a83b1af73e49f989fc3c014597cc040e1bf7d2e9..83ec6f464432ad473782cc7e7bf3b851096eaa8c 100644 (file)
@@ -5,15 +5,21 @@ import IR.*;
 import java.util.*;
 
 public class State {
-    public State(ParseNode parsetree) {
-       this.parsetree=parsetree;
+    public String main;
+
+    public State() {
        this.classes=new SymbolTable();
        this.treemethodmap=new Hashtable();
        this.flatmethodmap=new Hashtable();
+       this.parsetrees=new HashSet();
+    }
+
+    public void addParseNode(ParseNode parsetree) {
+       parsetrees.add(parsetree);
     }
 
     public SymbolTable classes;
-    public ParseNode parsetree;
+    public Set parsetrees;
     public Hashtable treemethodmap;
     public Hashtable flatmethodmap;
 
index 472254b6dbf47869e1158a599312d88069940994..b716a7bab0a2bef1ea738c9060240617b3eae700 100644 (file)
@@ -1,6 +1,7 @@
 package IR.Tree;
 import IR.*;
-import java.util.Vector;
+import java.util.*;
+
 
 public class BuildIR {
     State state;
@@ -8,8 +9,10 @@ public class BuildIR {
        this.state=state;
     }
     public void buildtree() {
-       ParseNode pn=state.parsetree;
-       parseFile(pn);
+       for(Iterator it=state.parsetrees.iterator();it.hasNext();) {
+           ParseNode pn=(ParseNode)it.next();
+           parseFile(pn);
+       }
     }
 
     /** Parse the classes in this file */
@@ -35,6 +38,9 @@ public class BuildIR {
                ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
                NameDescriptor nd=parseName(snn);
                cn.setSuper(nd.toString());
+           } else {
+               if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
+                   cn.setSuper(TypeUtil.ObjectClass);
            }
            cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
            parseClassBody(cn, pn.getChild("classbody"));
index f3b3af74af3d4da8377c01be55b51cfc4100bf8c..0fcb74ad0f5079d299f23d2015e652590abf2884 100644 (file)
@@ -27,6 +27,10 @@ public class Modifiers {
        return ((value&STATIC)!=0);
     }
 
+    public boolean isNative() {
+       return ((value&NATIVE)!=0);
+    }
+
     public String toString() {
        String st="";
        if ((value&PUBLIC)!=0)
index 6e777c07e37ae8968026574beb6592bca6d6e401..33889fdb3cb790f7dd0b72c6a165e4bb927a7997 100644 (file)
@@ -251,13 +251,15 @@ public class SemanticCheck {
            ln.setType(new TypeDescriptor(TypeDescriptor.LONG));
        } else if (o instanceof Float) {
            ln.setType(new TypeDescriptor(TypeDescriptor.FLOAT));
+       } else if (o instanceof Boolean) {
+           ln.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
        } else if (o instanceof Double) {
            ln.setType(new TypeDescriptor(TypeDescriptor.DOUBLE));
        } else if (o instanceof Character) {
            ln.setType(new TypeDescriptor(TypeDescriptor.CHAR));
        } else if (o instanceof String) {
            ln.setType(new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass)));
-       } 
+       }
 
        if (td!=null)
            if (!typeutil.isSuperorType(td,ln.getType()))
index 2cb7396803524c5d9ed4d1ba92c9fa08728b763e..3a3cf8d84ae976719081a1c92c231f93852967f9 100644 (file)
@@ -3,6 +3,7 @@ import java.util.*;
 
 public class TypeUtil {
     public static final String StringClass="String";
+    public static final String ObjectClass="Object";
     State state;
     Hashtable supertable;
     Hashtable subclasstable;
index 51e69cccbcf6acf76891f6393c74eb85a6dc6ee8..dea270a0bc66257aebc86c9b524fc3e45a8c884d 100644 (file)
@@ -13,30 +13,38 @@ import IR.TypeUtil;
 
 public class Main {
   public static void main(String args[]) throws Exception {
+      String ClassLibraryPrefix="./ClassLibrary/";
       if (args.length<1) {
          System.out.println("Must input source file");
          System.exit(-1);
       }
-      for(int i=1;i<args.length;i++) {
+      State state=new State();
+      
+      for(int i=0;i<args.length;i++) {
          String option=args[i];
          if (option.equals("-precise"))
              IR.Flat.BuildCode.GENERATEPRECISEGC=true;
          else if (option.equals("-dir"))
              IR.Flat.BuildCode.PREFIX=args[++i]+"/";
+         else if (option.equals("-classlibrary"))
+             ClassLibraryPrefix=args[++i]+"/";
+         else if (option.equals("-mainclass"))
+             state.main=args[++i];
          else if (option.equals("-help")) {
+             System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
              System.out.println("-dir outputdirectory -- output code in outputdirectory");
+             System.out.println("-mainclass -- main function to call");
              System.out.println("-precise -- use precise garbage collection");
+
              System.out.println("-help -- print out help");
              System.exit(0);
+         } else {
+             readSourceFile(state, args[i]);
          }
       }
-      Reader fr = new BufferedReader(new FileReader(args[0]));
-      Lex.Lexer l = new Lex.Lexer(fr);
-      java_cup.runtime.lr_parser g;
-      g = new Parse.Parser(l);
-      ParseNode p=(ParseNode) g./*debug_*/parse().value;
-      State state=new State(p);
       
+      readSourceFile(state, ClassLibraryPrefix+"Object.java");
+
       BuildIR bir=new BuildIR(state);
       bir.buildtree();
       
@@ -50,7 +58,19 @@ public class Main {
       
       BuildCode bc=new BuildCode(state, bf.getMap(), tu);
       bc.buildCode();
-      
-      System.exit(l.numErrors());
+      System.exit(0);
   }
+    
+    private static void readSourceFile(State state, String sourcefile) throws Exception {
+       Reader fr = new BufferedReader(new FileReader(sourcefile));
+       Lex.Lexer l = new Lex.Lexer(fr);
+       java_cup.runtime.lr_parser g;
+       g = new Parse.Parser(l);
+       ParseNode p=(ParseNode) g./*debug_*/parse().value;
+       state.addParseNode(p);
+       if (l.numErrors()!=0) {
+           System.out.println("Error parsing Object.java");
+           System.exit(l.numErrors());
+       }
+    }
 }