# HG changeset patch # User Aziz K?ksal # Date 1200676694 -3600 # Node ID e7811328e6c70961f1add9ab1c770578c5b66e1f # Parent 6a934ff01b68868f7758570c57a1eff8a02c00f6 Made Token.getLocation() a template function and added two aliases. diff -r 6a934ff01b68 -r e7811328e6c7 trunk/src/dil/lexer/Token.d --- 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; diff -r 6a934ff01b68 -r e7811328e6c7 trunk/src/dil/parser/Parser.d --- 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; diff -r 6a934ff01b68 -r e7811328e6c7 trunk/src/dil/semantic/Pass1.d --- 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(); diff -r 6a934ff01b68 -r e7811328e6c7 trunk/src/dil/semantic/Scope.d --- 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); } diff -r 6a934ff01b68 -r e7811328e6c7 trunk/src/dil/translator/German.d --- 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); }