From: Daniel Jasper Date: Fri, 17 Jan 2014 16:21:39 +0000 (+0000) Subject: clang-format: Don't break lines starting with "import " X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbd029577ee710c4f868c9ad4f6b0eef1866c6ad;p=clang clang-format: Don't break lines starting with "import " 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b04ccd0ba7..d80e550494 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -529,6 +529,15 @@ public: parsePreprocessorDirective(); return LT_PreprocessorDirective; } + + // Directly allow to 'import ' 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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c75df9ce15..0fade5b42f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4657,6 +4657,10 @@ TEST_F(FormatTest, HandlesIncludeDirectives) { verifyFormat("#if __has_include()\n" "#include \n" "#endif"); + + // Protocol buffer definition or missing "#". + verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";", + getLLVMStyleWithColumns(30)); } //===----------------------------------------------------------------------===//