Added SpaceAfterFunctionName option
Alexander Kornienko
alexfh at google.com
Tue Dec 3 09:56:50 PST 2013
Added SpaceAfterFunctionName, which is needed for GNU coding style.
Phab is taking a day off, so the patch is just here:
Index: include/clang/Format/Format.h
===================================================================
--- include/clang/Format/Format.h (revision 196295)
+++ include/clang/Format/Format.h (working copy)
@@ -260,6 +260,9 @@
/// and '('.
bool SpaceAfterControlStatementKeyword;
+ /// \brief If \c true, spaces will be inserted between function name and
'('.
+ bool SpaceAfterFunctionName;
+
/// \brief If \c false, spaces will be removed before assignment
operators.
bool SpaceBeforeAssignmentOperators;
@@ -317,6 +320,7 @@
SpacesInCStyleCastParentheses ==
R.SpacesInCStyleCastParentheses &&
SpaceAfterControlStatementKeyword ==
R.SpaceAfterControlStatementKeyword &&
+ SpaceAfterFunctionName == R.SpaceAfterFunctionName &&
SpaceBeforeAssignmentOperators ==
R.SpaceBeforeAssignmentOperators &&
ContinuationIndentWidth == R.ContinuationIndentWidth;
}
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp (revision 196295)
+++ lib/Format/Format.cpp (working copy)
@@ -181,6 +181,7 @@
Style.SpacesInCStyleCastParentheses);
IO.mapOptional("SpaceAfterControlStatementKeyword",
Style.SpaceAfterControlStatementKeyword);
+ IO.mapOptional("SpaceAfterFunctionName", Style.SpaceAfterFunctionName);
IO.mapOptional("SpaceBeforeAssignmentOperators",
Style.SpaceBeforeAssignmentOperators);
IO.mapOptional("ContinuationIndentWidth",
Style.ContinuationIndentWidth);
@@ -267,6 +268,7 @@
LLVMStyle.SpaceInEmptyParentheses = false;
LLVMStyle.SpacesInCStyleCastParentheses = false;
LLVMStyle.SpaceAfterControlStatementKeyword = true;
+ LLVMStyle.SpaceAfterFunctionName = false;
LLVMStyle.SpaceBeforeAssignmentOperators = true;
LLVMStyle.ContinuationIndentWidth = 4;
LLVMStyle.SpacesInAngles = false;
@@ -316,6 +318,7 @@
GoogleStyle.SpaceInEmptyParentheses = false;
GoogleStyle.SpacesInCStyleCastParentheses = false;
GoogleStyle.SpaceAfterControlStatementKeyword = true;
+ GoogleStyle.SpaceAfterFunctionName = false;
GoogleStyle.SpaceBeforeAssignmentOperators = true;
GoogleStyle.ContinuationIndentWidth = 4;
GoogleStyle.SpacesInAngles = false;
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp (revision 196295)
+++ lib/Format/TokenAnnotator.cpp (working copy)
@@ -1295,7 +1295,8 @@
tok::semi) ||
(Style.SpaceAfterControlStatementKeyword &&
Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
tok::kw_switch,
- tok::kw_catch));
+ tok::kw_catch)) ||
+ (Style.SpaceAfterFunctionName && Left.is(tok::identifier));
}
if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() !=
tok::objc_not_keyword)
return false;
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp (revision 196295)
+++ unittests/Format/FormatTest.cpp (working copy)
@@ -6637,6 +6637,33 @@
"}", NoSpace);
}
+TEST_F(FormatTest, ConfigurableSpaceAfterFunctionName) {
+ FormatStyle Space = getLLVMStyle();
+ Space.SpaceAfterControlStatementKeyword = false;
+ Space.SpaceAfterFunctionName = true;
+
+ verifyFormat("int f ();", Space);
+ verifyFormat("void f (int a, T b) {\n"
+ " while(true)\n"
+ " continue;\n"
+ "}",
+ Space);
+ verifyFormat("if(true)\n"
+ " f ();\n"
+ "else if(true)\n"
+ " f ();",
+ Space);
+ verifyFormat("do {\n"
+ " do_something ();\n"
+ "} while(something ());",
+ Space);
+ verifyFormat("switch(x) {\n"
+ "default:\n"
+ " break;\n"
+ "}",
+ Space);
+}
+
TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
FormatStyle Spaces = getLLVMStyle();
@@ -6945,6 +6972,7 @@
CHECK_PARSE_BOOL(SpaceInEmptyParentheses);
CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
CHECK_PARSE_BOOL(SpaceAfterControlStatementKeyword);
+ CHECK_PARSE_BOOL(SpaceAfterFunctionName);
CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131203/841d3de6/attachment.html>
More information about the cfe-commits
mailing list