r242404 - clang-format: [Proto] Handle enum bodies differently.
Daniel Jasper
djasper at google.com
Thu Jul 16 07:25:43 PDT 2015
Author: djasper
Date: Thu Jul 16 09:25:43 2015
New Revision: 242404
URL: http://llvm.org/viewvc/llvm-project?rev=242404&view=rev
Log:
clang-format: [Proto] Handle enum bodies differently.
In proto, enum constants can contain complex options and should be
handled more like individual declarations.
Before:
enum Type {
UNKNOWN = 0 [(some_options) =
{
a: aa,
b: bb
}];
};
After:
enum Type {
UNKNOWN = 0 [(some_options) = {
a: aa,
b: bb
}];
};
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=242404&r1=242403&r2=242404&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jul 16 09:25:43 2015
@@ -811,9 +811,8 @@ void UnwrappedLineParser::parseStructura
// parseEnum falls through and does not yet add an unwrapped line as an
// enum definition can start a structural element.
parseEnum();
- // This does not apply for Java and JavaScript.
- if (Style.Language == FormatStyle::LK_Java ||
- Style.Language == FormatStyle::LK_JavaScript) {
+ // This only applies for C++.
+ if (Style.Language != FormatStyle::LK_Cpp) {
addUnwrappedLine();
return;
}
@@ -1554,6 +1553,9 @@ void UnwrappedLineParser::parseEnum() {
// Java enums are different.
parseJavaEnumBody();
return;
+ } else if (Style.Language == FormatStyle::LK_Proto) {
+ parseBlock(/*MustBeDeclaration=*/true);
+ return;
}
// Parse enum body.
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=242404&r1=242403&r2=242404&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Jul 16 09:25:43 2015
@@ -73,6 +73,12 @@ TEST_F(FormatTestProto, FormatsEnums) {
" TYPE_A = 1;\n"
" TYPE_B = 2;\n"
"};");
+ verifyFormat("enum Type {\n"
+ " UNKNOWN = 0 [(some_options) = {\n"
+ " a: aa,\n"
+ " b: bb\n"
+ " }];\n"
+ "};");
}
TEST_F(FormatTestProto, UnderstandsReturns) {
More information about the cfe-commits
mailing list