Mercurial > vim
comparison src/eval.c @ 31545:c8d4fced1f94 v9.0.1105
patch 9.0.1105: code is indented too much
Commit: https://github.com/vim/vim/commit/87c1cbbe984e60582f2536e4d3c2ce88cd474bb7
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue Dec 27 19:54:52 2022 +0000
patch 9.0.1105: code is indented too much
Problem: Code is indented too much.
Solution: Use an early return. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/11756)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 27 Dec 2022 21:00:05 +0100 |
parents | aa45593ec2ca |
children | 53c3df37a2b0 |
comparison
equal
deleted
inserted
replaced
31544:922e7109afcf | 31545:c8d4fced1f94 |
---|---|
126 void | 126 void |
127 fill_evalarg_from_eap(evalarg_T *evalarg, exarg_T *eap, int skip) | 127 fill_evalarg_from_eap(evalarg_T *evalarg, exarg_T *eap, int skip) |
128 { | 128 { |
129 init_evalarg(evalarg); | 129 init_evalarg(evalarg); |
130 evalarg->eval_flags = skip ? 0 : EVAL_EVALUATE; | 130 evalarg->eval_flags = skip ? 0 : EVAL_EVALUATE; |
131 if (eap != NULL) | 131 |
132 { | 132 if (eap == NULL) |
133 evalarg->eval_cstack = eap->cstack; | 133 return; |
134 if (sourcing_a_script(eap) || eap->getline == get_list_line) | 134 |
135 { | 135 evalarg->eval_cstack = eap->cstack; |
136 evalarg->eval_getline = eap->getline; | 136 if (sourcing_a_script(eap) || eap->getline == get_list_line) |
137 evalarg->eval_cookie = eap->cookie; | 137 { |
138 } | 138 evalarg->eval_getline = eap->getline; |
139 evalarg->eval_cookie = eap->cookie; | |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 /* | 143 /* |
143 * Top level evaluation function, returning a boolean. | 144 * Top level evaluation function, returning a boolean. |
402 * Caller is expected to overwrite "evalarg->eval_tofree" next. | 403 * Caller is expected to overwrite "evalarg->eval_tofree" next. |
403 */ | 404 */ |
404 static void | 405 static void |
405 free_eval_tofree_later(evalarg_T *evalarg) | 406 free_eval_tofree_later(evalarg_T *evalarg) |
406 { | 407 { |
407 if (evalarg->eval_tofree != NULL) | 408 if (evalarg->eval_tofree == NULL) |
408 { | 409 return; |
409 if (ga_grow(&evalarg->eval_tofree_ga, 1) == OK) | 410 |
410 ((char_u **)evalarg->eval_tofree_ga.ga_data) | 411 if (ga_grow(&evalarg->eval_tofree_ga, 1) == OK) |
411 [evalarg->eval_tofree_ga.ga_len++] | 412 ((char_u **)evalarg->eval_tofree_ga.ga_data) |
412 = evalarg->eval_tofree; | 413 [evalarg->eval_tofree_ga.ga_len++] |
414 = evalarg->eval_tofree; | |
415 else | |
416 vim_free(evalarg->eval_tofree); | |
417 } | |
418 | |
419 /* | |
420 * After using "evalarg" filled from "eap": free the memory. | |
421 */ | |
422 void | |
423 clear_evalarg(evalarg_T *evalarg, exarg_T *eap) | |
424 { | |
425 if (evalarg == NULL) | |
426 return; | |
427 | |
428 garray_T *etga = &evalarg->eval_tofree_ga; | |
429 | |
430 if (evalarg->eval_tofree != NULL || evalarg->eval_using_cmdline) | |
431 { | |
432 if (eap != NULL) | |
433 { | |
434 // We may need to keep the original command line, e.g. for | |
435 // ":let" it has the variable names. But we may also need | |
436 // the new one, "nextcmd" points into it. Keep both. | |
437 vim_free(eap->cmdline_tofree); | |
438 eap->cmdline_tofree = *eap->cmdlinep; | |
439 | |
440 if (evalarg->eval_using_cmdline && etga->ga_len > 0) | |
441 { | |
442 // "nextcmd" points into the last line in eval_tofree_ga, | |
443 // need to keep it around. | |
444 --etga->ga_len; | |
445 *eap->cmdlinep = ((char_u **)etga->ga_data)[etga->ga_len]; | |
446 vim_free(evalarg->eval_tofree); | |
447 } | |
448 else | |
449 *eap->cmdlinep = evalarg->eval_tofree; | |
450 } | |
413 else | 451 else |
414 vim_free(evalarg->eval_tofree); | 452 vim_free(evalarg->eval_tofree); |
415 } | 453 evalarg->eval_tofree = NULL; |
416 } | 454 } |
417 | 455 |
418 /* | 456 ga_clear_strings(etga); |
419 * After using "evalarg" filled from "eap": free the memory. | 457 VIM_CLEAR(evalarg->eval_tofree_lambda); |
420 */ | |
421 void | |
422 clear_evalarg(evalarg_T *evalarg, exarg_T *eap) | |
423 { | |
424 if (evalarg != NULL) | |
425 { | |
426 garray_T *etga = &evalarg->eval_tofree_ga; | |
427 | |
428 if (evalarg->eval_tofree != NULL || evalarg->eval_using_cmdline) | |
429 { | |
430 if (eap != NULL) | |
431 { | |
432 // We may need to keep the original command line, e.g. for | |
433 // ":let" it has the variable names. But we may also need | |
434 // the new one, "nextcmd" points into it. Keep both. | |
435 vim_free(eap->cmdline_tofree); | |
436 eap->cmdline_tofree = *eap->cmdlinep; | |
437 | |
438 if (evalarg->eval_using_cmdline && etga->ga_len > 0) | |
439 { | |
440 // "nextcmd" points into the last line in eval_tofree_ga, | |
441 // need to keep it around. | |
442 --etga->ga_len; | |
443 *eap->cmdlinep = ((char_u **)etga->ga_data)[etga->ga_len]; | |
444 vim_free(evalarg->eval_tofree); | |
445 } | |
446 else | |
447 *eap->cmdlinep = evalarg->eval_tofree; | |
448 } | |
449 else | |
450 vim_free(evalarg->eval_tofree); | |
451 evalarg->eval_tofree = NULL; | |
452 } | |
453 | |
454 ga_clear_strings(etga); | |
455 VIM_CLEAR(evalarg->eval_tofree_lambda); | |
456 } | |
457 } | 458 } |
458 | 459 |
459 /* | 460 /* |
460 * Skip over an expression at "*pp". | 461 * Skip over an expression at "*pp". |
461 * Return FAIL for an error, OK otherwise. | 462 * Return FAIL for an error, OK otherwise. |
3217 blob_T *b1 = tv1->vval.v_blob; | 3218 blob_T *b1 = tv1->vval.v_blob; |
3218 blob_T *b2 = tv2->vval.v_blob; | 3219 blob_T *b2 = tv2->vval.v_blob; |
3219 blob_T *b = blob_alloc(); | 3220 blob_T *b = blob_alloc(); |
3220 int i; | 3221 int i; |
3221 | 3222 |
3222 if (b != NULL) | 3223 if (b == NULL) |
3223 { | 3224 return; |
3224 for (i = 0; i < blob_len(b1); i++) | 3225 |
3225 ga_append(&b->bv_ga, blob_get(b1, i)); | 3226 for (i = 0; i < blob_len(b1); i++) |
3226 for (i = 0; i < blob_len(b2); i++) | 3227 ga_append(&b->bv_ga, blob_get(b1, i)); |
3227 ga_append(&b->bv_ga, blob_get(b2, i)); | 3228 for (i = 0; i < blob_len(b2); i++) |
3228 | 3229 ga_append(&b->bv_ga, blob_get(b2, i)); |
3229 clear_tv(tv1); | 3230 |
3230 rettv_blob_set(tv1, b); | 3231 clear_tv(tv1); |
3231 } | 3232 rettv_blob_set(tv1, b); |
3232 } | 3233 } |
3233 | 3234 |
3234 /* | 3235 /* |
3235 * Make a copy of list "tv1" and append list "tv2". | 3236 * Make a copy of list "tv1" and append list "tv2". |
3236 */ | 3237 */ |
4816 && check_for_list_arg(argvars, 0) == FAIL) | 4817 && check_for_list_arg(argvars, 0) == FAIL) |
4817 || check_for_number_arg(argvars, 1) == FAIL | 4818 || check_for_number_arg(argvars, 1) == FAIL |
4818 || check_for_opt_number_arg(argvars, 2) == FAIL)) | 4819 || check_for_opt_number_arg(argvars, 2) == FAIL)) |
4819 return; | 4820 return; |
4820 | 4821 |
4821 if (check_can_index(argvars, TRUE, FALSE) == OK) | 4822 if (check_can_index(argvars, TRUE, FALSE) != OK) |
4822 { | 4823 return; |
4823 copy_tv(argvars, rettv); | 4824 |
4824 eval_index_inner(rettv, TRUE, argvars + 1, | 4825 copy_tv(argvars, rettv); |
4825 argvars[2].v_type == VAR_UNKNOWN ? NULL : argvars + 2, | 4826 eval_index_inner(rettv, TRUE, argvars + 1, |
4826 TRUE, NULL, 0, FALSE); | 4827 argvars[2].v_type == VAR_UNKNOWN ? NULL : argvars + 2, |
4827 } | 4828 TRUE, NULL, 0, FALSE); |
4828 } | 4829 } |
4829 | 4830 |
4830 /* | 4831 /* |
4831 * Apply index or range to "rettv". | 4832 * Apply index or range to "rettv". |
4832 * "var1" is the first index, NULL for [:expr]. | 4833 * "var1" is the first index, NULL for [:expr]. |
5043 * becomes zero. | 5044 * becomes zero. |
5044 */ | 5045 */ |
5045 void | 5046 void |
5046 partial_unref(partial_T *pt) | 5047 partial_unref(partial_T *pt) |
5047 { | 5048 { |
5048 if (pt != NULL) | 5049 if (pt == NULL) |
5049 { | 5050 return; |
5050 int done = FALSE; | 5051 |
5051 | 5052 int done = FALSE; |
5052 if (--pt->pt_refcount <= 0) | 5053 |
5053 partial_free(pt); | 5054 if (--pt->pt_refcount <= 0) |
5054 | 5055 partial_free(pt); |
5055 // If the reference count goes down to one, the funcstack may be the | 5056 |
5056 // only reference and can be freed if no other partials reference it. | 5057 // If the reference count goes down to one, the funcstack may be the |
5057 else if (pt->pt_refcount == 1) | 5058 // only reference and can be freed if no other partials reference it. |
5058 { | 5059 else if (pt->pt_refcount == 1) |
5059 // careful: if the funcstack is freed it may contain this partial | 5060 { |
5060 // and it gets freed as well | 5061 // careful: if the funcstack is freed it may contain this partial |
5061 if (pt->pt_funcstack != NULL) | 5062 // and it gets freed as well |
5062 done = funcstack_check_refcount(pt->pt_funcstack); | 5063 if (pt->pt_funcstack != NULL) |
5063 | 5064 done = funcstack_check_refcount(pt->pt_funcstack); |
5064 if (!done) | 5065 |
5065 { | 5066 if (!done) |
5066 int depth; | 5067 { |
5067 | 5068 int depth; |
5068 for (depth = 0; depth < MAX_LOOP_DEPTH; ++depth) | 5069 |
5069 if (pt->pt_loopvars[depth] != NULL | 5070 for (depth = 0; depth < MAX_LOOP_DEPTH; ++depth) |
5070 && loopvars_check_refcount(pt->pt_loopvars[depth])) | 5071 if (pt->pt_loopvars[depth] != NULL |
5072 && loopvars_check_refcount(pt->pt_loopvars[depth])) | |
5071 break; | 5073 break; |
5072 } | |
5073 } | 5074 } |
5074 } | 5075 } |
5075 } | 5076 } |
5076 | 5077 |
5077 /* | 5078 /* |
7223 void | 7224 void |
7224 last_set_msg(sctx_T script_ctx) | 7225 last_set_msg(sctx_T script_ctx) |
7225 { | 7226 { |
7226 char_u *p; | 7227 char_u *p; |
7227 | 7228 |
7228 if (script_ctx.sc_sid != 0) | 7229 if (script_ctx.sc_sid == 0) |
7229 { | 7230 return; |
7230 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); | 7231 |
7231 if (p != NULL) | 7232 p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); |
7232 { | 7233 if (p == NULL) |
7233 verbose_enter(); | 7234 return; |
7234 msg_puts(_("\n\tLast set from ")); | 7235 |
7235 msg_puts((char *)p); | 7236 verbose_enter(); |
7236 if (script_ctx.sc_lnum > 0) | 7237 msg_puts(_("\n\tLast set from ")); |
7237 { | 7238 msg_puts((char *)p); |
7238 msg_puts(_(line_msg)); | 7239 if (script_ctx.sc_lnum > 0) |
7239 msg_outnum((long)script_ctx.sc_lnum); | 7240 { |
7240 } | 7241 msg_puts(_(line_msg)); |
7241 verbose_leave(); | 7242 msg_outnum((long)script_ctx.sc_lnum); |
7242 vim_free(p); | 7243 } |
7243 } | 7244 verbose_leave(); |
7244 } | 7245 vim_free(p); |
7245 } | 7246 } |
7246 | 7247 |
7247 #endif // FEAT_EVAL | 7248 #endif // FEAT_EVAL |
7248 | 7249 |
7249 /* | 7250 /* |