neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

ex_eval_defs.h (5304B)


      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.
     11 typedef struct eslist_elem eslist_T;
     12 struct eslist_elem {
     13  int saved_emsg_silent;  ///< saved value of "emsg_silent"
     14  eslist_T *next;         ///< next element on the list
     15 };
     16 
     17 enum {
     18  /// For conditional commands a stack is kept of nested conditionals.
     19  /// When cs_idx < 0, there is no conditional command.
     20  CSTACK_LEN = 50,
     21 };
     22 
     23 typedef struct {
     24  int cs_flags[CSTACK_LEN];       ///< CSF_ flags
     25  char cs_pending[CSTACK_LEN];    ///< CSTP_: what's pending in ":finally"
     26  union {
     27    void *csp_rv[CSTACK_LEN];     ///< return typeval for pending return
     28    void *csp_ex[CSTACK_LEN];     ///< exception for pending throw
     29  } cs_pend;
     30  void *cs_forinfo[CSTACK_LEN];   ///< info used by ":for"
     31  int cs_line[CSTACK_LEN];        ///< line nr of ":while"/":for" line
     32  int cs_idx;                     ///< current entry, or -1 if none
     33  int cs_looplevel;               ///< nr of nested ":while"s and ":for"s
     34  int cs_trylevel;                ///< nr of nested ":try"s
     35  eslist_T *cs_emsg_silent_list;  ///< saved values of "emsg_silent"
     36  int 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.
     43 enum {
     44  CSF_TRUE     = 0x0001,  ///< condition was TRUE
     45  CSF_ACTIVE   = 0x0002,  ///< current state is active
     46  CSF_ELSE     = 0x0004,  ///< ":else" has been passed
     47  CSF_WHILE    = 0x0008,  ///< is a ":while"
     48  CSF_FOR      = 0x0010,  ///< is a ":for"
     49 
     50  CSF_TRY      = 0x0100,  ///< is a ":try"
     51  CSF_FINALLY  = 0x0200,  ///< ":finally" has been passed
     52  CSF_THROWN   = 0x0800,  ///< exception thrown to this try conditional
     53  CSF_CAUGHT   = 0x1000,  ///< exception caught by this try conditional
     54  CSF_FINISHED = 0x2000,  ///< CSF_CAUGHT was handled by finish_exception()
     55  CSF_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:
     62 enum {
     63  CSTP_NONE      = 0,   ///< nothing pending in ":finally" clause
     64  CSTP_ERROR     = 1,   ///< an error is pending
     65  CSTP_INTERRUPT = 2,   ///< an interrupt is pending
     66  CSTP_THROW     = 4,   ///< a throw is pending
     67  CSTP_BREAK     = 8,   ///< ":break" is pending
     68  CSTP_CONTINUE  = 16,  ///< ":continue" is pending
     69  CSTP_RETURN    = 24,  ///< ":return" is pending
     70  CSTP_FINISH    = 32,  ///< ":finish" is pending
     71 };
     72 
     73 /// Flags for the cs_lflags item in cstack_T.
     74 enum {
     75  CSL_HAD_LOOP = 1,     ///< just found ":while" or ":for"
     76  CSL_HAD_ENDLOOP = 2,  ///< just found ":endwhile" or ":endfor"
     77  CSL_HAD_CONT = 4,     ///< just found ":continue"
     78  CSL_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().
     85 typedef struct msglist msglist_T;
     86 struct msglist {
     87  msglist_T *next;  ///< next of several messages in a row
     88  char *msg;        ///< original message, allocated
     89  char *throw_msg;  ///< msg to throw: usually original one
     90  char *sfile;      ///< value from estack_sfile(), allocated
     91  linenr_T slnum;   ///< line number for "sfile"
     92  bool multiline;   ///< whether this is a multiline message
     93 };
     94 
     95 /// The exception types.
     96 typedef enum {
     97  ET_USER,       ///< exception caused by ":throw" command
     98  ET_ERROR,      ///< error exception
     99  ET_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).
    104 typedef struct vim_exception except_T;
    105 struct vim_exception {
    106  except_type_T type;   ///< exception type
    107  char *value;          ///< exception value
    108  msglist_T *messages;  ///< message(s) causing error exception
    109  char *throw_name;     ///< name of the throw point
    110  linenr_T throw_lnum;  ///< line number of the throw point
    111  list_T *stacktrace;   ///< stacktrace
    112  except_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.
    118 typedef struct cleanup_stuff cleanup_T;
    119 struct cleanup_stuff {
    120  int pending;          ///< error/interrupt/exception state
    121  except_T *exception;  ///< exception value
    122 };
    123 
    124 /// Exception state that is saved and restored when calling timer callback
    125 /// functions and deferred functions.
    126 typedef struct exception_state_S exception_state_T;
    127 struct exception_state_S {
    128  except_T *estate_current_exception;
    129  bool estate_did_throw;
    130  bool estate_need_rethrow;
    131  int estate_trylevel;
    132  int estate_did_emsg;
    133 };