Skip to content
Snippets Groups Projects
cppcodeformatter.cpp 31.6 KiB
Newer Older
        // function definition - argument list is expression state
        if (topState.type == case_cont)
            *indentDepth = topState.savedIndentDepth;
        else if (topState.type == expression && previousState.type == declaration_start)
            *indentDepth = previousState.savedIndentDepth;
        else if (topState.type != defun_open
                && topState.type != substatement_open
                && topState.type != block_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) {
                *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;
    }
}