refactor(uncrustify): move macros definitions to enable formatting

Uncrustify struggles to format function-like macros which are defined in
deeply nested areas of the code. Un-nesting them unblocks useful
formatting rules from uncrustify.
This commit is contained in:
dundargoc 2022-10-14 16:34:39 +02:00
parent 784e498c4a
commit b967cb2e03
3 changed files with 100 additions and 95 deletions

View File

@ -3409,6 +3409,30 @@ static int check_regexp_delim(int c)
/// @return 0, 1 or 2. See show_cmdpreview() for more information on what the return value means.
static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T cmdpreview_bufnr)
{
#define ADJUST_SUB_FIRSTLNUM() \
do { \
/* For a multi-line match, make a copy of the last matched */ \
/* line and continue in that one. */ \
if (nmatch > 1) { \
sub_firstlnum += (linenr_T)nmatch - 1; \
xfree(sub_firstline); \
sub_firstline = xstrdup(ml_get(sub_firstlnum)); \
/* When going beyond the last line, stop substituting. */ \
if (sub_firstlnum <= line2) { \
do_again = true; \
} else { \
subflags.do_all = false; \
} \
} \
if (skip_match) { \
/* Already hit end of the buffer, sub_firstlnum is one */ \
/* less than what it ought to be. */ \
xfree(sub_firstline); \
sub_firstline = xstrdup(""); \
copycol = 0; \
} \
} while (0)
long i = 0;
regmmatch_T regmatch;
static subflags_T subflags = {
@ -3980,30 +4004,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
skip_match = true;
}
#define ADJUST_SUB_FIRSTLNUM() \
do { \
/* For a multi-line match, make a copy of the last matched */ \
/* line and continue in that one. */ \
if (nmatch > 1) { \
sub_firstlnum += (linenr_T)nmatch - 1; \
xfree(sub_firstline); \
sub_firstline = xstrdup(ml_get(sub_firstlnum)); \
/* When going beyond the last line, stop substituting. */ \
if (sub_firstlnum <= line2) { \
do_again = true; \
} else { \
subflags.do_all = false; \
} \
} \
if (skip_match) { \
/* Already hit end of the buffer, sub_firstlnum is one */ \
/* less than what it ought to be. */ \
xfree(sub_firstline); \
sub_firstline = xstrdup(""); \
copycol = 0; \
} \
} while (0)
// Save the line numbers for the preview buffer
// NOTE: If the pattern matches a final newline, the next line will
// be shown also, but should not be highlighted. Intentional for now.

View File

@ -1557,6 +1557,18 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
(sd_default_values[(entry).type].data.attr == (entry).data.attr)
#define ONE_IF_NOT_DEFAULT(entry, attr) \
((size_t)(!CHECK_DEFAULT(entry, attr)))
#define PACK_BOOL(entry, name, attr) \
do { \
if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
PACK_STATIC_STR(name); \
if (sd_default_values[(entry).type].data.search_pattern.attr) { \
msgpack_pack_false(spacker); \
} else { \
msgpack_pack_true(spacker); \
} \
} \
} while (0)
switch (entry.type) {
case kSDItemMissing:
abort();
@ -1640,17 +1652,6 @@ static ShaDaWriteResult shada_pack_entry(msgpack_packer *const packer, ShadaEntr
msgpack_pack_map(spacker, map_size);
PACK_STATIC_STR(SEARCH_KEY_PAT);
PACK_BIN(cstr_as_string(entry.data.search_pattern.pat));
#define PACK_BOOL(entry, name, attr) \
do { \
if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
PACK_STATIC_STR(name); \
if (sd_default_values[(entry).type].data.search_pattern.attr) { \
msgpack_pack_false(spacker); \
} else { \
msgpack_pack_true(spacker); \
} \
} \
} while (0)
PACK_BOOL(entry, SEARCH_KEY_MAGIC, magic);
PACK_BOOL(entry, SEARCH_KEY_IS_LAST_USED, is_last_used);
PACK_BOOL(entry, SEARCH_KEY_SMARTCASE, smartcase);
@ -1957,6 +1958,28 @@ static const char *shada_format_entry(const ShadaEntry entry)
ret[0] = 0;
vim_snprintf(S_LEN(ret), "%s", "[ ] ts=%" PRIu64 " ");
// ^ Space for `can_free_entry`
#define FORMAT_MARK_ENTRY(entry_name, name_fmt, name_fmt_arg) \
do { \
typval_T ad_tv = { \
.v_type = VAR_DICT, \
.vval.v_dict = entry.data.filemark.additional_data \
}; \
size_t ad_len; \
char *const ad = encode_tv2string(&ad_tv, &ad_len); \
vim_snprintf_add(S_LEN(ret), \
entry_name " {" name_fmt " file=[%zu]\"%.512s\", " \
"pos={l=%" PRIdLINENR ",c=%" PRIdCOLNR ",a=%" PRIdCOLNR "}, " \
"ad={%p:[%zu]%.64s} }", \
name_fmt_arg, \
strlen(entry.data.filemark.fname), \
entry.data.filemark.fname, \
entry.data.filemark.mark.lnum, \
entry.data.filemark.mark.col, \
entry.data.filemark.mark.coladd, \
(void *)entry.data.filemark.additional_data, \
ad_len, \
ad); \
} while (0)
switch (entry.type) {
case kSDItemMissing:
vim_snprintf_add(S_LEN(ret), "Missing");
@ -1985,28 +2008,6 @@ static const char *shada_format_entry(const ShadaEntry entry)
case kSDItemVariable:
vim_snprintf_add(S_LEN(ret), "Variable { TODO }");
break;
#define FORMAT_MARK_ENTRY(entry_name, name_fmt, name_fmt_arg) \
do { \
typval_T ad_tv = { \
.v_type = VAR_DICT, \
.vval.v_dict = entry.data.filemark.additional_data \
}; \
size_t ad_len; \
char *const ad = encode_tv2string(&ad_tv, &ad_len); \
vim_snprintf_add(S_LEN(ret), \
entry_name " {" name_fmt " file=[%zu]\"%.512s\", " \
"pos={l=%" PRIdLINENR ",c=%" PRIdCOLNR ",a=%" PRIdCOLNR "}, " \
"ad={%p:[%zu]%.64s} }", \
name_fmt_arg, \
strlen(entry.data.filemark.fname), \
entry.data.filemark.fname, \
entry.data.filemark.mark.lnum, \
entry.data.filemark.mark.col, \
entry.data.filemark.mark.coladd, \
(void *)entry.data.filemark.additional_data, \
ad_len, \
ad); \
} while (0)
case kSDItemGlobalMark:
FORMAT_MARK_ENTRY("GlobalMark", " name='%c',", entry.data.filemark.name);
break;
@ -2055,6 +2056,32 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re
ShaDaWriteResult ret = kSDWriteSuccessfull;
ShadaEntry entry;
ShaDaReadResult srni_ret;
#define COMPARE_WITH_ENTRY(wms_entry_, entry) \
do { \
PossiblyFreedShadaEntry *const wms_entry = (wms_entry_); \
if (wms_entry->data.type != kSDItemMissing) { \
if (wms_entry->data.timestamp >= (entry).timestamp) { \
shada_free_shada_entry(&(entry)); \
break; \
} \
if (wms_entry->can_free_entry) { \
shada_free_shada_entry(&wms_entry->data); \
} \
} \
*wms_entry = pfs_entry; \
} while (0)
#define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \
do { \
if ((entry).can_free_entry) { \
shada_free_shada_entry(&(entry).data); \
} \
} while (0)
#define SDE_TO_PFSDE(entry) \
((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = (entry) })
while ((srni_ret = shada_read_next_item(sd_reader, &entry, srni_flags,
max_kbyte))
!= kSDReadStatusFinished) {
@ -2072,20 +2099,6 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re
case kSDReadStatusMalformed:
continue;
}
#define COMPARE_WITH_ENTRY(wms_entry_, entry) \
do { \
PossiblyFreedShadaEntry *const wms_entry = (wms_entry_); \
if (wms_entry->data.type != kSDItemMissing) { \
if (wms_entry->data.timestamp >= (entry).timestamp) { \
shada_free_shada_entry(&(entry)); \
break; \
} \
if (wms_entry->can_free_entry) { \
shada_free_shada_entry(&wms_entry->data); \
} \
} \
*wms_entry = pfs_entry; \
} while (0)
const PossiblyFreedShadaEntry pfs_entry = {
.can_free_entry = true,
.data = entry,
@ -2225,14 +2238,6 @@ static inline ShaDaWriteResult shada_read_when_writing(ShaDaReadDef *const sd_re
*wms_entry = pfs_entry;
}
} else {
#define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry) \
do { \
if ((entry).can_free_entry) { \
shada_free_shada_entry(&(entry).data); \
} \
} while (0)
#define SDE_TO_PFSDE(entry) \
((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = (entry) })
#define AFTERFREE_DUMMY(entry)
#define DUMMY_IDX_ADJ(i)
MERGE_JUMPS(filemarks->changes_size, filemarks->changes,

View File

@ -2120,6 +2120,22 @@ viml_pexpr_parse_process_token:
assert(kv_size(pt_stack));
const ExprASTParseType cur_pt = kv_last(pt_stack);
assert(lambda_node == NULL || cur_pt == kEPTLambdaArguments);
#define SIMPLE_UB_OP(op) \
case kExprLex##op: { \
if (want_node == kENodeValue) { \
/* Value level: assume unary operator. */ \
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeUnary##op); \
*top_node_p = cur_node; \
kvi_push(ast_stack, &cur_node->children); \
HL_CUR_TOKEN(Unary##op); \
} else { \
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeBinary##op); \
ADD_OP_NODE(cur_node); \
HL_CUR_TOKEN(Binary##op); \
} \
want_node = kENodeValue; \
break; \
}
switch (tok_type) {
case kExprLexMissing:
case kExprLexSpacing:
@ -2141,22 +2157,6 @@ viml_pexpr_parse_process_token:
HL_CUR_TOKEN(Register);
break;
}
#define SIMPLE_UB_OP(op) \
case kExprLex##op: { \
if (want_node == kENodeValue) { \
/* Value level: assume unary operator. */ \
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeUnary##op); \
*top_node_p = cur_node; \
kvi_push(ast_stack, &cur_node->children); \
HL_CUR_TOKEN(Unary##op); \
} else { \
NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeBinary##op); \
ADD_OP_NODE(cur_node); \
HL_CUR_TOKEN(Binary##op); \
} \
want_node = kENodeValue; \
break; \
}
SIMPLE_UB_OP(Plus)
SIMPLE_UB_OP(Minus)
#undef SIMPLE_UB_OP