[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 08:51:23 PST 2018
benhamilton created this revision.
benhamilton added a reviewer: krasimir.
Herald added a subscriber: cfe-commits.
To handle diagnosing bugs where ObjCHeaderStyleGuesser guesses
wrong, this diff adds a bit more debug logging to the Objective-C
language guesser.
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.172599.patch
Type: text/x-patch
Size: 1921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181105/287252a4/attachment.bin>
More information about the cfe-commits
mailing list