diff dang/compiler.d @ 88:eb5b2c719a39 new_gen

Major change to locations, tokens and expressions. A location (now SourceLocation or SLoc) is only 32 bit in size - disadvantage is that it can't find its own text. You have to go through the new SourceManager to do that. This has caused changes to a lot of stuff and removal of DataSource and the old Location Additionally Exp has gotten some location stuff, so we can give proper error messages. Not in Decl and Stmt yet, but thats coming too.
author Anders Halager <halager@gmail.com>
date Sun, 04 May 2008 18:13:46 +0200
parents 9a35a973175a
children a49bb982a7b0
line wrap: on
line diff
--- a/dang/compiler.d	Sun May 04 12:58:02 2008 +0200
+++ b/dang/compiler.d	Sun May 04 18:13:46 2008 +0200
@@ -8,7 +8,7 @@
 import lexer.Lexer,
        parser.Parser;
 
-import misc.DataSource;
+import basic.SourceManager;
 
 import ast.Decl;
 
@@ -76,7 +76,7 @@
     Signal!(Lexer) postLex;
 
     Signal!(Lexer) preParse;
-    Signal!(Decl[], DataSource) postParse;
+    Signal!(Decl[], SourceManager) postParse;
 
     preStart.attach(&checkFiles);
 
@@ -128,7 +128,7 @@
     auto what = options["what-to-do"];
     if (what == "" || what == "gen-llvm")
         postParse.attach(
-            (Decl[] decls, DataSource src) {
+            (Decl[] decls, SourceManager sm) {
                 StopWatch w; w.start;
                 auto llvmGen = new CodeGen();
                 llvmGen.gen(decls, optimize, inline);
@@ -136,7 +136,7 @@
             });
     else if (what == "dot")
         postParse.attach(
-            (Decl[] decls, DataSource src) {
+            (Decl[] decls, SourceManager sm) {
                 StopWatch w; w.start;
                 auto print = new DotPrinter();
                 print.print(decls);
@@ -144,21 +144,24 @@
             });
     else if (what == "code")
         postParse.attach(
-            (Decl[] decls, DataSource src) {
+            (Decl[] decls, SourceManager sm) {
                 StopWatch w; w.start;
-                auto print = new AstPrinter(src);
+                auto print = new AstPrinter(sm);
                 print.print(decls);
                 timings ~= Measurement("Converting AST to text", w.stop);
             });
 
+    SourceManager src_mgr = new SourceManager;
+
     StopWatch total;
     total.start;
-    foreach(file ; filesToHandle)
+    foreach (file; filesToHandle)
     {
         preLex(file);
 
-        auto src = DataSource(file);
-        auto lexer = new Lexer(src);
+        auto start = src_mgr.addFile(file);
+        Stdout(file).newline;
+        auto lexer = new Lexer(start, src_mgr);
         postLex(lexer);
 
         preParse(lexer);
@@ -166,7 +169,8 @@
         StopWatch watch;
         watch.start;
         auto parser = new Parser;
-        auto decls = cast(Decl[])parser.parse(lexer, new AstAction);
+        auto action = new AstAction(src_mgr);
+        auto decls = cast(Decl[])parser.parse(src_mgr, lexer, action);
         timings ~= Measurement("Lex + Parse", watch.stop);
 
         StopWatch watch2;
@@ -191,7 +195,7 @@
         timings ~= Measurement("  - Extracting declarations", declarations);
         timings ~= Measurement("  - Making casts explicit", implicit_casts);
 
-        postParse(decls, src);
+        postParse(decls, src_mgr);
     }
     timings ~= Measurement("Total", total.stop);