If ``true``, spaces will be inserted between 'for'/'if'/'while'/...
and '('.
+**SpaceBeforeAssignmentOperators** (``bool``)
+ If ``false``, spaces will be removed before '=', '+=', etc.
+
**SpaceInEmptyParentheses** (``bool``)
If ``false``, spaces may be inserted into '()'.
/// and '('.
bool SpaceAfterControlStatementKeyword;
+ /// \brief If \c false, spaces will be removed before assignment operators.
+ bool SpaceBeforeAssignmentOperators;
+
bool operator==(const FormatStyle &R) const {
return AccessModifierOffset == R.AccessModifierOffset &&
ConstructorInitializerIndentWidth ==
SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
SpaceAfterControlStatementKeyword ==
- R.SpaceAfterControlStatementKeyword;
+ R.SpaceAfterControlStatementKeyword &&
+ SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators;
}
};
Style.SpacesInCStyleCastParentheses);
IO.mapOptional("SpaceAfterControlStatementKeyword",
Style.SpaceAfterControlStatementKeyword);
+ IO.mapOptional("SpaceBeforeAssignmentOperators",
+ Style.SpaceBeforeAssignmentOperators);
}
};
}
LLVMStyle.SpaceInEmptyParentheses = false;
LLVMStyle.SpacesInCStyleCastParentheses = false;
LLVMStyle.SpaceAfterControlStatementKeyword = true;
+ LLVMStyle.SpaceBeforeAssignmentOperators = true;
setDefaultPenalties(LLVMStyle);
LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
GoogleStyle.SpaceInEmptyParentheses = false;
GoogleStyle.SpacesInCStyleCastParentheses = false;
GoogleStyle.SpaceAfterControlStatementKeyword = true;
+ GoogleStyle.SpaceBeforeAssignmentOperators = true;
setDefaultPenalties(GoogleStyle);
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
Tok.Previous->isOneOf(tok::arrowstar, tok::periodstar))
return false;
+ if (!Style.SpaceBeforeAssignmentOperators &&
+ Tok.getPrecedence() == prec::Assignment)
+ return false;
if ((Tok.Type == TT_BinaryOperator && !Tok.Previous->is(tok::l_paren)) ||
Tok.Previous->Type == TT_BinaryOperator)
return true;
"}", Spaces);
}
+TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
+ verifyFormat("int a = 5;");
+ verifyFormat("a += 42;");
+ verifyFormat("a or_eq 8;");
+
+ FormatStyle Spaces = getLLVMStyle();
+ Spaces.SpaceBeforeAssignmentOperators = false;
+ verifyFormat("int a= 5;", Spaces);
+ verifyFormat("a+= 42;", Spaces);
+ verifyFormat("a or_eq 8;", Spaces);
+}
+
TEST_F(FormatTest, LinuxBraceBreaking) {
FormatStyle BreakBeforeBrace = getLLVMStyle();
BreakBeforeBrace.BreakBeforeBraces = FormatStyle::BS_Linux;
CHECK_PARSE_BOOL(SpaceInEmptyParentheses);
CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
CHECK_PARSE_BOOL(SpaceAfterControlStatementKeyword);
+ CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
CHECK_PARSE("AccessModifierOffset: -1234", AccessModifierOffset, -1234);
CHECK_PARSE("ConstructorInitializerIndentWidth: 1234",