From: Saleem Abdulrasool Date: Sun, 9 Feb 2014 23:29:24 +0000 (+0000) Subject: MCParser: add a single token lookahead X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a879fab3b31536cb9a8077c7c0850971e04aef60;p=platform%2Fupstream%2Fllvm.git MCParser: add a single token lookahead Some of the more complex directive and macro handling for GAS compatibility requires lookahead. Add a single token lookahead in the MCAsmLexer. llvm-svn: 201058 --- diff --git a/llvm/include/llvm/MC/MCParser/AsmLexer.h b/llvm/include/llvm/MC/MCParser/AsmLexer.h index 1b3ab57..89677a9 100644 --- a/llvm/include/llvm/MC/MCParser/AsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/AsmLexer.h @@ -47,6 +47,8 @@ public: virtual StringRef LexUntilEndOfStatement(); StringRef LexUntilEndOfLine(); + virtual const AsmToken peekTok(bool ShouldSkipSpace = true); + bool isAtStartOfComment(char Char); bool isAtStatementSeparator(const char *Ptr); diff --git a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h index ceba3f0..e3d4181 100644 --- a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h @@ -160,6 +160,9 @@ public: return CurTok; } + /// peekTok - Look ahead at the next token to be lexed. + virtual const AsmToken peekTok(bool ShouldSkipSpace = true) = 0; + /// getErrLoc - Get the current error location const SMLoc &getErrLoc() { return ErrLoc; diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp index 88f1761..a3b68d8 100644 --- a/llvm/lib/MC/MCParser/AsmLexer.cpp +++ b/llvm/lib/MC/MCParser/AsmLexer.cpp @@ -439,6 +439,28 @@ StringRef AsmLexer::LexUntilEndOfLine() { return StringRef(TokStart, CurPtr-TokStart); } +const AsmToken AsmLexer::peekTok(bool ShouldSkipSpace) { + const char *SavedTokStart = TokStart; + const char *SavedCurPtr = CurPtr; + bool SavedAtStartOfLine = isAtStartOfLine; + bool SavedSkipSpace = SkipSpace; + + std::string SavedErr = getErr(); + SMLoc SavedErrLoc = getErrLoc(); + + SkipSpace = ShouldSkipSpace; + AsmToken Token = LexToken(); + + SetError(SavedErrLoc, SavedErr); + + SkipSpace = SavedSkipSpace; + isAtStartOfLine = SavedAtStartOfLine; + CurPtr = SavedCurPtr; + TokStart = SavedTokStart; + + return Token; +} + bool AsmLexer::isAtStartOfComment(char Char) { // FIXME: This won't work for multi-character comment indicators like "//". return Char == *MAI.getCommentString();