summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2018-03-27 15:01:21 +0000
committerBen Hamilton <benhamilton@google.com>2018-03-27 15:01:21 +0000
commitea7a27b847b8eca39e427b430381e6b2cbf349f3 (patch)
treefd5c59dd2c0bc64eeec27861bbcff4acd865dcae /clang/lib/Format/Format.cpp
parentd54e7aa9e252a9d895c1250a0512e5323632efb8 (diff)
downloadbcm5719-llvm-ea7a27b847b8eca39e427b430381e6b2cbf349f3.tar.gz
bcm5719-llvm-ea7a27b847b8eca39e427b430381e6b2cbf349f3.zip
[clang-format] Refine ObjC guesser to handle child lines of child lines
Summary: This fixes an issue brought up by djasper@ in his review of D44790. We handled top-level child lines, but if those child lines themselves had child lines, we didn't handle them. Rather than use recursion (which could blow out the stack), I use a DenseSet to hold the set of lines we haven't yet checked (since order doesn't matter), and update the set to add the children of each line as we check it. Test Plan: New tests added. Confirmed tests failed before fix and passed after fix. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44831 llvm-svn: 328628
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ac22d6b4501..f7e74abab37 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@ private:
"UIView",
};
- auto LineContainsObjCCode = [&Keywords](const AnnotatedLine &Line) {
- for (const FormatToken *FormatTok = Line.First; FormatTok;
+ for (auto Line : AnnotatedLines) {
+ for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
(FormatTok->isObjCAtKeyword(tok::objc_interface) ||
@@ -1535,14 +1535,7 @@ private:
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
return true;
}
- }
- return false;
- };
- for (auto Line : AnnotatedLines) {
- if (LineContainsObjCCode(*Line))
- return true;
- for (auto ChildLine : Line->Children) {
- if (LineContainsObjCCode(*ChildLine))
+ if (guessIsObjC(Line->Children, Keywords))
return true;
}
}
OpenPOWER on IntegriCloud