Fixed some problems with the logic of parsing line comments by adding
authorKevin Enderby <enderby@apple.com>
Wed, 16 Sep 2009 18:08:00 +0000 (18:08 +0000)
committerKevin Enderby <enderby@apple.com>
Wed, 16 Sep 2009 18:08:00 +0000 (18:08 +0000)
isAtStartOfComment and using that instead in two places where a loop
to check if the char was in MAI.getCommentString().

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

tools/llvm-mc/AsmLexer.cpp
tools/llvm-mc/AsmLexer.h

index 2016f935c5b88a6e8fe69a9923aebc2e43b120c6..be8f60d2dd7b3a458a9fb2bab31a8f758445acb9 100644 (file)
@@ -232,27 +232,30 @@ AsmToken AsmLexer::LexQuote() {
 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:
index 32b0c5f5fb468206867664abfe6cf6d53398f744..0c2ec138924e4e40dd1b370958df721460f0e298 100644 (file)
@@ -55,7 +55,8 @@ public:
   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);