[llvm-commits] [llvm] r82059 - in /llvm/trunk/tools/llvm-mc: AsmLexer.cpp AsmLexer.h

Kevin Enderby enderby at apple.com
Wed Sep 16 11:08:00 PDT 2009


Author: enderby
Date: Wed Sep 16 13:08:00 2009
New Revision: 82059

URL: http://llvm.org/viewvc/llvm-project?rev=82059&view=rev
Log:
Fixed some problems with the logic of parsing line comments by adding
isAtStartOfComment and using that instead in two places where a loop
to check if the char was in MAI.getCommentString().

Modified:
    llvm/trunk/tools/llvm-mc/AsmLexer.cpp
    llvm/trunk/tools/llvm-mc/AsmLexer.h

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.cpp?rev=82059&r1=82058&r2=82059&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.cpp Wed Sep 16 13:08:00 2009
@@ -232,27 +232,30 @@
 StringRef AsmLexer::LexUntilEndOfStatement() {
   TokStart = CurPtr;
 
-  while (*CurPtr != ';' &&  // End of statement marker.
+  while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
+	  *CurPtr != ';' &&  // End of statement marker.
          *CurPtr != '\n' &&
          *CurPtr != '\r' &&
          (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
-    // check for start of line comment.
-    for (const char *p = MAI.getCommentString(); *p != 0; ++p)
-      if (*CurPtr == *p)
-        break;
     ++CurPtr;
   }
   return StringRef(TokStart, CurPtr-TokStart);
 }
 
+bool AsmLexer::isAtStartOfComment(char Char) {
+  for (const char *p = MAI.getCommentString(); *p != 0; ++p)
+    if (Char == *p)
+        return true;
+  return false;
+}
+
 AsmToken AsmLexer::LexToken() {
   TokStart = CurPtr;
   // This always consumes at least one character.
   int CurChar = getNextChar();
   
-  for (const char *p = MAI.getCommentString(); *p != 0; ++p)
-    if (CurChar == *p)
-      return LexLineComment();
+  if (isAtStartOfComment(CurChar))
+    return LexLineComment();
 
   switch (CurChar) {
   default:

Modified: llvm/trunk/tools/llvm-mc/AsmLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmLexer.h?rev=82059&r1=82058&r2=82059&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmLexer.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmLexer.h Wed Sep 16 13:08:00 2009
@@ -55,7 +55,8 @@
   SMLoc getLoc() const;
   
   StringRef LexUntilEndOfStatement();
-  
+
+  bool isAtStartOfComment(char Char);
 
   /// EnterIncludeFile - Enter the specified file. This returns true on failure.
   bool EnterIncludeFile(const std::string &Filename);





More information about the llvm-commits mailing list