From 84774ba4247fc19ba1ac22ebf9c05609ad5adc1c Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 8 Nov 2015 23:48:23 +0000 Subject: [PATCH] [AsmParser] Allow tokens to be put back in to the token stream. Differential Revision: http://reviews.llvm.org/D14252 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252432 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCParser/MCAsmLexer.h | 14 +++++++++++--- lib/MC/MCParser/MCAsmLexer.cpp | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/llvm/MC/MCParser/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h index a9a9357f827..55279f49529 100644 --- a/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/include/llvm/MC/MCParser/MCAsmLexer.h @@ -118,7 +118,7 @@ public: /// lexers. class MCAsmLexer { /// The current token, stored in the base class for faster access. - AsmToken CurTok; + SmallVector CurTok; /// The location and description of the current error SMLoc ErrLoc; @@ -148,7 +148,15 @@ public: /// The lexer will continuosly return the end-of-file token once the end of /// the main input file has been reached. const AsmToken &Lex() { - return CurTok = LexToken(); + assert(!CurTok.empty()); + CurTok.erase(CurTok.begin()); + if (CurTok.empty()) + CurTok.emplace_back(LexToken()); + return CurTok.front(); + } + + void UnLex(AsmToken const &Token) { + CurTok.insert(CurTok.begin(), Token); } virtual StringRef LexUntilEndOfStatement() = 0; @@ -158,7 +166,7 @@ public: /// Get the current (last) lexed token. const AsmToken &getTok() const { - return CurTok; + return CurTok[0]; } /// Look ahead at the next token to be lexed. diff --git a/lib/MC/MCParser/MCAsmLexer.cpp b/lib/MC/MCParser/MCAsmLexer.cpp index 795cc85ef54..e891bd2c624 100644 --- a/lib/MC/MCParser/MCAsmLexer.cpp +++ b/lib/MC/MCParser/MCAsmLexer.cpp @@ -12,8 +12,8 @@ using namespace llvm; -MCAsmLexer::MCAsmLexer() : CurTok(AsmToken::Error, StringRef()), - TokStart(nullptr), SkipSpace(true) { +MCAsmLexer::MCAsmLexer() : TokStart(nullptr), SkipSpace(true) { + CurTok.emplace_back(AsmToken::Error, StringRef()); } MCAsmLexer::~MCAsmLexer() { -- 2.34.1