r199501 - clang-format: Don't break lines starting with "import <string-literal>"
Daniel Jasper
djasper at google.com
Fri Jan 17 08:21:39 PST 2014
Author: djasper
Date: Fri Jan 17 10:21:39 2014
New Revision: 199501
URL: http://llvm.org/viewvc/llvm-project?rev=199501&view=rev
Log:
clang-format: Don't break lines starting with "import <string-literal>"
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.
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=199501&r1=199500&r2=199501&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Jan 17 10:21:39 2014
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=199501&r1=199500&r2=199501&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 17 10:21:39 2014
@@ -4657,6 +4657,10 @@ TEST_F(FormatTest, HandlesIncludeDirecti
verifyFormat("#if __has_include(<strstream>)\n"
"#include <strstream>\n"
"#endif");
+
+ // Protocol buffer definition or missing "#".
+ verifyFormat("import \"aaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaa\";",
+ getLLVMStyleWithColumns(30));
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list