diff options
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodeformatter.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index f1c55b7347..342b426fef 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -299,6 +299,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: @@ -339,14 +346,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; @@ -468,7 +477,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case block_open: if (tryStatement()) break; - switch(kind) { + switch (kind) { case T_RBRACE: leave(true); break; } break; @@ -757,13 +766,14 @@ void CodeFormatter::correctIndentation(const QTextBlock &block) } bool CodeFormatter::tryExpression(bool alsoExpression) -{ +{ int newState = -1; const int kind = m_currentToken.kind(); 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: @@ -979,11 +989,10 @@ int CodeFormatter::column(int index) const const QChar tab = QLatin1Char('\t'); for (int i = 0; i < index; i++) { - if (m_currentLine[i] == tab) { + if (m_currentLine[i] == tab) col = ((col / m_tabSize) + 1) * m_tabSize; - } else { + else col++; - } } return col; } @@ -1017,7 +1026,7 @@ void CodeFormatter::saveCurrentState(const QTextBlock &block) void CodeFormatter::restoreCurrentState(const QTextBlock &block) { - if (block.isValid()) { + if (block.isValid()) { BlockData blockData; if (loadBlockData(block, &blockData)) { m_indentDepth = blockData.m_indentDepth; @@ -1234,7 +1243,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 @@ -1318,9 +1327,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd *indentDepth += m_tabSettings.m_indentSize; } - if (followedByData) { + if (followedByData) *paddingDepth = nextTokenPosition-*indentDepth; - } break; } @@ -1473,11 +1481,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i } else if ((topState.type == expression && previousState.type == declaration_start) || topState.type == member_init || topState.type == member_init_open) { // the declaration_start indent is the base - if (topState.type == member_init) { + if (topState.type == member_init) *indentDepth = state(2).savedIndentDepth; - } else { + else *indentDepth = previousState.savedIndentDepth; - } if (m_styleSettings.indentFunctionBraces) *indentDepth += m_tabSettings.m_indentSize; *paddingDepth = 0; |