diff basic/Message.d @ 179:2a1a635bd531

Changes the way messages can be displayed. Also added a toString to DType's for type printing.
author Anders Johnsen <skabet@gmail.com>
date Fri, 25 Jul 2008 01:21:07 +0200
parents 6c5a3c0bb4fb
children 75d0544ddc45
line wrap: on
line diff
--- a/basic/Message.d	Thu Jul 24 23:36:38 2008 +0200
+++ b/basic/Message.d	Fri Jul 25 01:21:07 2008 +0200
@@ -42,9 +42,16 @@
         return m;
     }
 
-    Message report(uint opcode, SLoc location1, SLoc location2)
+    Message report(uint opcode, SourceRange[] ranges, SourceLocation[] locs)
     {
-        Message m = new Message(opcode, location1, location2, src_mgr, this);
+        Message m = new Message(opcode, ranges, locs, src_mgr, this);
+        messages ~= m;
+        return m;
+    }
+
+    Message report(uint opcode, SLoc location1, SLoc location2, SLoc location3 = SLoc.Invalid)
+    {
+        Message m = new Message(opcode, [SourceRange(location1, location2)][], [location3][], src_mgr, this);
         messages ~= m;
         return m;
     }
@@ -91,17 +98,23 @@
     this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler)
     {
         this.src_mgr = src_mgr;
-        this.location = location;
+        this.interests ~= location;
         args ~= Messages[opcode].message;
         this.type = Messages[opcode].type;
         this.msg_handler = msg_handler;
     }
 
-    this(int opcode, SLoc location, SLoc end, SourceManager src_mgr, MessageHandler msg_handler)
+    this(int opcode, SourceRange[] locs, SLoc[] interests,
+            SourceManager src_mgr, MessageHandler msg_handler)
+    in
+    {
+        assert(locs.length + interests.length, "Atleast one location is requiret for a mark");
+    }
+    body
     {
         this.src_mgr = src_mgr;
-        this.location = location;
-        this.end = end;
+        this.locs = locs;
+        this.interests = interests;
         args ~= Messages[opcode].message;
         this.type = Messages[opcode].type;
         this.msg_handler = msg_handler;
@@ -113,16 +126,22 @@
         char[256] tmp = void;
         char[] msg = layout(tmp, args);
 
+        SLoc location;
+        if (interests.length)
+            location = interests[0];
+        else
+            location = locs[0].begin;
+
         int len = 0;
         if(!haveEnd)
         {
-            Lexer l = new Lexer(location, src_mgr, new MessageHandler(src_mgr));
+            Lexer l = new Lexer(interests[0], src_mgr, new MessageHandler(src_mgr));
 
             Token t = l.next;
             len = t.length;
         }
-        else
-            len = end - location;
+//        else
+  //          len = end - location;
         
         if (src_mgr.getRawData(location).length > 0)
             msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg;
@@ -133,8 +152,18 @@
         char[] line = src_mgr.getLine(location);
         char[] marks = line.dup;
         marks[] = ' ';
-        size_t p = src_mgr.getColumn(location);
-        marks[p .. p + len] = '^';
+
+        foreach (s ; locs)
+        {
+            size_t p = src_mgr.getColumn(s.begin);
+            marks[p .. p + (s.end-s.begin)] = '~';
+        }
+
+        foreach (interest ; interests)
+        {
+            size_t i = src_mgr.getColumn(interest);
+            marks[i] = '^';
+        }
 
         msg ~= "\n    ";
         msg ~= line;
@@ -191,7 +220,8 @@
     MessageType type;
 private:
     char[][] args;
-    SLoc location, end;
+    SourceRange[] locs;
+    SLoc[] interests;
     bool haveEnd;
     SourceManager src_mgr;
     MessageHandler msg_handler;