r215527 - clang-format: Understand #defines defining system includes.
Daniel Jasper
djasper at google.com
Wed Aug 13 01:29:18 PDT 2014
Author: djasper
Date: Wed Aug 13 03:29:18 2014
New Revision: 215527
URL: http://llvm.org/viewvc/llvm-project?rev=215527&view=rev
Log:
clang-format: Understand #defines defining system includes.
Before:
#define MY_IMPORT < a / b >
After:
#define MY_IMPORT <a/b>
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=215527&r1=215526&r2=215527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Aug 13 03:29:18 2014
@@ -497,7 +497,6 @@ private:
}
void parseIncludeDirective() {
- next();
if (CurrentToken && CurrentToken->is(tok::less)) {
next();
while (CurrentToken) {
@@ -554,6 +553,7 @@ private:
switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) {
case tok::pp_include:
case tok::pp_import:
+ next();
parseIncludeDirective();
break;
case tok::pp_error:
@@ -587,8 +587,18 @@ public:
// should not break the line).
IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
if (Info && Info->getPPKeywordID() == tok::pp_import &&
- CurrentToken->Next && CurrentToken->Next->is(tok::string_literal))
+ CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) {
+ next();
parseIncludeDirective();
+ return LT_Other;
+ }
+
+ // If this line starts and ends in '<' and '>', respectively, it is likely
+ // part of "#define <a/b.h>".
+ if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
+ parseIncludeDirective();
+ return LT_Other;
+ }
while (CurrentToken) {
if (CurrentToken->is(tok::kw_virtual))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=215527&r1=215526&r2=215527&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 13 03:29:18 2014
@@ -5234,6 +5234,8 @@ TEST_F(FormatTest, HandlesIncludeDirecti
"#include <strstream>\n"
"#endif");
+ verifyFormat("#define MY_IMPORT <a/b>");
+
// Protocol buffer definition or missing "#".
verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";",
getLLVMStyleWithColumns(30));
More information about the cfe-commits
mailing list