TGLexer::TGLexer(MemoryBuffer *StartBuf) : CurLineNo(1), CurBuf(StartBuf) {
CurPtr = CurBuf->getBufferStart();
+ TokStart = 0;
}
TGLexer::~TGLexer() {
// 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";
}
}
int TGLexer::LexToken() {
+ TokStart = CurPtr;
// This always consumes at least one character.
int CurChar = getNextChar();
/// 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;
}
}
if (NewBuf == 0) {
- PrintError(TokStart, "Could not find include file '" + Filename + "'");
+ PrintError(getTokenStart(),
+ "Could not find include file '" + Filename + "'");
return true;
}
// 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();
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;