OSDN Git Service

Update aosp/master LLVM for rebase to r256229
[android-x86/external-llvm.git] / include / llvm / MC / MCParser / MCAsmLexer.h
index 71f15b3..55279f4 100644 (file)
@@ -118,7 +118,7 @@ public:
 /// 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;
@@ -135,7 +135,7 @@ protected: // Can only create subclasses.
 
   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;
   }
@@ -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,14 +166,28 @@ 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.
-  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;
   }
 
@@ -175,13 +197,13 @@ public:
   }
 
   /// 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; }