[llvm] r201058 - MCParser: add a single token lookahead

Saleem Abdulrasool compnerd at compnerd.org
Sun Feb 9 15:29:24 PST 2014


Author: compnerd
Date: Sun Feb  9 17:29:24 2014
New Revision: 201058

URL: http://llvm.org/viewvc/llvm-project?rev=201058&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
    llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h
    llvm/trunk/lib/MC/MCParser/AsmLexer.cpp

Modified: llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h?rev=201058&r1=201057&r2=201058&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/AsmLexer.h Sun Feb  9 17:29:24 2014
@@ -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);
 

Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h?rev=201058&r1=201057&r2=201058&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmLexer.h Sun Feb  9 17:29:24 2014
@@ -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;

Modified: llvm/trunk/lib/MC/MCParser/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmLexer.cpp?rev=201058&r1=201057&r2=201058&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmLexer.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmLexer.cpp Sun Feb  9 17:29:24 2014
@@ -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();





More information about the llvm-commits mailing list