Author: lattner Date: Mon Nov 19 01:43:52 2007 New Revision: 44227 URL: http://llvm.org/viewvc/llvm-project?rev=44227&view=rev Log: Record the start of the current token, for use in error reporting.
Modified: llvm/trunk/utils/TableGen/TGLexer.cpp llvm/trunk/utils/TableGen/TGLexer.h Modified: llvm/trunk/utils/TableGen/TGLexer.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGLexer.cpp?rev=44227&r1=44226&r2=44227&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/TGLexer.cpp (original) +++ llvm/trunk/utils/TableGen/TGLexer.cpp Mon Nov 19 01:43:52 2007 @@ -27,6 +27,7 @@ TGLexer::TGLexer(MemoryBuffer *StartBuf) : CurLineNo(1), CurBuf(StartBuf) { CurPtr = CurBuf->getBufferStart(); + TokStart = 0; } TGLexer::~TGLexer() { @@ -76,8 +77,7 @@ // Print out the line. cerr << std::string(LineStart, LineEnd) << "\n"; // Print out spaces before the carat. - const char *Pos = LineStart; - while (Pos != ErrorLoc) + for (const char *Pos = LineStart; Pos != ErrorLoc; ++Pos) cerr << (*Pos == '\t' ? '\t' : ' '); cerr << "^\n"; } @@ -122,6 +122,7 @@ } int TGLexer::LexToken() { + TokStart = CurPtr; // This always consumes at least one character. int CurChar = getNextChar(); @@ -238,11 +239,10 @@ /// comes next and enter the include. bool TGLexer::LexInclude() { // The token after the include must be a string. - const char *TokStart = CurPtr-7; int Tok = LexToken(); if (Tok == YYERROR) return true; if (Tok != STRVAL) { - PrintError(TokStart, "Expected filename after include"); + PrintError(getTokenStart(), "Expected filename after include"); return true; } @@ -260,7 +260,8 @@ } if (NewBuf == 0) { - PrintError(TokStart, "Could not find include file '" + Filename + "'"); + PrintError(getTokenStart(), + "Could not find include file '" + Filename + "'"); return true; } Modified: llvm/trunk/utils/TableGen/TGLexer.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGLexer.h?rev=44227&r1=44226&r2=44227&view=diff ============================================================================== --- llvm/trunk/utils/TableGen/TGLexer.h (original) +++ llvm/trunk/utils/TableGen/TGLexer.h Mon Nov 19 01:43:52 2007 @@ -40,6 +40,7 @@ // IncludeDirectories - This is the list of directories we should search for // include files in. std::vector<std::string> IncludeDirectories; + const char *TokStart; public: TGLexer(MemoryBuffer *StartBuf); ~TGLexer(); @@ -50,7 +51,10 @@ int LexToken(); - void PrintError(const char *Loc, const std::string &Msg) const; + typedef const char* LocationTy; + LocationTy getTokenStart() const { return TokStart; } + + void PrintError(LocationTy Loc, const std::string &Msg) const; std::ostream &err() const; void PrintIncludeStack(std::ostream &OS) const; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits