refactor: format with uncrustify #15726

This commit is contained in:
dundargoc
2021-09-20 15:53:38 +02:00
committed by GitHub
parent 490e09c6d8
commit 30fefee684
10 changed files with 2210 additions and 2116 deletions

View File

@@ -7,23 +7,23 @@
///
/// Functions for Ex command line for the +eval feature.
#include <assert.h>
#include <stdbool.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/debugger.h"
#include "nvim/ex_eval.h"
#include "nvim/charset.h"
#include "nvim/debugger.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/message.h"
#include "nvim/ex_eval.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_eval.c.generated.h"
@@ -111,8 +111,9 @@ int aborting(void)
*/
void update_force_abort(void)
{
if (cause_abort)
if (cause_abort) {
force_abort = TRUE;
}
}
/*
@@ -248,8 +249,9 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
*/
if (msg_list != NULL) {
plist = msg_list;
while (*plist != NULL)
while (*plist != NULL) {
plist = &(*plist)->next;
}
elem = xmalloc(sizeof(struct msglist));
elem->msg = vim_strsave(mesg);
@@ -257,19 +259,20 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
elem->throw_msg = NULL;
*plist = elem;
if (plist == msg_list || severe) {
char_u *tmsg;
char_u *tmsg;
/* Skip the extra "Vim " prefix for message "E458". */
// Skip the extra "Vim " prefix for message "E458".
tmsg = elem->msg;
if (STRNCMP(tmsg, "Vim E", 5) == 0
&& ascii_isdigit(tmsg[5])
&& ascii_isdigit(tmsg[6])
&& ascii_isdigit(tmsg[7])
&& tmsg[8] == ':'
&& tmsg[9] == ' ')
&& tmsg[9] == ' ') {
(*msg_list)->throw_msg = &tmsg[4];
else
} else {
(*msg_list)->throw_msg = tmsg;
}
}
}
return true;
@@ -281,7 +284,7 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
*/
static void free_msglist(struct msglist *l)
{
struct msglist *messages, *next;
struct msglist *messages, *next;
messages = l;
while (messages != NULL) {
@@ -320,16 +323,18 @@ void do_errthrow(cstack_T *cstack, char_u *cmdname)
/* If no exception is to be thrown or the conversion should be done after
* returning to a previous invocation of do_one_cmd(), do nothing. */
if (msg_list == NULL || *msg_list == NULL)
if (msg_list == NULL || *msg_list == NULL) {
return;
}
if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL)
if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL) {
free_msglist(*msg_list);
else {
if (cstack != NULL)
} else {
if (cstack != NULL) {
do_throw(cstack);
else
} else {
need_rethrow = TRUE;
}
}
*msg_list = NULL;
}
@@ -357,36 +362,35 @@ int do_intthrow(cstack_T *cstack)
}
} else {
#endif
// Throw an interrupt exception, so that everything will be aborted
// (except for executing finally clauses), until the interrupt exception
// is caught; if still uncaught at the top level, the script processing
// will be terminated then. - If an interrupt exception is already
// being thrown, do nothing.
// Throw an interrupt exception, so that everything will be aborted
// (except for executing finally clauses), until the interrupt exception
// is caught; if still uncaught at the top level, the script processing
// will be terminated then. - If an interrupt exception is already
// being thrown, do nothing.
if (current_exception) {
if (current_exception->type == ET_INTERRUPT) {
return false;
}
if (current_exception) {
if (current_exception->type == ET_INTERRUPT) {
return false;
}
// An interrupt exception replaces any user or error exception.
discard_current_exception();
}
if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) {
do_throw(cstack);
}
#ifdef THROW_TEST
// An interrupt exception replaces any user or error exception.
discard_current_exception();
}
if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) {
do_throw(cstack);
}
#ifdef THROW_TEST
}
#endif
return true;
}
// Get an exception message that is to be stored in current_exception->value.
char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
int *should_free)
char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname, int *should_free)
{
char_u *ret, *mesg;
char_u *p, *val;
char_u *ret, *mesg;
char_u *p, *val;
if (type == ET_ERROR) {
*should_free = true;
@@ -434,7 +438,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
}
} else {
*should_free = FALSE;
ret = (char_u *) value;
ret = (char_u *)value;
}
return ret;
@@ -447,7 +451,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
// error exception.
static int throw_exception(void *value, except_type_T type, char_u *cmdname)
{
except_T *excp;
except_T *excp;
int should_free;
/*
@@ -466,14 +470,16 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
excp = xmalloc(sizeof(except_T));
if (type == ET_ERROR)
if (type == ET_ERROR) {
/* Store the original message and prefix the exception value with
* "Vim:" or, if a command name is given, "Vim(cmdname):". */
excp->messages = (struct msglist *)value;
}
excp->value = get_exception_string(value, type, cmdname, &should_free);
if (excp->value == NULL && should_free)
if (excp->value == NULL && should_free) {
goto nomem;
}
excp->type = type;
excp->throw_name = vim_strsave(sourcing_name == NULL
@@ -483,24 +489,27 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
if (debug_break_level > 0)
msg_silent = FALSE; /* display messages */
else
if (debug_break_level > 0) {
msg_silent = FALSE; // display messages
} else {
verbose_enter();
}
++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL)
msg_scroll = TRUE; /* always scroll up, don't overwrite */
if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(_("Exception thrown: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either
if (debug_break_level > 0 || *p_vfile == NUL)
if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row;
}
--no_wait_return;
if (debug_break_level > 0)
if (debug_break_level > 0) {
msg_silent = save_msg_silent;
else
} else {
verbose_leave();
}
}
current_exception = excp;
@@ -521,7 +530,7 @@ fail:
*/
static void discard_exception(except_T *excp, bool was_finished)
{
char_u *saved_IObuff;
char_u *saved_IObuff;
if (current_exception == excp) {
current_exception = NULL;
@@ -535,13 +544,15 @@ static void discard_exception(except_T *excp, bool was_finished)
int save_msg_silent = msg_silent;
saved_IObuff = vim_strsave(IObuff);
if (debug_break_level > 0)
msg_silent = FALSE; /* display messages */
else
if (debug_break_level > 0) {
msg_silent = FALSE; // display messages
} else {
verbose_enter();
}
++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL)
msg_scroll = TRUE; /* always scroll up, don't overwrite */
if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(was_finished ? _("Exception finished: %s")
: _("Exception discarded: %s"),
excp->value);
@@ -558,10 +569,12 @@ static void discard_exception(except_T *excp, bool was_finished)
xstrlcpy((char *)IObuff, (const char *)saved_IObuff, IOSIZE);
xfree(saved_IObuff);
}
if (excp->type != ET_INTERRUPT)
if (excp->type != ET_INTERRUPT) {
xfree(excp->value);
if (excp->type == ET_ERROR)
}
if (excp->type == ET_ERROR) {
free_msglist(excp->messages);
}
xfree(excp->throw_name);
xfree(excp);
}
@@ -586,7 +599,7 @@ static void catch_exception(except_T *excp)
{
excp->caught = caught_stack;
caught_stack = excp;
set_vim_var_string(VV_EXCEPTION, (char *) excp->value, -1);
set_vim_var_string(VV_EXCEPTION, (char *)excp->value, -1);
if (*excp->throw_name != NUL) {
if (excp->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE, _("%s, line %" PRId64),
@@ -594,7 +607,7 @@ static void catch_exception(except_T *excp)
} else {
vim_snprintf((char *)IObuff, IOSIZE, "%s", excp->throw_name);
}
set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1);
set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else {
// throw_name not set on an exception from a command that was typed.
set_vim_var_string(VV_THROWPOINT, NULL, -1);
@@ -603,24 +616,27 @@ static void catch_exception(except_T *excp)
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
if (debug_break_level > 0)
msg_silent = FALSE; /* display messages */
else
if (debug_break_level > 0) {
msg_silent = FALSE; // display messages
} else {
verbose_enter();
}
++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL)
msg_scroll = TRUE; /* always scroll up, don't overwrite */
if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(_("Exception caught: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either
if (debug_break_level > 0 || *p_vfile == NUL)
if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row;
}
--no_wait_return;
if (debug_break_level > 0)
if (debug_break_level > 0) {
msg_silent = save_msg_silent;
else
} else {
verbose_leave();
}
}
}
@@ -634,7 +650,7 @@ static void finish_exception(except_T *excp)
}
caught_stack = caught_stack->caught;
if (caught_stack != NULL) {
set_vim_var_string(VV_EXCEPTION, (char *) caught_stack->value, -1);
set_vim_var_string(VV_EXCEPTION, (char *)caught_stack->value, -1);
if (*caught_stack->throw_name != NUL) {
if (caught_stack->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE,
@@ -644,7 +660,7 @@ static void finish_exception(except_T *excp)
vim_snprintf((char *)IObuff, IOSIZE, "%s",
caught_stack->throw_name);
}
set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1);
set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else {
// throw_name not set on an exception from a command that was
// typed.
@@ -688,7 +704,7 @@ static void report_pending(int action, int pending, void *value)
case RP_RESUME:
mesg = _("%s resumed");
break;
/* case RP_DISCARD: */
// case RP_DISCARD:
default:
mesg = _("%s discarded");
break;
@@ -708,7 +724,7 @@ static void report_pending(int action, int pending, void *value)
s = ":finish";
break;
case CSTP_RETURN:
/* ":return" command producing value, allocated */
// ":return" command producing value, allocated
s = (char *)get_return_cmd(value);
break;
@@ -718,30 +734,34 @@ static void report_pending(int action, int pending, void *value)
mesg, _("Exception"));
mesg = (char *)concat_str(IObuff, (char_u *)": %s");
s = (char *)((except_T *)value)->value;
} else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT))
} else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT)) {
s = _("Error and interrupt");
else if (pending & CSTP_ERROR)
} else if (pending & CSTP_ERROR) {
s = _("Error");
else /* if (pending & CSTP_INTERRUPT) */
} else { // if (pending & CSTP_INTERRUPT)
s = _("Interrupt");
}
}
save_msg_silent = msg_silent;
if (debug_break_level > 0)
msg_silent = FALSE; /* display messages */
if (debug_break_level > 0) {
msg_silent = FALSE; // display messages
}
++no_wait_return;
msg_scroll = TRUE; /* always scroll up, don't overwrite */
msg_scroll = TRUE; // always scroll up, don't overwrite
smsg(mesg, s);
msg_puts("\n"); // don't overwrite this either
cmdline_row = msg_row;
--no_wait_return;
if (debug_break_level > 0)
if (debug_break_level > 0) {
msg_silent = save_msg_silent;
}
if (pending == CSTP_RETURN)
if (pending == CSTP_RETURN) {
xfree(s);
else if (pending & CSTP_THROW)
} else if (pending & CSTP_THROW) {
xfree(mesg);
}
}
/*
@@ -751,11 +771,13 @@ static void report_pending(int action, int pending, void *value)
void report_make_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_enter();
}
report_pending(RP_MAKE, pending, value);
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_leave();
}
}
}
@@ -766,11 +788,13 @@ void report_make_pending(int pending, void *value)
void report_resume_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_enter();
}
report_pending(RP_RESUME, pending, value);
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_leave();
}
}
}
@@ -781,11 +805,13 @@ void report_resume_pending(int pending, void *value)
void report_discard_pending(int pending, void *value)
{
if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_enter();
}
report_pending(RP_DISCARD, pending, value);
if (debug_break_level <= 0)
if (debug_break_level <= 0) {
verbose_leave();
}
}
}
@@ -808,9 +834,9 @@ void ex_if(exarg_T *eap)
int result;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1)
if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E579: :if nesting too deep");
else {
} else {
++cstack->cs_idx;
cstack->cs_flags[cstack->cs_idx] = 0;
@@ -820,11 +846,13 @@ void ex_if(exarg_T *eap)
result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
if (!skip && !error) {
if (result)
if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
} else
/* set TRUE, so this conditional will never get active */
}
} else {
// set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
}
}
}
@@ -884,13 +912,15 @@ void ex_else(exarg_T *eap)
skip = TRUE;
}
/* if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it */
// if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it
if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) {
if (eap->errmsg == NULL)
if (eap->errmsg == NULL) {
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
skip = TRUE; /* don't evaluate an ":elseif" */
} else
}
skip = TRUE; // don't evaluate an ":elseif"
} else {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE;
}
/*
* When debugging or a breakpoint was encountered, display the debug prompt
@@ -917,15 +947,18 @@ void ex_else(exarg_T *eap)
* case, the parsing error will be ignored by emsg(). */
if (!skip && !error) {
if (result)
if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
else
} else {
cstack->cs_flags[cstack->cs_idx] = 0;
} else if (eap->errmsg == NULL)
/* set TRUE, so this conditional will never get active */
}
} else if (eap->errmsg == NULL) {
// set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
} else
}
} else {
cstack->cs_flags[cstack->cs_idx] |= CSF_ELSE;
}
}
/*
@@ -938,9 +971,9 @@ void ex_while(exarg_T *eap)
int result;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1)
if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E585: :while/:for nesting too deep");
else {
} else {
/*
* The loop flag is set when we have jumped back from the matching
* ":endwhile" or ":endfor". When not set, need to initialise this
@@ -972,16 +1005,17 @@ void ex_while(exarg_T *eap)
fi = cstack->cs_forinfo[cstack->cs_idx];
error = FALSE;
} else {
/* Evaluate the argument and get the info in a structure. */
// Evaluate the argument and get the info in a structure.
fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip);
cstack->cs_forinfo[cstack->cs_idx] = fi;
}
/* use the element at the start of the list and advance */
if (!error && fi != NULL && !skip)
// use the element at the start of the list and advance
if (!error && fi != NULL && !skip) {
result = next_for_item(fi, eap->arg);
else
} else {
result = FALSE;
}
if (!result) {
free_for_info(fi);
@@ -1003,8 +1037,9 @@ void ex_while(exarg_T *eap)
* the list, show the debug prompt at the ":endwhile"/":endfor" as
* if there was a ":break" in a ":while"/":for" evaluating to
* TRUE. */
if (!skip && !error)
if (!skip && !error) {
cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE;
}
}
}
}
@@ -1017,9 +1052,9 @@ void ex_continue(exarg_T *eap)
int idx;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E586: :continue without :while or :for");
else {
} else {
/* Try to find the matching ":while". This might stop at a try
* conditional not in its finally clause (which is then to be executed
* next). Therefore, deactivate all conditionals except the ":while"
@@ -1033,7 +1068,7 @@ void ex_continue(exarg_T *eap)
* Set CSL_HAD_CONT, so do_cmdline() will jump back to the
* matching ":while".
*/
cstack->cs_lflags |= CSL_HAD_CONT; /* let do_cmdline() handle it */
cstack->cs_lflags |= CSL_HAD_CONT; // let do_cmdline() handle it
} else {
/* If a try conditional not in its finally clause is reached first,
* make the ":continue" pending for execution at the ":endtry". */
@@ -1073,7 +1108,7 @@ void ex_endwhile(exarg_T *eap)
{
cstack_T *const cstack = eap->cstack;
int idx;
char_u *err;
char_u *err;
int csf;
int fl;
@@ -1085,24 +1120,26 @@ void ex_endwhile(exarg_T *eap)
csf = CSF_FOR;
}
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = err;
else {
} else {
fl = cstack->cs_flags[cstack->cs_idx];
if (!(fl & csf)) {
/* If we are in a ":while" or ":for" but used the wrong endloop
* command, do not rewind to the next enclosing ":for"/":while". */
if (fl & CSF_WHILE)
if (fl & CSF_WHILE) {
eap->errmsg = (char_u *)_("E732: Using :endfor with :while");
else if (fl & CSF_FOR)
} else if (fl & CSF_FOR) {
eap->errmsg = (char_u *)_("E733: Using :endwhile with :for");
}
}
if (!(fl & (CSF_WHILE | CSF_FOR))) {
if (!(fl & CSF_TRY))
if (!(fl & CSF_TRY)) {
eap->errmsg = e_endif;
else if (fl & CSF_FINALLY)
} else if (fl & CSF_FINALLY) {
eap->errmsg = e_endtry;
/* Try to find the matching ":while" and report what's missing. */
}
// Try to find the matching ":while" and report what's missing.
for (idx = cstack->cs_idx; idx > 0; --idx) {
fl = cstack->cs_flags[idx];
if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) {
@@ -1111,10 +1148,11 @@ void ex_endwhile(exarg_T *eap)
eap->errmsg = err;
return;
}
if (fl & csf)
if (fl & csf) {
break;
}
}
/* Cleanup and rewind all contained (and unclosed) conditionals. */
// Cleanup and rewind all contained (and unclosed) conditionals.
(void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
}
@@ -1130,8 +1168,9 @@ void ex_endwhile(exarg_T *eap)
*/
else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE
&& !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE)
&& dbg_check_skipped(eap))
&& dbg_check_skipped(eap)) {
(void)do_intthrow(cstack);
}
/*
* Set loop flag, so do_cmdline() will jump back to the matching
@@ -1216,13 +1255,14 @@ void do_throw(cstack_T *cstack)
* the matching catch clause or the finally clause.
*/
if (!(cstack->cs_flags[idx] & CSF_CAUGHT)) {
if (cstack->cs_flags[idx] & CSF_ACTIVE)
if (cstack->cs_flags[idx] & CSF_ACTIVE) {
cstack->cs_flags[idx] |= CSF_THROWN;
else
} else {
/* THROWN may have already been set for a catchable exception
* that has been discarded. Ensure it is reset for the new
* exception. */
cstack->cs_flags[idx] &= ~CSF_THROWN;
}
}
cstack->cs_flags[idx] &= ~CSF_ACTIVE;
cstack->cs_exception[idx] = current_exception;
@@ -1237,9 +1277,9 @@ void ex_try(exarg_T *eap)
int skip;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1)
if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E601: :try nesting too deep");
else {
} else {
++cstack->cs_idx;
++cstack->cs_trylevel;
cstack->cs_flags[cstack->cs_idx] = CSF_TRY;
@@ -1278,7 +1318,6 @@ void ex_try(exarg_T *eap)
emsg_silent = 0;
}
}
}
}
@@ -1291,13 +1330,13 @@ void ex_catch(exarg_T *eap)
int give_up = FALSE;
int skip = FALSE;
int caught = FALSE;
char_u *end;
char_u *end;
char_u save_char = 0;
char_u *save_cpo;
char_u *save_cpo;
regmatch_T regmatch;
int prev_got_int;
cstack_T *const cstack = eap->cstack;
char_u *pat;
char_u *pat;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E603: :catch without :try");
@@ -1309,20 +1348,23 @@ void ex_catch(exarg_T *eap)
eap->errmsg = get_end_emsg(cstack);
skip = TRUE;
}
for (idx = cstack->cs_idx; idx > 0; --idx)
if (cstack->cs_flags[idx] & CSF_TRY)
for (idx = cstack->cs_idx; idx > 0; --idx) {
if (cstack->cs_flags[idx] & CSF_TRY) {
break;
}
}
if (cstack->cs_flags[idx] & CSF_FINALLY) {
/* Give up for a ":catch" after ":finally" and ignore it.
* Just parse. */
eap->errmsg = (char_u *)N_("E604: :catch after :finally");
give_up = TRUE;
} else
} else {
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
&cstack->cs_looplevel);
&cstack->cs_looplevel);
}
}
if (ends_excmd(*eap->arg)) { /* no argument, catch all errors */
if (ends_excmd(*eap->arg)) { // no argument, catch all errors
pat = (char_u *)".*";
end = NULL;
eap->nextcmd = find_nextcmd(eap->arg);
@@ -1390,7 +1432,7 @@ void ex_catch(exarg_T *eap)
prev_got_int = got_int;
got_int = FALSE;
caught = vim_regexec_nl(&regmatch, current_exception->value,
(colnr_T)0);
(colnr_T)0);
got_int |= prev_got_int;
vim_regfree(regmatch.regprog);
}
@@ -1430,8 +1472,9 @@ void ex_catch(exarg_T *eap)
}
}
if (end != NULL)
if (end != NULL) {
eap->nextcmd = find_nextcmd(end);
}
}
/*
@@ -1444,28 +1487,31 @@ void ex_finally(exarg_T *eap)
int pending = CSTP_NONE;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0)
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E606: :finally without :try");
else {
} else {
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack);
for (idx = cstack->cs_idx - 1; idx > 0; --idx)
if (cstack->cs_flags[idx] & CSF_TRY)
for (idx = cstack->cs_idx - 1; idx > 0; --idx) {
if (cstack->cs_flags[idx] & CSF_TRY) {
break;
}
}
/* Make this error pending, so that the commands in the following
* finally clause can be executed. This overrules also a pending
* ":continue", ":break", ":return", or ":finish". */
pending = CSTP_ERROR;
} else
} else {
idx = cstack->cs_idx;
}
if (cstack->cs_flags[idx] & CSF_FINALLY) {
/* Give up for a multiple ":finally" and ignore it. */
// Give up for a multiple ":finally" and ignore it.
eap->errmsg = (char_u *)N_("E607: multiple :finally");
return;
}
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
&cstack->cs_looplevel);
&cstack->cs_looplevel);
/*
* Don't do something when the corresponding try block never got active
@@ -1517,7 +1563,7 @@ void ex_finally(exarg_T *eap)
if (pending == CSTP_ERROR || did_emsg || got_int || current_exception) {
if (cstack->cs_pending[cstack->cs_idx] == CSTP_RETURN) {
report_discard_pending(CSTP_RETURN,
cstack->cs_rettv[cstack->cs_idx]);
cstack->cs_rettv[cstack->cs_idx]);
discard_pending_return(cstack->cs_rettv[cstack->cs_idx]);
}
if (pending == CSTP_ERROR && !did_emsg) {
@@ -1564,7 +1610,7 @@ void ex_endtry(exarg_T *eap)
int skip;
int rethrow = FALSE;
int pending = CSTP_NONE;
void *rettv = NULL;
void *rettv = NULL;
cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
@@ -1585,13 +1631,13 @@ void ex_endtry(exarg_T *eap)
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack);
/* Find the matching ":try" and report what's missing. */
// Find the matching ":try" and report what's missing.
idx = cstack->cs_idx;
do
--idx;
while (idx > 0 && !(cstack->cs_flags[idx] & CSF_TRY));
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
&cstack->cs_looplevel);
&cstack->cs_looplevel);
skip = TRUE;
/*
@@ -1656,10 +1702,11 @@ void ex_endtry(exarg_T *eap)
if (!skip) {
pending = cstack->cs_pending[idx];
cstack->cs_pending[idx] = CSTP_NONE;
if (pending == CSTP_RETURN)
if (pending == CSTP_RETURN) {
rettv = cstack->cs_rettv[idx];
else if (pending & CSTP_THROW)
} else if (pending & CSTP_THROW) {
current_exception = cstack->cs_exception[idx];
}
}
/*
@@ -1679,8 +1726,8 @@ void ex_endtry(exarg_T *eap)
if (!skip) {
report_resume_pending(pending,
(pending == CSTP_RETURN) ? rettv :
(pending & CSTP_THROW) ? (void *)current_exception : NULL);
(pending == CSTP_RETURN) ? rettv :
(pending & CSTP_THROW) ? (void *)current_exception : NULL);
switch (pending) {
case CSTP_NONE:
break;
@@ -1788,7 +1835,7 @@ void enter_cleanup(cleanup_T *csp)
did_emsg = got_int = need_rethrow = false;
current_exception = NULL;
/* Report if required by the 'verbose' option or when debugging. */
// Report if required by the 'verbose' option or when debugging.
report_make_pending(pending, csp->exception);
} else {
csp->pending = CSTP_NONE;
@@ -1815,8 +1862,9 @@ void leave_cleanup(cleanup_T *csp)
{
int pending = csp->pending;
if (pending == CSTP_NONE) /* nothing to do */
if (pending == CSTP_NONE) { // nothing to do
return;
}
/* If there was an aborting error, an interrupt, or an uncaught exception
* after the corresponding call to enter_cleanup(), discard what has been
@@ -1832,8 +1880,9 @@ void leave_cleanup(cleanup_T *csp)
/* If an error was about to be converted to an exception when
* enter_cleanup() was called, free the message list. */
if (msg_list != NULL)
if (msg_list != NULL) {
free_global_msglist();
}
}
/*
* If there was no new error, interrupt, or throw between the calls
@@ -1846,9 +1895,9 @@ void leave_cleanup(cleanup_T *csp)
* called, we need to rethrow it. Make it the exception currently
* being thrown.
*/
if (pending & CSTP_THROW)
if (pending & CSTP_THROW) {
current_exception = csp->exception;
}
/*
* If an error was about to be converted to an exception when
* enter_cleanup() was called, let "cause_abort" take the part of
@@ -1871,8 +1920,7 @@ void leave_cleanup(cleanup_T *csp)
}
// Report if required by the 'verbose' option or when debugging.
report_resume_pending(
pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
report_resume_pending(pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
}
}
@@ -1920,7 +1968,7 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
case CSTP_RETURN:
report_discard_pending(CSTP_RETURN,
cstack->cs_rettv[idx]);
cstack->cs_rettv[idx]);
discard_pending_return(cstack->cs_rettv[idx]);
cstack->cs_pending[idx] = CSTP_NONE;
break;
@@ -1948,15 +1996,17 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
if (!(cstack->cs_flags[idx] & CSF_FINALLY)) {
if ((cstack->cs_flags[idx] & CSF_ACTIVE)
&& (cstack->cs_flags[idx] & CSF_CAUGHT))
&& (cstack->cs_flags[idx] & CSF_CAUGHT)) {
finish_exception((except_T *)cstack->cs_exception[idx]);
}
/* Stop at this try conditional - except the try block never
* got active (because of an inactive surrounding conditional
* or when the ":try" appeared after an error or interrupt or
* throw). */
if (cstack->cs_flags[idx] & CSF_TRUE) {
if (searched_cond == 0 && !inclusive)
if (searched_cond == 0 && !inclusive) {
break;
}
stop = TRUE;
}
}
@@ -1967,13 +2017,15 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
* If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT,
* check first whether "emsg_silent" needs to be restored. */
if (cstack->cs_flags[idx] & searched_cond) {
if (!inclusive)
if (!inclusive) {
break;
}
stop = TRUE;
}
cstack->cs_flags[idx] &= ~CSF_ACTIVE;
if (stop && searched_cond != (CSF_TRY | CSF_SILENT))
if (stop && searched_cond != (CSF_TRY | CSF_SILENT)) {
break;
}
/*
* When leaving a try conditional that reset "emsg_silent" on its
@@ -1982,7 +2034,7 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
if ((cstack->cs_flags[idx] & CSF_TRY)
&& (cstack->cs_flags[idx] & CSF_SILENT)) {
eslist_T *elem;
eslist_T *elem;
elem = cstack->cs_emsg_silent_list;
cstack->cs_emsg_silent_list = elem->next;
@@ -1990,8 +2042,9 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
xfree(elem);
cstack->cs_flags[idx] &= ~CSF_SILENT;
}
if (stop)
if (stop) {
break;
}
}
return idx;
}
@@ -2001,10 +2054,12 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/
static char_u *get_end_emsg(cstack_T *cstack)
{
if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE)
if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) {
return e_endwhile;
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR)
}
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
return e_endfor;
}
return e_endif;
}
@@ -2016,14 +2071,15 @@ static char_u *get_end_emsg(cstack_T *cstack)
* type.
* Also free "for info" structures where needed.
*/
void rewind_conditionals(cstack_T *cstack, int idx, int cond_type,
int *cond_level)
void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, int *cond_level)
{
while (cstack->cs_idx > idx) {
if (cstack->cs_flags[cstack->cs_idx] & cond_type)
if (cstack->cs_flags[cstack->cs_idx] & cond_type) {
--*cond_level;
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR)
}
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
free_for_info(cstack->cs_forinfo[cstack->cs_idx]);
}
--cstack->cs_idx;
}
}
@@ -2043,18 +2099,21 @@ int has_loop_cmd(char_u *p)
{
int len;
/* skip modifiers, white space and ':' */
// skip modifiers, white space and ':'
for (;; ) {
while (*p == ' ' || *p == '\t' || *p == ':')
while (*p == ' ' || *p == '\t' || *p == ':') {
++p;
}
len = modifier_len(p);
if (len == 0)
if (len == 0) {
break;
}
p += len;
}
if ((p[0] == 'w' && p[1] == 'h')
|| (p[0] == 'f' && p[1] == 'o' && p[2] == 'r'))
|| (p[0] == 'f' && p[1] == 'o' && p[2] == 'r')) {
return TRUE;
}
return FALSE;
}