robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e27f7125d6
master
1#pragma once 2 3#include <stdbool.h> 4 5#include "nvim/eval/typval_defs.h" 6#include "nvim/pos_defs.h" 7 8/// A list used for saving values of "emsg_silent". Used by ex_try() to save the 9/// value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT 10/// flag below is set. 11typedef struct eslist_elem eslist_T ; 12struct eslist_elem { 13int saved_emsg_silent ;///< saved value of "emsg_silent" 14eslist_T * next ;///< next element on the list 15}; 16 17enum { 18/// For conditional commands a stack is kept of nested conditionals. 19/// When cs_idx < 0, there is no conditional command. 20CSTACK_LEN = 50 , 21}; 22 23typedef struct { 24int cs_flags [CSTACK_LEN ];///< CSF_ flags 25char cs_pending [CSTACK_LEN ];///< CSTP_: what's pending in ":finally" 26union { 27void * csp_rv [CSTACK_LEN ];///< return typeval for pending return 28void * csp_ex [CSTACK_LEN ];///< exception for pending throw 29 }cs_pend ; 30void * cs_forinfo [CSTACK_LEN ];///< info used by ":for" 31int cs_line [CSTACK_LEN ];///< line nr of ":while"/":for" line 32int cs_idx ;///< current entry, or -1 if none 33int cs_looplevel ;///< nr of nested ":while"s and ":for"s 34int cs_trylevel ;///< nr of nested ":try"s 35eslist_T * cs_emsg_silent_list ;///< saved values of "emsg_silent" 36int cs_lflags ;///< loop flags: CSL_ flags 37}cstack_T ; 38#define cs_rettv cs_pend.csp_rv 39#define cs_exception cs_pend.csp_ex 40 41/// There is no CSF_IF, the lack of CSF_WHILE, CSF_FOR and CSF_TRY means ":if" 42/// was used. 43enum { 44CSF_TRUE = 0x0001 ,///< condition was TRUE 45CSF_ACTIVE = 0x0002 ,///< current state is active 46CSF_ELSE = 0x0004 ,///< ":else" has been passed 47CSF_WHILE = 0x0008 ,///< is a ":while" 48CSF_FOR = 0x0010 ,///< is a ":for" 49 50CSF_TRY = 0x0100 ,///< is a ":try" 51CSF_FINALLY = 0x0200 ,///< ":finally" has been passed 52CSF_THROWN = 0x0800 ,///< exception thrown to this try conditional 53CSF_CAUGHT = 0x1000 ,///< exception caught by this try conditional 54CSF_FINISHED = 0x2000 ,///< CSF_CAUGHT was handled by finish_exception() 55CSF_SILENT = 0x4000 ,///< "emsg_silent" reset by ":try" 56}; 57// Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset 58// (an ":if"), and CSF_SILENT is only used when CSF_TRY is set. 59 60/// What's pending for being reactivated at the ":endtry" of this try 61/// conditional: 62enum { 63CSTP_NONE = 0 ,///< nothing pending in ":finally" clause 64CSTP_ERROR = 1 ,///< an error is pending 65CSTP_INTERRUPT = 2 ,///< an interrupt is pending 66CSTP_THROW = 4 ,///< a throw is pending 67CSTP_BREAK = 8 ,///< ":break" is pending 68CSTP_CONTINUE = 16 ,///< ":continue" is pending 69CSTP_RETURN = 24 ,///< ":return" is pending 70CSTP_FINISH = 32 ,///< ":finish" is pending 71}; 72 73/// Flags for the cs_lflags item in cstack_T. 74enum { 75CSL_HAD_LOOP = 1 ,///< just found ":while" or ":for" 76CSL_HAD_ENDLOOP = 2 ,///< just found ":endwhile" or ":endfor" 77CSL_HAD_CONT = 4 ,///< just found ":continue" 78CSL_HAD_FINA = 8 ,///< just found ":finally" 79}; 80 81/// A list of error messages that can be converted to an exception. "throw_msg" 82/// is only set in the first element of the list. Usually, it points to the 83/// original message stored in that element, but sometimes it points to a later 84/// message in the list. See cause_errthrow(). 85typedef struct msglist msglist_T ; 86struct msglist { 87msglist_T * next ;///< next of several messages in a row 88char * msg ;///< original message, allocated 89char * throw_msg ;///< msg to throw: usually original one 90char * sfile ;///< value from estack_sfile(), allocated 91linenr_T slnum ;///< line number for "sfile" 92bool multiline ;///< whether this is a multiline message 93}; 94 95/// The exception types. 96typedef enum { 97ET_USER ,///< exception caused by ":throw" command 98ET_ERROR ,///< error exception 99ET_INTERRUPT ,///< interrupt exception triggered by Ctrl-C 100}except_type_T ; 101 102/// Structure describing an exception. 103/// (don't use "struct exception", it's used by the math library). 104typedef struct vim_exception except_T ; 105struct vim_exception { 106except_type_T type ;///< exception type 107char * value ;///< exception value 108msglist_T * messages ;///< message(s) causing error exception 109char * throw_name ;///< name of the throw point 110linenr_T throw_lnum ;///< line number of the throw point 111list_T * stacktrace ;///< stacktrace 112except_T * caught ;///< next exception on the caught stack 113}; 114 115/// Structure to save the error/interrupt/exception state between calls to 116/// enter_cleanup() and leave_cleanup(). Must be allocated as an automatic 117/// variable by the (common) caller of these functions. 118typedef struct cleanup_stuff cleanup_T ; 119struct cleanup_stuff { 120int pending ;///< error/interrupt/exception state 121except_T * exception ;///< exception value 122}; 123 124/// Exception state that is saved and restored when calling timer callback 125/// functions and deferred functions. 126typedef struct exception_state_S exception_state_T ; 127struct exception_state_S { 128except_T * estate_current_exception ; 129bool estate_did_throw ; 130bool estate_need_rethrow ; 131int estate_trylevel ; 132int estate_did_emsg ; 133};