]> granicus.if.org Git - clang/commitdiff
clang-format: Understand #defines defining system includes.
authorDaniel Jasper <djasper@google.com>
Wed, 13 Aug 2014 08:29:18 +0000 (08:29 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 13 Aug 2014 08:29:18 +0000 (08:29 +0000)
Before:
  #define MY_IMPORT < a / b >

After:
  #define MY_IMPORT <a/b>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215527 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index b24573fffcdf2c964376bc01832adc849f34c24e..a3662348736c48e991a41cab75d16b43ece9322e 100644 (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))
index f36eede8feebac53f43eb877b4c21fcd1297a71e..1bd52aa9b5eccdadba8f6a5e82be990a7b989b85 100644 (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));