[cfe-commits] r161898 - /cfe/trunk/lib/Sema/SemaStmt.cpp

Chad Rosier mcrosier at apple.com
Tue Aug 14 15:11:17 PDT 2012


Author: mcrosier
Date: Tue Aug 14 17:11:17 2012
New Revision: 161898

URL: http://llvm.org/viewvc/llvm-project?rev=161898&view=rev
Log:
[ms-inline asm] Simplify more logic by using the Token::hasLeadingSpace() and
Token::isAtStartOfLine() APIs.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161898&r1=161897&r2=161898&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Aug 14 17:11:17 2012
@@ -2759,41 +2759,6 @@
   return Owned(NS);
 }
 
-// needSpaceAsmToken - This function handles whitespace around asm punctuation.
-// Returns true if a space should be emitted.
-static inline bool needSpaceAsmToken(Token currTok) {
-  static Token prevTok;
-
-  // No need for space after prevToken.
-  switch(prevTok.getKind()) {
-  default:
-    break;
-  case tok::l_square:
-  case tok::r_square:
-  case tok::l_brace:
-  case tok::r_brace:
-  case tok::colon:
-    prevTok = currTok;
-    return false;
-  }
-
-  // No need for a space before currToken.
-  switch(currTok.getKind()) {
-  default:
-    break;
-  case tok::l_square:
-  case tok::r_square:
-  case tok::l_brace:
-  case tok::r_brace:
-  case tok::comma:
-  case tok::colon:
-    prevTok = currTok;
-    return false;
-  }
-  prevTok = currTok;
-  return true;
-}
-
 static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
                               SourceLocation AsmLoc,
                               ArrayRef<Token> AsmToks,
@@ -2812,14 +2777,17 @@
     if (i != 0 && AsmToks[i].isAtStartOfLine())
       AsmStrings[NumAsmStrings++] = Asm.c_str();
 
+    if (i && AsmToks[i].isAtStartOfLine())
+      Asm += '\n';
+
     // Start a new asm string with the opcode.
     if (i == 0 || AsmToks[i].isAtStartOfLine()) {
       Asm = AsmToks[i].getIdentifierInfo()->getName().str();
       continue;
     }
 
-    if (needSpaceAsmToken(AsmToks[i]))
-      Asm += " ";
+    if (i && AsmToks[i].hasLeadingSpace())
+      Asm += ' ';
 
     // Check the operand(s).
     switch (AsmToks[i].getKind()) {
@@ -2862,24 +2830,19 @@
 
 // Build the unmodified MSAsmString.
 static std::string buildMSAsmString(Sema &SemaRef,
-                                    ArrayRef<Token> AsmToks,
-                                    ArrayRef<unsigned> LineEnds) {
+                                    ArrayRef<Token> AsmToks) {
   assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
   SmallString<512> Asm;
   SmallString<512> TokenBuf;
   TokenBuf.resize(512);
-  unsigned AsmLineNum = 0;
   for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
     bool StringInvalid = false;
-    if (i && (!AsmLineNum || i != LineEnds[AsmLineNum-1]) &&
-        needSpaceAsmToken(AsmToks[i]))
+    if (i && AsmToks[i].isAtStartOfLine())
+      Asm += '\n';
+    else if (i && AsmToks[i].hasLeadingSpace())
       Asm += ' ';
     Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
     assert (!StringInvalid && "Expected valid string!");
-    if (i + 1 == LineEnds[AsmLineNum] && i + 1 != AsmToks.size()) {
-      Asm += '\n';
-      ++AsmLineNum;
-    }
   }
   return Asm.c_str();
 }
@@ -2902,7 +2865,7 @@
     return Owned(NS);
   }
 
-  std::string AsmString = buildMSAsmString(*this, AsmToks, LineEnds);
+  std::string AsmString = buildMSAsmString(*this, AsmToks);
 
   bool IsSimple;
   std::vector<std::string> PatchedAsmStrings;





More information about the cfe-commits mailing list