Mercurial > projects > dang
diff 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 |
line wrap: on
line diff
--- a/src/basic/Message.d Tue Aug 12 18:14:56 2008 +0200 +++ b/src/basic/Message.d Tue Aug 12 18:19:34 2008 +0200 @@ -10,7 +10,8 @@ import llvm.type; import lexer.Token, - lexer.Lexer; + lexer.Lexer, + sema.DType; import basic.SourceLocation, basic.SourceManager; @@ -41,6 +42,20 @@ return m; } + Message report(uint opcode, SourceRange[] ranges, SourceLocation[] locs) + { + 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; + } + void checkErrors(ExitLevel exitlevel = ExitLevel.Normal) { if(messages.length == 0) @@ -83,20 +98,50 @@ 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, 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.locs = locs; + this.interests = interests; + args ~= Messages[opcode].message; + this.type = Messages[opcode].type; + this.msg_handler = msg_handler; + haveEnd = true; + } + char[] toString() { char[256] tmp = void; char[] msg = layout(tmp, args); - Lexer l = new Lexer(location, src_mgr, new MessageHandler(src_mgr)); + SLoc location; + if (interests.length) + location = interests[0]; + else + location = locs[0].begin; - Token t = l.next; + int len = 0; + if(!haveEnd) + { + Lexer l = new Lexer(interests[0], src_mgr, new MessageHandler(src_mgr)); + + Token t = l.next; + len = t.length; + } +// else + // len = end - location; if (src_mgr.getRawData(location).length > 0) msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg; @@ -107,8 +152,18 @@ char[] line = src_mgr.getLine(location); char[] marks = line.dup; marks[] = ' '; - size_t p = src_mgr.getColumn(location); - marks[p .. p + t.length] = '^'; + + foreach (s ; locs) + { + size_t p = src_mgr.getColumn(s.begin); + marks[p .. p + (s.end-s.begin)] = interests.length ? '~' : '^'; + } + + foreach (interest ; interests) + { + size_t i = src_mgr.getColumn(interest); + marks[i] = '^'; + } msg ~= "\n "; msg ~= line; @@ -120,7 +175,7 @@ Message arg(char[] s) { - if (args.length == 11) + if (args.length > 10) throw new Exception("Sorry, errors only support up to 10 args"); args ~= s; return this; @@ -140,6 +195,14 @@ return arg([c]); } + Message arg(DType[] types) + { + char[][] res; + foreach (type; types) + res ~= type.name(); + return arg(res); + } + Message fatal(ExitLevel exitlevel = ExitLevel.Normal) { msg_handler.checkErrors(exitlevel); @@ -157,7 +220,10 @@ MessageType type; private: char[][] args; - SLoc location; + SourceRange[] locs; + SLoc[] interests; + bool haveEnd; SourceManager src_mgr; MessageHandler msg_handler; + Token t; }