comparison src/basic/Message.d @ 207:e0551773a005

Added the correct version.
author Anders Johnsen <skabet@gmail.com>
date Tue, 12 Aug 2008 18:19:34 +0200
parents d3c148ca429b
children 42e663451371
comparison
equal deleted inserted replaced
206:d3c148ca429b 207:e0551773a005
8 import tango.stdc.stdlib; 8 import tango.stdc.stdlib;
9 9
10 import llvm.type; 10 import llvm.type;
11 11
12 import lexer.Token, 12 import lexer.Token,
13 lexer.Lexer; 13 lexer.Lexer,
14 sema.DType;
14 15
15 import basic.SourceLocation, 16 import basic.SourceLocation,
16 basic.SourceManager; 17 basic.SourceManager;
17 18
18 public import basic.Messages; 19 public import basic.Messages;
39 Message m = new Message(opcode, location, src_mgr, this); 40 Message m = new Message(opcode, location, src_mgr, this);
40 messages ~= m; 41 messages ~= m;
41 return m; 42 return m;
42 } 43 }
43 44
45 Message report(uint opcode, SourceRange[] ranges, SourceLocation[] locs)
46 {
47 Message m = new Message(opcode, ranges, locs, src_mgr, this);
48 messages ~= m;
49 return m;
50 }
51
52 Message report(uint opcode, SLoc location1, SLoc location2, SLoc location3 = SLoc.Invalid)
53 {
54 Message m = new Message(opcode, [SourceRange(location1, location2)][], [location3][], src_mgr, this);
55 messages ~= m;
56 return m;
57 }
58
44 void checkErrors(ExitLevel exitlevel = ExitLevel.Normal) 59 void checkErrors(ExitLevel exitlevel = ExitLevel.Normal)
45 { 60 {
46 if(messages.length == 0) 61 if(messages.length == 0)
47 return; 62 return;
48 63
81 { 96 {
82 97
83 this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler) 98 this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler)
84 { 99 {
85 this.src_mgr = src_mgr; 100 this.src_mgr = src_mgr;
86 this.location = location; 101 this.interests ~= location;
87 args ~= Messages[opcode].message; 102 args ~= Messages[opcode].message;
88 this.type = Messages[opcode].type; 103 this.type = Messages[opcode].type;
89 this.msg_handler = msg_handler; 104 this.msg_handler = msg_handler;
90 } 105 }
91 106
107 this(int opcode, SourceRange[] locs, SLoc[] interests,
108 SourceManager src_mgr, MessageHandler msg_handler)
109 in
110 {
111 assert(locs.length + interests.length, "Atleast one location is requiret for a mark");
112 }
113 body
114 {
115 this.src_mgr = src_mgr;
116 this.locs = locs;
117 this.interests = interests;
118 args ~= Messages[opcode].message;
119 this.type = Messages[opcode].type;
120 this.msg_handler = msg_handler;
121 haveEnd = true;
122 }
123
92 char[] toString() 124 char[] toString()
93 { 125 {
94 char[256] tmp = void; 126 char[256] tmp = void;
95 char[] msg = layout(tmp, args); 127 char[] msg = layout(tmp, args);
96 128
97 Lexer l = new Lexer(location, src_mgr, new MessageHandler(src_mgr)); 129 SLoc location;
98 130 if (interests.length)
99 Token t = l.next; 131 location = interests[0];
132 else
133 location = locs[0].begin;
134
135 int len = 0;
136 if(!haveEnd)
137 {
138 Lexer l = new Lexer(interests[0], src_mgr, new MessageHandler(src_mgr));
139
140 Token t = l.next;
141 len = t.length;
142 }
143 // else
144 // len = end - location;
100 145
101 if (src_mgr.getRawData(location).length > 0) 146 if (src_mgr.getRawData(location).length > 0)
102 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg; 147 msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg;
103 else 148 else
104 msg = msg.dup; 149 msg = msg.dup;
105 150
106 151
107 char[] line = src_mgr.getLine(location); 152 char[] line = src_mgr.getLine(location);
108 char[] marks = line.dup; 153 char[] marks = line.dup;
109 marks[] = ' '; 154 marks[] = ' ';
110 size_t p = src_mgr.getColumn(location); 155
111 marks[p .. p + t.length] = '^'; 156 foreach (s ; locs)
157 {
158 size_t p = src_mgr.getColumn(s.begin);
159 marks[p .. p + (s.end-s.begin)] = interests.length ? '~' : '^';
160 }
161
162 foreach (interest ; interests)
163 {
164 size_t i = src_mgr.getColumn(interest);
165 marks[i] = '^';
166 }
112 167
113 msg ~= "\n "; 168 msg ~= "\n ";
114 msg ~= line; 169 msg ~= line;
115 msg ~= "\n "; 170 msg ~= "\n ";
116 msg ~= marks; 171 msg ~= marks;
118 return msg; 173 return msg;
119 } 174 }
120 175
121 Message arg(char[] s) 176 Message arg(char[] s)
122 { 177 {
123 if (args.length == 11) 178 if (args.length > 10)
124 throw new Exception("Sorry, errors only support up to 10 args"); 179 throw new Exception("Sorry, errors only support up to 10 args");
125 args ~= s; 180 args ~= s;
126 return this; 181 return this;
127 } 182 }
128 183
138 Message arg(char c) 193 Message arg(char c)
139 { 194 {
140 return arg([c]); 195 return arg([c]);
141 } 196 }
142 197
198 Message arg(DType[] types)
199 {
200 char[][] res;
201 foreach (type; types)
202 res ~= type.name();
203 return arg(res);
204 }
205
143 Message fatal(ExitLevel exitlevel = ExitLevel.Normal) 206 Message fatal(ExitLevel exitlevel = ExitLevel.Normal)
144 { 207 {
145 msg_handler.checkErrors(exitlevel); 208 msg_handler.checkErrors(exitlevel);
146 return this; 209 return this;
147 } 210 }
155 */ 218 */
156 219
157 MessageType type; 220 MessageType type;
158 private: 221 private:
159 char[][] args; 222 char[][] args;
160 SLoc location; 223 SourceRange[] locs;
224 SLoc[] interests;
225 bool haveEnd;
161 SourceManager src_mgr; 226 SourceManager src_mgr;
162 MessageHandler msg_handler; 227 MessageHandler msg_handler;
228 Token t;
163 } 229 }