diff options
author | Ben Hamilton <benhamilton@google.com> | 2018-11-05 16:59:33 +0000 |
---|---|---|
committer | Ben Hamilton <benhamilton@google.com> | 2018-11-05 16:59:33 +0000 |
commit | 0675e87ec82929f3287a5f7028b2843b6cd612a4 (patch) | |
tree | e6fd51e41fd6b7aef22694b8c4d659329d8d5e0e /clang/lib/Format/Format.cpp | |
parent | 87aa10062c0170a6a8cb79427655a086cf253b97 (diff) | |
download | bcm5719-llvm-0675e87ec82929f3287a5f7028b2843b6cd612a4.tar.gz bcm5719-llvm-0675e87ec82929f3287a5f7028b2843b6cd612a4.zip |
[Format] Add debugging to ObjC language guesser
Summary:
To handle diagnosing bugs where ObjCHeaderStyleGuesser guesses
wrong, this diff adds a bit more debug logging to the Objective-C
language guesser.
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D54110
llvm-svn: 346144
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 84af7383683..2c4f8760540 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1504,7 +1504,8 @@ public: 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}; } @@ -1512,8 +1513,10 @@ public: 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 @@ private: 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; } } |