Commit 1aed32d8 authored by Christian Kamm's avatar Christian Kamm Committed by hjk
Browse files

C++11: Fix indent of brace initializers in ctor lists.



Change-Id: Ib784df9e17ff2fe6bb249dcf8c2fee7310340f50
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 8c1a4556
......@@ -300,6 +300,13 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: tryExpression(); break;
} break;
case braceinit_open:
switch (kind) {
case T_RBRACE: leave(); break;
case T_RPAREN: leave(); continue; // recover?
default: tryExpression(); break;
} break;
case ternary_op:
switch (kind) {
case T_RPAREN:
......@@ -340,14 +347,16 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case member_init:
switch (kind) {
case T_LPAREN: enter(member_init_paren_open); break;
case T_RPAREN: leave(); break;
case T_LBRACE:
case T_LPAREN: enter(member_init_nest_open); break;
case T_RBRACE:
case T_RPAREN: leave(); break;
case T_SEMICOLON: leave(); continue; // try to recover
} break;
case member_init_paren_open:
case member_init_nest_open:
switch (kind) {
case T_RBRACE:
case T_RPAREN: leave(); continue;
case T_SEMICOLON: leave(); continue; // try to recover
default: tryExpression(); break;
......@@ -765,6 +774,7 @@ bool CodeFormatter::tryExpression(bool alsoExpression)
switch (kind) {
case T_LPAREN: newState = arglist_open; break;
case T_QUESTION: newState = ternary_op; break;
case T_LBRACE: newState = braceinit_open; break;
case T_EQUAL:
case T_AMPER_EQUAL:
......@@ -1235,7 +1245,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
case arglist_open:
case condition_paren_open:
case member_init_paren_open:
case member_init_nest_open:
if (!lastToken)
*paddingDepth = nextTokenPosition-*indentDepth;
else
......
......@@ -124,7 +124,7 @@ public: // must be public to make Q_GADGET introspection work
member_init_open, // After ':' that starts a member initialization list.
member_init_expected, // At the start and after every ',' in member_init_open
member_init, // After an identifier in member_init_expected
member_init_paren_open, // After '(' in member_init.
member_init_nest_open, // After '(' or '{' in member_init.
enum_start, // After 'enum'
enum_open, // Brace that opens a enum declaration.
......@@ -168,6 +168,7 @@ public: // must be public to make Q_GADGET introspection work
stream_op, // After a '<<' or '>>' in a context where it's likely a stream operator.
stream_op_cont, // When finding another stream operator in stream_op
ternary_op, // The ? : operator
braceinit_open, // after '{' in an expression context
condition_open, // Start of a condition in 'if', 'while', entered after opening paren
condition_paren_open, // After an lparen in a condition
......
......@@ -117,6 +117,7 @@ private Q_SLOTS:
void functionBodyAndBraces4();
void constructor1();
void constructor2();
void constructor3();
void caseBody1();
void caseBody2();
void caseBody3();
......@@ -1876,6 +1877,42 @@ void tst_CodeFormatter::constructor2()
checkIndent(data);
}
void tst_CodeFormatter::constructor3()
{
QList<Line> data;
data << Line("class Foo {")
<< Line(" Foo() : _a{0}, _b{1, {2, {3, \"foo\"}, 3}}")
<< Line(" {")
<< Line(" _b = 0")
<< Line(" }")
<< Line(" int _a;")
<< Line(" Foo()")
<< Line(" ~ : _foo{1},")
<< Line(" ~ _bar{2},")
<< Line(" ~ _carooooo(")
<< Line(" ~ foo() + 12),")
<< Line(" ~ _carooooo{foo(),")
<< Line(" ~ 12}")
<< Line(" {")
<< Line(" _b = 0")
<< Line(" }")
<< Line(" int _b;")
<< Line(" Foo()")
<< Line(" ~ : _foo{1}")
<< Line(" ~ , _bar{2}")
<< Line(" ~ , _carooooo{")
<< Line(" ~ foo() + 12}")
<< Line(" ~ , _carooooo{foo(),")
<< Line(" ~ 12}")
<< Line(" {")
<< Line(" _b = 0")
<< Line(" }")
<< Line("};")
;
CppCodeStyleSettings codeStyle;
checkIndent(data);
}
void tst_CodeFormatter::caseBody1()
{
QList<Line> data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment