/** * Checks to see if pc is a better spot to split. * This should only be called going BACKWARDS (ie prev) * A lower level wins * * Splitting Preference: * - semicolon * - comma * - boolean op * - comparison * - arithmetic op * - assignment */ static void try_split_here(cw_entry& ent, chunk_t *pc) { chunk_t *prev; int pc_pri = get_split_pri(pc->type); if (pc_pri == 0) { return; } /* Can't split after a newline */ prev = chunk_get_prev(pc); if ((prev == NULL) || chunk_is_newline(prev)) { return; } /* Check levels first */ bool change = false; if ((ent.pc == NULL) || (pc->level < ent.pc->level)) { change = true; } else { if ((pc->level > ent.pc->level) && (pc_pri <= ent.pri)) { change = true; } } if (change) { ent.pc = pc; ent.pri = pc_pri; } }
/** * Checks to see if pc is a better spot to split. * This should only be called going BACKWARDS (ie prev) * A lower level wins * * Splitting Preference: * - semicolon * - comma * - boolean op * - comparison * - arithmetic op * - assignment * - ? : * - function open paren not followed by close paren */ static void try_split_here(cw_entry& ent, chunk_t *pc) { chunk_t *next; chunk_t *prev; int pc_pri = get_split_pri(pc->type); if (pc_pri == 0) { return; } /* Can't split after a newline */ prev = chunk_get_prev(pc); if ((prev == NULL) || chunk_is_newline(prev)) { return; } /* Can't split a function without arguments */ if (pc->type == CT_FPAREN_OPEN) { next = chunk_get_next(pc); if (next->type == CT_FPAREN_CLOSE) { return; } } /* keep common groupings unless indent_continue < 0 */ if ((cpd.settings[UO_indent_continue].n >= 0) && (pc_pri >= 20)) { return; } /* don't break after last term of a qualified type */ if (pc_pri == 25) { next = chunk_get_next(pc); if ((next->type != CT_WORD) && (get_split_pri(next->type) != 25)) { return; } } /* Check levels first */ bool change = false; if ((ent.pc == NULL) || (pc->level < ent.pc->level)) { change = true; } else { if ((pc->level > ent.pc->level) && (pc_pri <= ent.pri)) { change = true; } } if (change) { ent.pc = pc; ent.pri = pc_pri; } }
/** * Checks to see if pc is a better spot to split. * This should only be called going BACKWARDS (ie prev) * A lower level wins * * Splitting Preference: * - semicolon * - comma * - boolean op * - comparison * - arithmetic op * - assignment * - concatenated strings * - ? : * - function open paren not followed by close paren */ static void try_split_here(cw_entry &ent, chunk_t *pc) { LOG_FUNC_ENTRY(); chunk_t *next; chunk_t *prev; int pc_pri = get_split_pri(pc->type); if (pc_pri == 0) { return; } /* Can't split after a newline */ prev = chunk_get_prev(pc); if ((prev == NULL) || (chunk_is_newline(prev) && (pc->type != CT_STRING))) { return; } /* Can't split a function without arguments */ if (pc->type == CT_FPAREN_OPEN) { next = chunk_get_next(pc); if (next->type == CT_FPAREN_CLOSE) { return; } } /* Only split concatenated strings */ if (pc->type == CT_STRING) { next = chunk_get_next(pc); if (next->type != CT_STRING) { return; } } /* keep common groupings unless ls_code_width */ if (!cpd.settings[UO_ls_code_width].b && (pc_pri >= 20)) { return; } /* don't break after last term of a qualified type */ if (pc_pri == 25) { next = chunk_get_next(pc); if ((next->type != CT_WORD) && (get_split_pri(next->type) != 25)) { return; } } /* Check levels first */ bool change = false; if ((ent.pc == NULL) || (pc->level < ent.pc->level)) { change = true; } else { if ((pc->level >= ent.pc->level) && (pc_pri < ent.pri)) { change = true; } } if (change) { ent.pc = pc; ent.pri = pc_pri; } } // try_split_here
static void try_split_here(cw_entry &ent, chunk_t *pc) { LOG_FUNC_ENTRY(); LOG_FMT(LSPLIT, "%s(%d): at %s, orig_col=%zu\n", __func__, __LINE__, pc->text(), pc->orig_col); size_t pc_pri = get_split_pri(pc->type); LOG_FMT(LSPLIT, "%s(%d): pc_pri=%zu\n", __func__, __LINE__, pc_pri); if (pc_pri == 0) { LOG_FMT(LSPLIT, "%s(%d): pc_pri is 0, return\n", __func__, __LINE__); return; } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // Can't split after a newline chunk_t *prev = chunk_get_prev(pc); if ( prev == nullptr || (chunk_is_newline(prev) && pc->type != CT_STRING)) { if (prev != nullptr) { LOG_FMT(LSPLIT, "%s(%d): Can't split after a newline, orig_line=%zu, return\n", __func__, __LINE__, prev->orig_line); } return; } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // Can't split a function without arguments if (pc->type == CT_FPAREN_OPEN) { chunk_t *next = chunk_get_next(pc); if (next->type == CT_FPAREN_CLOSE) { LOG_FMT(LSPLIT, "%s(%d): Can't split a function without arguments, return\n", __func__, __LINE__); return; } } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // Only split concatenated strings if (pc->type == CT_STRING) { chunk_t *next = chunk_get_next(pc); if (next->type != CT_STRING) { LOG_FMT(LSPLIT, "%s(%d): Only split concatenated strings, return\n", __func__, __LINE__); return; } } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // keep common groupings unless ls_code_width if (!cpd.settings[UO_ls_code_width].b && pc_pri >= 20) { LOG_FMT(LSPLIT, "%s(%d): keep common groupings unless ls_code_width, return\n", __func__, __LINE__); return; } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // don't break after last term of a qualified type if (pc_pri == 25) { chunk_t *next = chunk_get_next(pc); if (next->type != CT_WORD && (get_split_pri(next->type) != 25)) { LOG_FMT(LSPLIT, "%s(%d): don't break after last term of a qualified type, return\n", __func__, __LINE__); return; } } LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); // Check levels first bool change = false; if (ent.pc == nullptr || pc->level < ent.pc->level) { LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); change = true; } else { if (pc->level >= ent.pc->level && pc_pri < ent.pri) { LOG_FMT(LSPLIT, "%s(%d):\n", __func__, __LINE__); change = true; } } LOG_FMT(LSPLIT, "%s(%d): change is %s\n", __func__, __LINE__, change ? "TRUE" : "FALSE"); if (change) { LOG_FMT(LSPLIT, "%s(%d): do the change\n", __func__, __LINE__); ent.pc = pc; ent.pri = pc_pri; } } // try_split_here