Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
*indentDepth = m_indentSize;
break;
}
}
void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, int lexerState, int *indentDepth) const
{
State topState = state();
State previousState = state(1);
const bool topWasMaybeElse = (topState.type == maybe_else);
if (topWasMaybeElse) {
int outermostBraceless = 1;
while (state(outermostBraceless).type != invalid && isBracelessState(state(outermostBraceless).type))
++outermostBraceless;
topState = state(outermostBraceless);
previousState = state(outermostBraceless + 1);
}
// adjusting the indentDepth here instead of in enter() gives 'else if' the correct indentation
// ### could be moved?
if (topState.type == substatement)
*indentDepth += m_indentSize;
// keep user-adjusted indent in multiline comments
if (topState.type == multiline_comment_start
|| topState.type == multiline_comment_cont) {
if (!tokens.isEmpty()) {
*indentDepth = tokens.at(0).begin();
return;
}
}
const int kind = tokenAt(0).kind();
switch (kind) {
case T_POUND: *indentDepth = 0; break;
case T_COLON:
// ### ok for constructor initializer lists - what about ? and bitfields?
if (topState.type == expression && previousState.type == declaration_start) {
*indentDepth = previousState.savedIndentDepth + m_indentSize;
} else if (topState.type == ternary_op) {
*indentDepth -= 2;
}
break;
case T_COMMA:
if (topState.type == member_init_open) {
*indentDepth -= 2;
}
break;
case T_LBRACE: {
if (topState.type == case_cont) {
*indentDepth = topState.savedIndentDepth;
// function definition - argument list is expression state
} else if (topState.type == expression && previousState.type == declaration_start) {
*indentDepth = previousState.savedIndentDepth;
if (m_indentDeclarationBraces)
*indentDepth += m_indentSize;
} else if (topState.type == class_start) {
*indentDepth = topState.savedIndentDepth;
if (m_indentDeclarationBraces)
*indentDepth += m_indentSize;
} else if (topState.type == substatement) {
*indentDepth = topState.savedIndentDepth;
if (m_indentSubstatementBraces)
*indentDepth += m_indentSize;
} else if (topState.type != defun_open
&& !topWasMaybeElse) {
*indentDepth = topState.savedIndentDepth;
}
break;
}
case T_RBRACE: {
if (topState.type == block_open && previousState.type == case_cont) {
*indentDepth = previousState.savedIndentDepth;
break;
}
for (int i = 0; state(i).type != topmost_intro; ++i) {
const int type = state(i).type;
if (type == defun_open
|| type == substatement_open
|| type == class_open
|| type == brace_list_open
|| type == namespace_open
|| type == block_open
|| type == enum_open) {
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
*indentDepth = state(i).savedIndentDepth;
break;
}
}
break;
}
case T_RPAREN:
if (topState.type == condition_open) {
*indentDepth = previousState.savedIndentDepth;
}
break;
case T_DEFAULT:
case T_CASE:
for (int i = 0; state(i).type != topmost_intro; ++i) {
const int type = state(i).type;
if (type == switch_statement || type == case_cont) {
*indentDepth = state(i).savedIndentDepth;
break;
} else if (type == topmost_intro) {
break;
}
}
break;
case T_PUBLIC:
case T_PRIVATE:
case T_PROTECTED:
case T_Q_SIGNALS:
if (topState.type == class_open) {
if (tokenAt(1).is(T_COLON) || tokenAt(2).is(T_COLON))
*indentDepth = topState.savedIndentDepth;
}
break;
case T_ELSE:
if (topWasMaybeElse)
*indentDepth = state().savedIndentDepth; // topSavedIndent is actually the previous
break;
case T_LESS_LESS:
case T_GREATER_GREATER:
if (topState.type == stream_op)
*indentDepth -= 3; // to align << with <<
break;
case T_COMMENT:
case T_DOXY_COMMENT:
case T_CPP_COMMENT:
case T_CPP_DOXY_COMMENT:
// unindent the last line of a comment
if ((topState.type == multiline_comment_cont
|| topState.type == multiline_comment_start)
&& (kind == T_COMMENT || kind == T_DOXY_COMMENT)
&& (lexerState == Lexer::State_Default
|| tokens.size() != 1)) {
*indentDepth -= m_indentSize;
}
break;
}
}