# HG changeset patch # User Aziz K?ksal # Date 1197657127 -3600 # Node ID 6ddff941862aa0f08a5d0f78fab2edc3e44112cc # Parent 6160ab7b1816fda24e45757fb2a5d0ee64f338ca Added new error classes. diff -r 6160ab7b1816 -r 6ddff941862a trunk/src/dil/Information.d --- a/trunk/src/dil/Information.d Fri Dec 14 19:08:21 2007 +0100 +++ b/trunk/src/dil/Information.d Fri Dec 14 19:32:07 2007 +0100 @@ -3,31 +3,31 @@ License: GPL3 +/ module dil.Information; + import dil.Messages; import common; public import dil.Location; -enum InfoType -{ - Lexer, - Parser, - Semantic -} - class Information { - MID id; - InfoType type; + +} + +class InformationManager +{ + Information[] info; +} + +class Problem : Information +{ Location location; - uint column; + uint column; /// Cache variable for column. string message; - this(InfoType type, MID id, Location location, string message) + this(Location location, string message) { assert(location !is null); - this.id = id; - this.type = type; this.location = location; this.message = message; } @@ -37,11 +37,13 @@ return this.message; } + /// Returns the line of code. size_t loc() { return location.lineNum; } + /// Returns the column. size_t col() { if (column == 0) @@ -49,13 +51,49 @@ return column; } + /// Returns the file path. string filePath() { return location.filePath; } } -class InformationManager +class Warning : Problem +{ + this(Location location, string message) + { + super(location, message); + } +} + +class Error : Problem +{ + this(Location location, string message) + { + super(location, message); + } +} + +class LexerError : Error { - Information[] info; + this(Location location, string message) + { + super(location, message); + } } + +class ParserError : Error +{ + this(Location location, string message) + { + super(location, message); + } +} + +class SemanticError : Error +{ + this(Location location, string message) + { + super(location, message); + } +} diff -r 6160ab7b1816 -r 6ddff941862a trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Fri Dec 14 19:08:21 2007 +0100 +++ b/trunk/src/dil/Lexer.d Fri Dec 14 19:32:07 2007 +0100 @@ -35,7 +35,7 @@ char* end; /// Points one character past the end of the source text. // Members used for error messages: - Information[] errors; + LexerError[] errors; /// Always points to the beginning of the current line. char* lineBegin; // Token* newline; /// Current newline token. @@ -2385,7 +2385,7 @@ lineNum = this.errorLineNumber(lineNum); auto location = new Location(errorPath, lineNum, lineBegin, columnPos); auto msg = Format(_arguments, _argptr, GetMsg(mid)); - errors ~= new Information(InfoType.Lexer, mid, location, msg); + errors ~= new LexerError(location, msg); } Token* getTokens() diff -r 6160ab7b1816 -r 6ddff941862a trunk/src/dil/Parser.d --- a/trunk/src/dil/Parser.d Fri Dec 14 19:08:21 2007 +0100 +++ b/trunk/src/dil/Parser.d Fri Dec 14 19:32:07 2007 +0100 @@ -27,7 +27,7 @@ Token* token; /// Current non-whitespace token. Token* prevToken; /// Previous non-whitespace token. - Information[] errors; + ParserError[] errors; ImportDeclaration[] imports; /// ImportDeclarations in the source text. @@ -4421,15 +4421,15 @@ /// Reports an error that has no message ID yet. void error(Token* token, char[] formatMsg, ...) { - error_(token, MID.min, formatMsg, _arguments, _argptr); + error_(token, formatMsg, _arguments, _argptr); } void error(MID mid, ...) { - error_(this.token, mid, GetMsg(mid), _arguments, _argptr); + error_(this.token, GetMsg(mid), _arguments, _argptr); } - void error_(Token* token, MID mid, char[] formatMsg, TypeInfo[] _arguments, void* _argptr) + void error_(Token* token, char[] formatMsg, TypeInfo[] _arguments, void* _argptr) { if (trying) { @@ -4438,7 +4438,7 @@ } auto location = token.getLocation(); auto msg = Format(_arguments, _argptr, formatMsg); - errors ~= new Information(InfoType.Parser, mid, location, msg); + errors ~= new ParserError(location, msg); } /// Collection of error messages with no MID yet. diff -r 6160ab7b1816 -r 6ddff941862a trunk/src/dil/Scope.d --- a/trunk/src/dil/Scope.d Fri Dec 14 19:08:21 2007 +0100 +++ b/trunk/src/dil/Scope.d Fri Dec 14 19:32:07 2007 +0100 @@ -58,8 +58,7 @@ void error(Token* token, MID mid) { auto location = token.getLocation(); - auto msg = GetMsg(mid); - auto error = new Information(InfoType.Semantic, mid, location, msg); + auto error = new SemanticError(location, GetMsg(mid)); // infoMan.add(error); } }