changeset 514:6ddff941862a

Added new error classes.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 14 Dec 2007 19:32:07 +0100
parents 6160ab7b1816
children 7cb97346bc6f
files trunk/src/dil/Information.d trunk/src/dil/Lexer.d trunk/src/dil/Parser.d trunk/src/dil/Scope.d
diffstat 4 files changed, 61 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- 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);
+  }
+}
--- 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()
--- 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.
--- 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);
   }
 }