Mercurial > projects > dang
diff basic/Message.d @ 92:771ac63898e2 new_gen
A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 05 May 2008 18:44:20 +0200 |
parents | a49bb982a7b0 |
children | 621cedba53ea |
line wrap: on
line diff
--- a/basic/Message.d Mon May 05 17:07:16 2008 +0200 +++ b/basic/Message.d Mon May 05 18:44:20 2008 +0200 @@ -19,6 +19,13 @@ public import basic.Messages; +enum ExitLevel +{ + Normal = 1, + Lexer = 2, + Parser = 3, +} + class MessageHandler { public: @@ -28,31 +35,36 @@ this.src_mgr = src_mgr; } - Message report(uint opcode, SLoc location, bool fatal = false) + Message report(uint opcode, SLoc location) { - Message m = new Message(opcode, location, src_mgr); + Message m = new Message(opcode, location, src_mgr, this); messages ~= m; - if(fatal) - checkErrors(); return m; } - void checkErrors() + void checkErrors(ExitLevel exitlevel = ExitLevel.Normal) { if(messages.length == 0) return; + if(warnings) + checkWarnings; foreach(m ; messages) if(m.type == MessageType.Error) { Stdout(m).newline; } - exit(1); + exit(exitlevel); } void checkWarnings() { + foreach(m ; messages) + if(m.type == MessageType.Warning) + { + Stdout(m).newline; + } } void showWarnings(bool value) @@ -69,12 +81,13 @@ class Message { - this(int opcode, SLoc location, SourceManager src_mgr) + this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler) { this.src_mgr = src_mgr; this.location = location; args ~= Messages[opcode].message; this.type = Messages[opcode].type; + this.msg_handler = msg_handler; } char[] toString() @@ -95,7 +108,7 @@ char[] line = src_mgr.getLine(location); char[] marks = line.dup; marks[] = ' '; - size_t p = src_mgr.getOffsetToLine(location); + size_t p = src_mgr.getColumn(location); marks[p .. p + t.length] = '^'; msg ~= "\n "; @@ -141,6 +154,12 @@ return arg(sym.type.name ~ " " ~ sym.id.get); } + Message fatal(ExitLevel exitlevel = ExitLevel.Normal) + { + msg_handler.checkErrors(exitlevel); + return this; + } + /* Message loc(SLoc loc) { @@ -154,4 +173,5 @@ char[][] args; SLoc location; SourceManager src_mgr; + MessageHandler msg_handler; }