add enw file
authorbdemsky <bdemsky>
Tue, 19 Apr 2011 00:27:43 +0000 (00:27 +0000)
committerbdemsky <bdemsky>
Tue, 19 Apr 2011 00:27:43 +0000 (00:27 +0000)
Robust/src/IR/Tree/JavaBuilder.java [new file with mode: 0644]

diff --git a/Robust/src/IR/Tree/JavaBuilder.java b/Robust/src/IR/Tree/JavaBuilder.java
new file mode 100644 (file)
index 0000000..e11a677
--- /dev/null
@@ -0,0 +1,68 @@
+package IR.Tree;
+
+import IR.*;
+
+public class JavaBuilder {
+  State state;
+
+  public JavaBuilder(State state) {
+    this.state=state;
+  }
+
+
+  public void build(Vector<String> sourcefiles) {
+    BuildIR bir=new BuildIR(state);
+    TypeUtil tu=new TypeUtil(state, bir);
+
+    for(int i=0;i<sourcefiles.size();i++)
+      loadClass(bir, sourcefiles.get(i));
+
+    
+
+    BuildFlat bf=new BuildFlat(state,tu);
+    bf.buildFlat();
+
+  }
+
+  public static ParseNode readSourceFile(State state, String sourcefile) {
+    try {
+      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=null;
+      try {
+       p=(ParseNode) g./*debug_*/parse().value;
+      } catch (Exception e) {
+       System.err.println("Error parsing file:"+sourcefile);
+       e.printStackTrace();
+       System.exit(-1);
+      }
+      state.addParseNode(p);
+      if (l.numErrors()!=0) {
+       System.out.println("Error parsing "+sourcefile);
+       System.exit(l.numErrors());
+      }
+      state.lines+=l.line_num;
+      return p;
+
+    } catch (Exception e) {
+      throw new Error(e);
+    }
+  }
+
+  public static void loadClass(BuildIR bir, String sourcefile) {
+    try {
+      ParseNode pn=readSourceFile(state, sourcefile);
+      bir.buildtree(pn, null,sourcefile);
+    } catch (Exception e) {
+      System.out.println("Error in sourcefile:"+sourcefile);
+      e.printStackTrace();
+      System.exit(-1);
+    } catch (Error e) {
+      System.out.println("Error in sourcefile:"+sourcefile);
+      e.printStackTrace();
+      System.exit(-1);
+    }
+  }
+}
\ No newline at end of file