diff options
Diffstat (limited to 'src/nvim/ex_eval.c')
-rw-r--r-- | src/nvim/ex_eval.c | 231 |
1 files changed, 111 insertions, 120 deletions
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 09a1350f17..cfc8eb7316 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -254,12 +254,12 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore) } elem = xmalloc(sizeof(struct msglist)); - elem->msg = vim_strsave(mesg); + elem->msg = (char *)vim_strsave(mesg); elem->next = NULL; elem->throw_msg = NULL; *plist = elem; if (plist == msg_list || severe) { - char_u *tmsg; + char *tmsg; // Skip the extra "Vim " prefix for message "E458". tmsg = elem->msg; @@ -387,28 +387,28 @@ int do_intthrow(cstack_T *cstack) } // 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 *get_exception_string(void *value, except_type_T type, char_u *cmdname, int *should_free) { - char_u *ret, *mesg; - char_u *p, *val; + char *ret, *mesg; + char *p, *val; if (type == ET_ERROR) { *should_free = true; mesg = ((struct msglist *)value)->throw_msg; if (cmdname != NULL && *cmdname != NUL) { size_t cmdlen = STRLEN(cmdname); - ret = vim_strnsave((char_u *)"Vim(", 4 + cmdlen + 2 + STRLEN(mesg)); + ret = (char *)vim_strnsave((char_u *)"Vim(", 4 + cmdlen + 2 + STRLEN(mesg)); STRCPY(&ret[4], cmdname); STRCPY(&ret[4 + cmdlen], "):"); val = ret + 4 + cmdlen + 2; } else { - ret = vim_strnsave((char_u *)"Vim:", 4 + STRLEN(mesg)); + ret = (char *)vim_strnsave((char_u *)"Vim:", 4 + STRLEN(mesg)); val = ret + 4; } - /* msg_add_fname may have been used to prefix the message with a file - * name in quotes. In the exception value, put the file name in - * parentheses and move it to the end. */ + // msg_add_fname may have been used to prefix the message with a file + // name in quotes. In the exception value, put the file name in + // parentheses and move it to the end. for (p = mesg;; p++) { if (*p == NUL || (*p == 'E' @@ -438,7 +438,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname, i } } else { *should_free = FALSE; - ret = (char_u *)value; + ret = value; } return ret; @@ -463,7 +463,7 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname) if (STRNCMP((char_u *)value, "Vim", 3) == 0 && (((char_u *)value)[3] == NUL || ((char_u *)value)[3] == ':' || ((char_u *)value)[3] == '(')) { - EMSG(_("E608: Cannot :throw exceptions with 'Vim' prefix")); + emsg(_("E608: Cannot :throw exceptions with 'Vim' prefix")); goto fail; } } @@ -518,7 +518,7 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname) nomem: xfree(excp); suppress_errthrow = true; - EMSG(_(e_outofmem)); + emsg(_(e_outofmem)); fail: current_exception = NULL; return FAIL; @@ -835,7 +835,7 @@ void ex_if(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) { - eap->errmsg = (char_u *)N_("E579: :if nesting too deep"); + eap->errmsg = N_("E579: :if nesting too deep"); } else { ++cstack->cs_idx; cstack->cs_flags[cstack->cs_idx] = 0; @@ -865,7 +865,7 @@ void ex_endif(exarg_T *eap) if (eap->cstack->cs_idx < 0 || (eap->cstack->cs_flags[eap->cstack->cs_idx] & (CSF_WHILE | CSF_FOR | CSF_TRY))) { - eap->errmsg = (char_u *)N_("E580: :endif without :if"); + eap->errmsg = N_("E580: :endif without :if"); } else { // When debugging or a breakpoint was encountered, display the debug // prompt (if not already done). This shows the user that an ":endif" @@ -898,17 +898,17 @@ void ex_else(exarg_T *eap) || (cstack->cs_flags[cstack->cs_idx] & (CSF_WHILE | CSF_FOR | CSF_TRY))) { if (eap->cmdidx == CMD_else) { - eap->errmsg = (char_u *)N_("E581: :else without :if"); + eap->errmsg = N_("E581: :else without :if"); return; } - eap->errmsg = (char_u *)N_("E582: :elseif without :if"); + eap->errmsg = N_("E582: :elseif without :if"); skip = TRUE; } else if (cstack->cs_flags[cstack->cs_idx] & CSF_ELSE) { if (eap->cmdidx == CMD_else) { - eap->errmsg = (char_u *)N_("E583: multiple :else"); + eap->errmsg = N_("E583: multiple :else"); return; } - eap->errmsg = (char_u *)N_("E584: :elseif after :else"); + eap->errmsg = N_("E584: :elseif after :else"); skip = TRUE; } @@ -922,16 +922,14 @@ void ex_else(exarg_T *eap) cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE; } - /* - * When debugging or a breakpoint was encountered, display the debug prompt - * (if not already done). This shows the user that an ":else" or ":elseif" - * is executed when the ":if" or previous ":elseif" was not TRUE. Handle - * a ">quit" debug command as if an interrupt had occurred before the - * ":else" or ":elseif". That is, set "skip" and throw an interrupt - * exception if appropriate. Doing this here prevents that an exception - * for a parsing errors is discarded when throwing the interrupt exception - * later on. - */ + // When debugging or a breakpoint was encountered, display the debug prompt + // (if not already done). This shows the user that an ":else" or ":elseif" + // is executed when the ":if" or previous ":elseif" was not TRUE. Handle + // a ">quit" debug command as if an interrupt had occurred before the + // ":else" or ":elseif". That is, set "skip" and throw an interrupt + // exception if appropriate. Doing this here prevents that an exception + // for a parsing errors is discarded when throwing the interrupt exception + // later on. if (!skip && dbg_check_skipped(eap) && got_int) { (void)do_intthrow(cstack); skip = TRUE; @@ -972,7 +970,7 @@ void ex_while(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) { - eap->errmsg = (char_u *)N_("E585: :while/:for nesting too deep"); + eap->errmsg = N_("E585: :while/:for nesting too deep"); } else { /* * The loop flag is set when we have jumped back from the matching @@ -1053,13 +1051,13 @@ void ex_continue(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = (char_u *)N_("E586: :continue without :while or :for"); + eap->errmsg = N_("E586: :continue without :while or :for"); } 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" - * itself (if reached). */ - idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); + // 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" + // itself (if reached). + idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, false); assert(idx >= 0); if (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR)) { rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); @@ -1070,8 +1068,8 @@ void ex_continue(exarg_T *eap) */ 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". */ + // If a try conditional not in its finally clause is reached first, + // make the ":continue" pending for execution at the ":endtry". cstack->cs_pending[idx] = CSTP_CONTINUE; report_make_pending(CSTP_CONTINUE, NULL); } @@ -1087,12 +1085,12 @@ void ex_break(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = (char_u *)N_("E587: :break without :while or :for"); + eap->errmsg = N_("E587: :break without :while or :for"); } else { // Deactivate conditionals until the matching ":while" or a try // conditional not in its finally clause (which is then to be // executed next) is found. In the latter case, make the ":break" - // pending for execution at the ":endtry". */ + // pending for execution at the ":endtry". idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, true); if (idx >= 0 && !(cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) { cstack->cs_pending[idx] = CSTP_BREAK; @@ -1108,7 +1106,7 @@ void ex_endwhile(exarg_T *eap) { cstack_T *const cstack = eap->cstack; int idx; - char_u *err; + char *err; int csf; int fl; @@ -1128,9 +1126,9 @@ void ex_endwhile(exarg_T *eap) // 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) { - eap->errmsg = (char_u *)_("E732: Using :endfor with :while"); + eap->errmsg = _("E732: Using :endfor with :while"); } else if (fl & CSF_FOR) { - eap->errmsg = (char_u *)_("E733: Using :endwhile with :for"); + eap->errmsg = _("E733: Using :endwhile with :for"); } } if (!(fl & (CSF_WHILE | CSF_FOR))) { @@ -1155,20 +1153,17 @@ void ex_endwhile(exarg_T *eap) // 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); - } - /* - * When debugging or a breakpoint was encountered, display the debug - * prompt (if not already done). This shows the user that an - * ":endwhile"/":endfor" is executed when the ":while" was not TRUE or - * after a ":break". Handle a ">quit" debug command as if an - * interrupt had occurred before the ":endwhile"/":endfor". That is, - * throw an interrupt exception if appropriate. Doing this here - * prevents that an exception for a parsing error is discarded when - * throwing the interrupt exception later on. - */ - else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE - && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE) - && dbg_check_skipped(eap)) { + } else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE + && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE) + && dbg_check_skipped(eap)) { + // When debugging or a breakpoint was encountered, display the debug + // prompt (if not already done). This shows the user that an + // ":endwhile"/":endfor" is executed when the ":while" was not TRUE or + // after a ":break". Handle a ">quit" debug command as if an + // interrupt had occurred before the ":endwhile"/":endfor". That is, + // throw an interrupt exception if appropriate. Doing this here + // prevents that an exception for a parsing error is discarded when + // throwing the interrupt exception later on. (void)do_intthrow(cstack); } @@ -1193,7 +1188,7 @@ void ex_throw(exarg_T *eap) value = eval_to_string_skip(arg, (const char **)&eap->nextcmd, (bool)eap->skip); } else { - EMSG(_(e_argreq)); + emsg(_(e_argreq)); value = NULL; } @@ -1278,7 +1273,7 @@ void ex_try(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_idx == CSTACK_LEN - 1) { - eap->errmsg = (char_u *)N_("E601: :try nesting too deep"); + eap->errmsg = N_("E601: :try nesting too deep"); } else { ++cstack->cs_idx; ++cstack->cs_trylevel; @@ -1339,7 +1334,7 @@ void ex_catch(exarg_T *eap) char_u *pat; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = (char_u *)N_("E603: :catch without :try"); + eap->errmsg = N_("E603: :catch without :try"); give_up = TRUE; } else { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { @@ -1354,9 +1349,9 @@ void ex_catch(exarg_T *eap) } } 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 for a ":catch" after ":finally" and ignore it. + // Just parse. + eap->errmsg = N_("E604: :catch after :finally"); give_up = TRUE; } else { rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, @@ -1391,20 +1386,20 @@ void ex_catch(exarg_T *eap) if (!skip && (cstack->cs_flags[idx] & CSF_THROWN) && !(cstack->cs_flags[idx] & CSF_CAUGHT)) { if (end != NULL && *end != NUL && !ends_excmd(*skipwhite(end + 1))) { - EMSG(_(e_trailing)); + emsg(_(e_trailing)); return; } - /* When debugging or a breakpoint was encountered, display the - * debug prompt (if not already done) before checking for a match. - * This is a helpful hint for the user when the regular expression - * matching fails. Handle a ">quit" debug command as if an - * interrupt had occurred before the ":catch". That is, discard - * the original exception, replace it by an interrupt exception, - * and don't catch it in this try block. */ + // When debugging or a breakpoint was encountered, display the + // debug prompt (if not already done) before checking for a match. + // This is a helpful hint for the user when the regular expression + // matching fails. Handle a ">quit" debug command as if an + // interrupt had occurred before the ":catch". That is, discard + // the original exception, replace it by an interrupt exception, + // and don't catch it in this try block. if (!dbg_check_skipped(eap) || !do_intthrow(cstack)) { - /* Terminate the pattern and avoid the 'l' flag in 'cpoptions' - * while compiling it. */ + // Terminate the pattern and avoid the 'l' flag in 'cpoptions' + // while compiling it. if (end != NULL) { save_char = *end; *end = NUL; @@ -1422,7 +1417,7 @@ void ex_catch(exarg_T *eap) } p_cpo = save_cpo; if (regmatch.regprog == NULL) { - EMSG2(_(e_invarg2), pat); + semsg(_(e_invarg2), pat); } else { // // Save the value of got_int and reset it. We don't want @@ -1431,7 +1426,7 @@ void ex_catch(exarg_T *eap) // prev_got_int = got_int; got_int = FALSE; - caught = vim_regexec_nl(®match, current_exception->value, + caught = vim_regexec_nl(®match, (char_u *)current_exception->value, (colnr_T)0); got_int |= prev_got_int; vim_regfree(regmatch.regprog); @@ -1440,16 +1435,16 @@ void ex_catch(exarg_T *eap) } if (caught) { - /* Make this ":catch" clause active and reset did_emsg and got_int. - * Put the exception on the caught stack. */ + // Make this ":catch" clause active and reset did_emsg and got_int. + // Put the exception on the caught stack. cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT; did_emsg = got_int = false; catch_exception((except_T *)cstack->cs_exception[idx]); - /* It's mandatory that the current exception is stored in the cstack - * so that it can be discarded at the next ":catch", ":finally", or - * ":endtry" or when the catch clause is left by a ":continue", - * ":break", ":return", ":finish", error, interrupt, or another - * exception. */ + // It's mandatory that the current exception is stored in the cstack + // so that it can be discarded at the next ":catch", ":finally", or + // ":endtry" or when the catch clause is left by a ":continue", + // ":break", ":return", ":finish", error, interrupt, or another + // exception. if (cstack->cs_exception[cstack->cs_idx] != current_exception) { internal_error("ex_catch()"); } @@ -1488,7 +1483,7 @@ void ex_finally(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = (char_u *)N_("E606: :finally without :try"); + eap->errmsg = N_("E606: :finally without :try"); } else { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { eap->errmsg = get_end_emsg(cstack); @@ -1507,7 +1502,7 @@ void ex_finally(exarg_T *eap) if (cstack->cs_flags[idx] & CSF_FINALLY) { // Give up for a multiple ":finally" and ignore it. - eap->errmsg = (char_u *)N_("E607: multiple :finally"); + eap->errmsg = N_("E607: multiple :finally"); return; } rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, @@ -1576,13 +1571,13 @@ void ex_finally(exarg_T *eap) assert(pending >= CHAR_MIN && pending <= CHAR_MAX); cstack->cs_pending[cstack->cs_idx] = (char)pending; - /* It's mandatory that the current exception is stored in the - * cstack so that it can be rethrown at the ":endtry" or be - * discarded if the finally clause is left by a ":continue", - * ":break", ":return", ":finish", error, interrupt, or another - * exception. When emsg() is called for a missing ":endif" or - * a missing ":endwhile"/":endfor" detected here, the - * exception will be discarded. */ + // It's mandatory that the current exception is stored in the + // cstack so that it can be rethrown at the ":endtry" or be + // discarded if the finally clause is left by a ":continue", + // ":break", ":return", ":finish", error, interrupt, or another + // exception. When emsg() is called for a missing ":endif" or + // a missing ":endwhile"/":endfor" detected here, the + // exception will be discarded. if (current_exception && cstack->cs_exception[cstack->cs_idx] != current_exception) { internal_error("ex_finally()"); @@ -1614,7 +1609,7 @@ void ex_endtry(exarg_T *eap) cstack_T *const cstack = eap->cstack; if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) { - eap->errmsg = (char_u *)N_("E602: :endtry without :try"); + eap->errmsg = N_("E602: :endtry without :try"); } else { // Don't do something after an error, interrupt or throw in the try // block, catch clause, or finally clause preceding this ":endtry" or @@ -1633,8 +1628,9 @@ void ex_endtry(exarg_T *eap) eap->errmsg = get_end_emsg(cstack); // Find the matching ":try" and report what's missing. idx = cstack->cs_idx; - do + do{ --idx; + } while (idx > 0 && !(cstack->cs_flags[idx] & CSF_TRY)); rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, &cstack->cs_looplevel); @@ -1666,21 +1662,20 @@ void ex_endtry(exarg_T *eap) } } - /* If there was no finally clause, show the user when debugging or - * a breakpoint was encountered that the end of the try conditional has - * been reached: display the debug prompt (if not already done). Do - * this on normal control flow or when an exception was thrown, but not - * on an interrupt or error not converted to an exception or when - * a ":break", ":continue", ":return", or ":finish" is pending. These - * actions are carried out immediately. - */ + // If there was no finally clause, show the user when debugging or + // a breakpoint was encountered that the end of the try conditional has + // been reached: display the debug prompt (if not already done). Do + // this on normal control flow or when an exception was thrown, but not + // on an interrupt or error not converted to an exception or when + // a ":break", ":continue", ":return", or ":finish" is pending. These + // actions are carried out immediately. if ((rethrow || (!skip && !(cstack->cs_flags[idx] & CSF_FINALLY) && !cstack->cs_pending[idx])) && dbg_check_skipped(eap)) { - /* Handle a ">quit" debug command as if an interrupt had occurred - * before the ":endtry". That is, throw an interrupt exception and - * set "skip" and "rethrow". */ + // Handle a ">quit" debug command as if an interrupt had occurred + // before the ":endtry". That is, throw an interrupt exception and + // set "skip" and "rethrow". if (got_int) { skip = TRUE; (void)do_intthrow(cstack); @@ -1815,13 +1810,12 @@ void enter_cleanup(cleanup_T *csp) | (current_exception ? CSTP_THROW : 0) | (need_rethrow ? CSTP_THROW : 0); - /* If we are currently throwing an exception, save it as well. On an error - * not yet converted to an exception, update "force_abort" and reset - * "cause_abort" (as do_errthrow() would do). This is needed for the - * do_cmdline() call that is going to be made for autocommand execution. We - * need not save *msg_list because there is an extra instance for every call - * of do_cmdline(), anyway. - */ + // If we are currently throwing an exception, save it as well. On an error + // not yet converted to an exception, update "force_abort" and reset + // "cause_abort" (as do_errthrow() would do). This is needed for the + // do_cmdline() call that is going to be made for autocommand execution. We + // need not save *msg_list because there is an extra instance for every call + // of do_cmdline(), anyway. if (current_exception || need_rethrow) { csp->exception = current_exception; current_exception = NULL; @@ -1897,13 +1891,10 @@ void leave_cleanup(cleanup_T *csp) */ 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 - * "force_abort" (as done by cause_errthrow()). - */ - else if (pending & CSTP_ERROR) { + } else if (pending & CSTP_ERROR) { + // If an error was about to be converted to an exception when + // enter_cleanup() was called, let "cause_abort" take the part of + // "force_abort" (as done by cause_errthrow()). cause_abort = force_abort; force_abort = FALSE; } @@ -2052,7 +2043,7 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive) /* * Return an appropriate error message for a missing endwhile/endfor/endif. */ -static char_u *get_end_emsg(cstack_T *cstack) +static char *get_end_emsg(cstack_T *cstack) { if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) { return e_endwhile; @@ -2089,7 +2080,7 @@ void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, int *cond_lev */ void ex_endfunction(exarg_T *eap) { - EMSG(_("E193: :endfunction not inside a function")); + emsg(_("E193: :endfunction not inside a function")); } /* |