changeset 675:e7811328e6c7

Made Token.getLocation() a template function and added two aliases.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 18 Jan 2008 18:18:14 +0100
parents 6a934ff01b68
children c4e3a34e40f1
files trunk/src/dil/lexer/Token.d trunk/src/dil/parser/Parser.d trunk/src/dil/semantic/Pass1.d trunk/src/dil/semantic/Scope.d trunk/src/dil/translator/German.d
diffstat 5 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/lexer/Token.d	Fri Jan 18 17:25:37 2008 +0100
+++ b/trunk/src/dil/lexer/Token.d	Fri Jan 18 18:18:14 2008 +0100
@@ -193,14 +193,22 @@
   }
 
   /// Returns the Location of this token.
-  Location getLocation()
+  Location getLocation(bool realLocation)()
   {
     auto search_t = this.prev;
     // Find previous newline token.
     while (search_t.type != TOK.Newline)
       search_t = search_t.prev;
-    auto filePath  = search_t.newline.filePaths.setPath;
-    auto lineNum   = search_t.newline.oriLineNum - search_t.newline.setLineNum;
+    static if (realLocation)
+    {
+      auto filePath  = search_t.newline.filePaths.oriPath;
+      auto lineNum   = search_t.newline.oriLineNum;
+    }
+    else
+    {
+      auto filePath  = search_t.newline.filePaths.setPath;
+      auto lineNum   = search_t.newline.oriLineNum - search_t.newline.setLineNum;
+    }
     auto lineBegin = search_t.end;
     // Determine actual line begin and line number.
     while (1)
@@ -227,6 +235,9 @@
     return new Location(filePath, lineNum, lineBegin, this.start);
   }
 
+  alias getLocation!(true) getRealLocation;
+  alias getLocation!(false) getErrorLocation;
+
   uint lineCount()
   {
     uint count = 1;
--- a/trunk/src/dil/parser/Parser.d	Fri Jan 18 17:25:37 2008 +0100
+++ b/trunk/src/dil/parser/Parser.d	Fri Jan 18 18:18:14 2008 +0100
@@ -4128,7 +4128,7 @@
       ++errorCount;
       return;
     }
-    auto location = token.getLocation();
+    auto location = token.getErrorLocation();
     auto msg = Format(_arguments, _argptr, formatMsg);
     auto error = new ParserError(location, msg);
     errors ~= error;
--- a/trunk/src/dil/semantic/Pass1.d	Fri Jan 18 17:25:37 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Fri Jan 18 18:18:14 2008 +0100
@@ -55,7 +55,7 @@
 
   void error(Token* token, char[] formatMsg, ...)
   {
-    auto location = token.getLocation();
+    auto location = token.getErrorLocation();
     auto msg = Format(_arguments, _argptr, formatMsg);
     modul.infoMan ~= new SemanticError(location, msg);
   }
@@ -440,7 +440,7 @@
      error(scop, MSG.MixinArgumentMustBeString);
     else
     {
-      auto loc = this.begin.getLocation();
+      auto loc = this.begin.getErrorLocation();
       auto filePath = loc.filePath;
       auto parser = new_ExpressionParser(strExpr.getString(), filePath, scop.infoMan);
       expr = parser.parse();
--- a/trunk/src/dil/semantic/Scope.d	Fri Jan 18 17:25:37 2008 +0100
+++ b/trunk/src/dil/semantic/Scope.d	Fri Jan 18 18:18:14 2008 +0100
@@ -37,7 +37,7 @@
     auto sym2 = symbol.lookup(ident);
     if (sym2)
     {
-      auto loc = sym2.node.begin.getLocation();
+      auto loc = sym2.node.begin.getErrorLocation();
       auto locString = Format("{}({},{})", loc.filePath, loc.lineNum, loc.colNum);
       error(sym.node.begin, MSG.DeclConflictsWithDecl, ident.str, locString);
     }
@@ -53,7 +53,7 @@
     auto sym = symbol.lookup(var.ident);
     if (sym)
     {
-      auto loc = sym.node.begin.getLocation();
+      auto loc = sym.node.begin.getErrorLocation();
       auto locString = Format("{}({},{})", loc.filePath, loc.lineNum, loc.colNum);
       error(var.node.begin, MSG.VariableConflictsWithDecl, var.ident.str, locString);
     }
@@ -118,13 +118,13 @@
 
   void error(Token* token, MID mid)
   {
-    auto location = token.getLocation();
+    auto location = token.getErrorLocation();
     infoMan ~= new SemanticError(location, GetMsg(mid));
   }
 
   void error(Token* token, char[] formatMsg, ...)
   {
-    auto location = token.getLocation();
+    auto location = token.getErrorLocation();
     auto msg = Format(_arguments, _argptr, formatMsg);
     infoMan ~= new SemanticError(location, msg);
   }
--- a/trunk/src/dil/translator/German.d	Fri Jan 18 17:25:37 2008 +0100
+++ b/trunk/src/dil/translator/German.d	Fri Jan 18 18:18:14 2008 +0100
@@ -101,7 +101,7 @@
 
   void printLoc(Node node)
   {
-    auto loc = node.begin.getLocation();
+    auto loc = node.begin.getRealLocation();
     put(indent).formatln("@({},{})",/+ loc.filePath,+/ loc.lineNum, loc.colNum);
   }