MCParser: add a single token lookahead
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 9 Feb 2014 23:29:24 +0000 (23:29 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 9 Feb 2014 23:29:24 +0000 (23:29 +0000)
Some of the more complex directive and macro handling for GAS compatibility
requires lookahead.  Add a single token lookahead in the MCAsmLexer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201058 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCParser/AsmLexer.h
include/llvm/MC/MCParser/MCAsmLexer.h
lib/MC/MCParser/AsmLexer.cpp

index 1b3ab577519ba43d10d5505584bb0f121e1268b0..89677a91cd381ea664eaef7403047ce938a2afd6 100644 (file)
@@ -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);
 
index ceba3f05e1c9c246e60c1ba0b9230ec3b1117ea6..e3d4181e086f0d7944141d8dc8ecc9e4eb4a167a 100644 (file)
@@ -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;
index 88f17617895743d1c96409f3d875d3310c1c1d35..a3b68d838097b3528b23918305598606977bc032 100644 (file)
@@ -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();