[PATCH] D54110: [Format] Add debugging to ObjC language guesser

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 5 09:02:03 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC346144: [Format] Add debugging to ObjC language guesser (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54110?vs=172599&id=172600#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54110

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1504,16 +1504,19 @@
           SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
           FormatTokenLexer &Tokens) override {
     assert(Style.Language == FormatStyle::LK_Cpp);
-    IsObjC = guessIsObjC(AnnotatedLines, Tokens.getKeywords());
+    IsObjC = guessIsObjC(Env.getSourceManager(), AnnotatedLines,
+                         Tokens.getKeywords());
     tooling::Replacements Result;
     return {Result, 0};
   }
 
   bool isObjC() { return IsObjC; }
 
 private:
-  static bool guessIsObjC(const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
-                          const AdditionalKeywords &Keywords) {
+  static bool
+  guessIsObjC(const SourceManager &SourceManager,
+              const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
+              const AdditionalKeywords &Keywords) {
     // Keep this array sorted, since we are binary searching over it.
     static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
         "CGFloat",
@@ -1604,9 +1607,15 @@
                                TT_ObjCBlockLBrace, TT_ObjCBlockLParen,
                                TT_ObjCDecl, TT_ObjCForIn, TT_ObjCMethodExpr,
                                TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
+          LLVM_DEBUG(llvm::dbgs()
+                     << "Detected ObjC at location "
+                     << FormatTok->Tok.getLocation().printToString(
+                            SourceManager)
+                     << " token: " << FormatTok->TokenText << " token type: "
+                     << getTokenTypeName(FormatTok->Type) << "\n");
           return true;
         }
-        if (guessIsObjC(Line->Children, Keywords))
+        if (guessIsObjC(SourceManager, Line->Children, Keywords))
           return true;
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54110.172600.patch
Type: text/x-patch
Size: 1921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181105/82888c81/attachment-0001.bin>


More information about the cfe-commits mailing list