[PATCH] D44831: [clang-format] Refine ObjC guesser to handle child lines of child lines
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 27 08:06:38 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328628: [clang-format] Refine ObjC guesser to handle child lines of child lines (authored by benhamilton, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D44831?vs=139929&id=139932#toc
Repository:
rC Clang
https://reviews.llvm.org/D44831
Files:
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -12159,6 +12159,12 @@
guessLanguage("foo.h", "#define FOO ({ std::string s; })"));
EXPECT_EQ(FormatStyle::LK_ObjC,
guessLanguage("foo.h", "#define FOO ({ NSString *s; })"));
+ EXPECT_EQ(
+ FormatStyle::LK_Cpp,
+ guessLanguage("foo.h", "#define FOO ({ foo(); ({ std::string s; }) })"));
+ EXPECT_EQ(
+ FormatStyle::LK_ObjC,
+ guessLanguage("foo.h", "#define FOO ({ foo(); ({ NSString *s; }) })"));
}
} // end namespace
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1514,8 +1514,8 @@
"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 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44831.139932.patch
Type: text/x-patch
Size: 1744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180327/f69d6129/attachment-0001.bin>
More information about the cfe-commits
mailing list