clang-format: Understand #defines defining system includes.

Before:
  #define MY_IMPORT < a / b >

After:
  #define MY_IMPORT <a/b>

llvm-svn: 215527
This commit is contained in:
Daniel Jasper 2014-08-13 08:29:18 +00:00
parent 51bbd011c3
commit 343643b979
2 changed files with 14 additions and 2 deletions

View File

@ -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))

View File

@ -5234,6 +5234,8 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
"#include <strstream>\n"
"#endif");
verifyFormat("#define MY_IMPORT <a/b>");
// Protocol buffer definition or missing "#".
verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";",
getLLVMStyleWithColumns(30));