/// lexers.
class MCAsmLexer {
/// The current token, stored in the base class for faster access.
- AsmToken CurTok;
+ SmallVector<AsmToken, 1> CurTok;
/// The location and description of the current error
SMLoc ErrLoc;
virtual AsmToken LexToken() = 0;
- void SetError(const SMLoc &errLoc, const std::string &err) {
+ void SetError(SMLoc errLoc, const std::string &err) {
ErrLoc = errLoc;
Err = err;
}
/// 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;
/// Get the current (last) lexed token.
const AsmToken &getTok() const {
- return CurTok;
+ return CurTok[0];
}
/// Look ahead at the next token to be lexed.
- virtual const AsmToken peekTok(bool ShouldSkipSpace = true) = 0;
+ const AsmToken peekTok(bool ShouldSkipSpace = true) {
+ AsmToken Tok;
+
+ MutableArrayRef<AsmToken> Buf(Tok);
+ size_t ReadCount = peekTokens(Buf, ShouldSkipSpace);
+
+ assert(ReadCount == 1);
+ (void)ReadCount;
+
+ return Tok;
+ }
+
+ /// Look ahead an arbitrary number of tokens.
+ virtual size_t peekTokens(MutableArrayRef<AsmToken> Buf,
+ bool ShouldSkipSpace = true) = 0;
/// Get the current error location
- const SMLoc &getErrLoc() {
+ SMLoc getErrLoc() {
return ErrLoc;
}
}
/// Get the kind of current token.
- AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
+ AsmToken::TokenKind getKind() const { return getTok().getKind(); }
/// Check if the current token has kind \p K.
- bool is(AsmToken::TokenKind K) const { return CurTok.is(K); }
+ bool is(AsmToken::TokenKind K) const { return getTok().is(K); }
/// Check if the current token has kind \p K.
- bool isNot(AsmToken::TokenKind K) const { return CurTok.isNot(K); }
+ bool isNot(AsmToken::TokenKind K) const { return getTok().isNot(K); }
/// Set whether spaces should be ignored by the lexer
void setSkipSpace(bool val) { SkipSpace = val; }