]> granicus.if.org Git - clang/commitdiff
clang-format: Don't break lines starting with "import <string-literal>"
authorDaniel Jasper <djasper@google.com>
Fri, 17 Jan 2014 16:21:39 +0000 (16:21 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 17 Jan 2014 16:21:39 +0000 (16:21 +0000)
The author might be missing the "#" or these might be protocol buffer
definitions. Either way, we should not break the line or the string.

There don't seem to be other valid use cases.

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

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

index b04ccd0ba75238d0227c658cdfc3e168c0436566..d80e5504949052c75b233e1de3525bc58822e981 100644 (file)
@@ -529,6 +529,15 @@ public:
       parsePreprocessorDirective();
       return LT_PreprocessorDirective;
     }
+  
+    // Directly allow to 'import <string-literal>' to support protocol buffer
+    // definitions (code.google.com/p/protobuf) or missing "#" (either way we
+    // 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))
+      parseIncludeDirective();
+
     while (CurrentToken != NULL) {
       if (CurrentToken->is(tok::kw_virtual))
         KeywordVirtualFound = true;
index c75df9ce151e164ea7a80bbb8d97e41061707420..0fade5b42f04ed94d3fbb9981cb76466f072fbe2 100644 (file)
@@ -4657,6 +4657,10 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
   verifyFormat("#if __has_include(<strstream>)\n"
                "#include <strstream>\n"
                "#endif");
+
+  // Protocol buffer definition or missing "#".
+  verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";",
+               getLLVMStyleWithColumns(30));
 }
 
 //===----------------------------------------------------------------------===//