diff --git a/Makefile b/Makefile index 5667c9d953..079416eb43 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,6 @@ iwyu: build/.ran-cmake |src/nvim/buffer_defs.h\ |src/nvim/channel.h\ |src/nvim/charset.h\ - |src/nvim/cmdexpand.h\ |src/nvim/decoration.h\ |src/nvim/drawline.h\ |src/nvim/eval.h\ @@ -172,7 +171,6 @@ iwyu: build/.ran-cmake |src/nvim/event/wstream.h\ |src/nvim/extmark.h\ |src/nvim/garray.h\ - |src/nvim/getchar.h\ |src/nvim/globals.h\ |src/nvim/grid.h\ |src/nvim/highlight.h\ @@ -187,7 +185,6 @@ iwyu: build/.ran-cmake |src/nvim/msgpack_rpc/helpers.h\ |src/nvim/msgpack_rpc/unpacker.h\ |src/nvim/option.h\ - |src/nvim/os/fileio.h\ |src/nvim/os/input.h\ |src/nvim/os/pty_conpty_win.h\ |src/nvim/os/pty_process_unix.h\ diff --git a/src/clint.py b/src/clint.py index ddd3ff7d44..2a7eb16c9a 100755 --- a/src/clint.py +++ b/src/clint.py @@ -909,7 +909,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/buffer_defs.h", "src/nvim/channel.h", "src/nvim/charset.h", - "src/nvim/cmdexpand.h", "src/nvim/decoration.h", "src/nvim/drawline.h", "src/nvim/eval.h", @@ -930,7 +929,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/event/wstream.h", "src/nvim/extmark.h", "src/nvim/garray.h", - "src/nvim/getchar.h", "src/nvim/globals.h", "src/nvim/grid.h", "src/nvim/highlight.h", @@ -945,7 +943,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/msgpack_rpc/helpers.h", "src/nvim/msgpack_rpc/unpacker.h", "src/nvim/option.h", - "src/nvim/os/fileio.h", "src/nvim/os/input.h", "src/nvim/os/pty_conpty_win.h", "src/nvim/os/pty_process_unix.h", diff --git a/src/nvim/cmdexpand.h b/src/nvim/cmdexpand.h index b0772d26a3..a45b334cfb 100644 --- a/src/nvim/cmdexpand.h +++ b/src/nvim/cmdexpand.h @@ -2,8 +2,9 @@ #include "nvim/cmdexpand_defs.h" // IWYU pragma: export #include "nvim/eval/typval_defs.h" // IWYU pragma: keep -#include "nvim/ex_getln.h" +#include "nvim/ex_getln_defs.h" // IWYU pragma: keep #include "nvim/garray_defs.h" // IWYU pragma: keep +#include "nvim/regexp_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep // Values for nextwild() and ExpandOne(). See ExpandOne() for meaning. diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 7306645cc3..6d225b2713 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -13,8 +13,8 @@ #include "nvim/hashtab_defs.h" #include "nvim/macros_defs.h" #include "nvim/mbyte_defs.h" // IWYU pragma: keep -#include "nvim/os/fileio.h" -#include "nvim/os/stdpaths_defs.h" +#include "nvim/os/fileio_defs.h" // IWYU pragma: keep +#include "nvim/os/stdpaths_defs.h" // IWYU pragma: keep #include "nvim/vim_defs.h" // IWYU pragma: keep #define COPYID_INC 2 diff --git a/src/nvim/event/stream.h b/src/nvim/event/stream.h index d02707dc45..ab694e2247 100644 --- a/src/nvim/event/stream.h +++ b/src/nvim/event/stream.h @@ -6,7 +6,7 @@ #include "nvim/event/loop.h" #include "nvim/event/multiqueue.h" -#include "nvim/rbuffer.h" +#include "nvim/rbuffer_defs.h" struct stream; diff --git a/src/nvim/ex_getln.h b/src/nvim/ex_getln.h index 93bdd2299f..af08970f0b 100644 --- a/src/nvim/ex_getln.h +++ b/src/nvim/ex_getln.h @@ -1,76 +1,13 @@ #pragma once -#include +#include // IWYU pragma: keep -#include "klib/kvec.h" -#include "nvim/cmdexpand_defs.h" -#include "nvim/eval/typval_defs.h" +#include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/ex_cmds_defs.h" // IWYU pragma: keep +#include "nvim/ex_getln_defs.h" // IWYU pragma: export #include "nvim/option_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep -/// Command-line colors: one chunk -/// -/// Defines a region which has the same highlighting. -typedef struct { - int start; ///< Colored chunk start. - int end; ///< Colored chunk end (exclusive, > start). - int attr; ///< Highlight attr. -} CmdlineColorChunk; - -/// Command-line colors -/// -/// Holds data about all colors. -typedef kvec_t(CmdlineColorChunk) CmdlineColors; - -/// Command-line coloring -/// -/// Holds both what are the colors and what have been colored. Latter is used to -/// suppress unnecessary calls to coloring callbacks. -typedef struct { - unsigned prompt_id; ///< ID of the prompt which was colored last. - char *cmdbuff; ///< What exactly was colored last time or NULL. - CmdlineColors colors; ///< Last colors. -} ColoredCmdline; - -/// Keeps track how much state must be sent to external ui. -typedef enum { - kCmdRedrawNone, - kCmdRedrawPos, - kCmdRedrawAll, -} CmdRedraw; - -/// Variables shared between getcmdline(), redrawcmdline() and others. -/// These need to be saved when using CTRL-R |, that's why they are in a -/// structure. -typedef struct cmdline_info CmdlineInfo; -struct cmdline_info { - char *cmdbuff; ///< pointer to command line buffer - int cmdbufflen; ///< length of cmdbuff - int cmdlen; ///< number of chars in command line - int cmdpos; ///< current cursor position - int cmdspos; ///< cursor column on screen - int cmdfirstc; ///< ':', '/', '?', '=', '>' or NUL - int cmdindent; ///< number of spaces before cmdline - char *cmdprompt; ///< message in front of cmdline - int cmdattr; ///< attributes for prompt - int overstrike; ///< Typing mode on the command line. Shared by - ///< getcmdline() and put_on_cmdline(). - expand_T *xpc; ///< struct being used for expansion, xp_pattern - ///< may point into cmdbuff - int xp_context; ///< type of expansion - char *xp_arg; ///< user-defined expansion arg - int input_fn; ///< when true Invoked for input() function - unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. - Callback highlight_callback; ///< Callback used for coloring user input. - ColoredCmdline last_colors; ///< Last cmdline colors - int level; ///< current cmdline level - CmdlineInfo *prev_ccline; ///< pointer to saved cmdline state - char special_char; ///< last putcmdline char (used for redraws) - bool special_shift; ///< shift of last putcmdline char - CmdRedraw redraw_state; ///< needed redraw for external cmdline -}; - /// flags used by vim_strsave_fnameescape() enum { VSE_NONE = 0, diff --git a/src/nvim/ex_getln_defs.h b/src/nvim/ex_getln_defs.h new file mode 100644 index 0000000000..daba6cabb8 --- /dev/null +++ b/src/nvim/ex_getln_defs.h @@ -0,0 +1,68 @@ +#pragma once + +#include + +#include "klib/kvec.h" +#include "nvim/cmdexpand_defs.h" + +/// Command-line colors: one chunk +/// +/// Defines a region which has the same highlighting. +typedef struct { + int start; ///< Colored chunk start. + int end; ///< Colored chunk end (exclusive, > start). + int attr; ///< Highlight attr. +} CmdlineColorChunk; + +/// Command-line colors +/// +/// Holds data about all colors. +typedef kvec_t(CmdlineColorChunk) CmdlineColors; + +/// Command-line coloring +/// +/// Holds both what are the colors and what have been colored. Latter is used to +/// suppress unnecessary calls to coloring callbacks. +typedef struct { + unsigned prompt_id; ///< ID of the prompt which was colored last. + char *cmdbuff; ///< What exactly was colored last time or NULL. + CmdlineColors colors; ///< Last colors. +} ColoredCmdline; + +/// Keeps track how much state must be sent to external ui. +typedef enum { + kCmdRedrawNone, + kCmdRedrawPos, + kCmdRedrawAll, +} CmdRedraw; + +/// Variables shared between getcmdline(), redrawcmdline() and others. +/// These need to be saved when using CTRL-R |, that's why they are in a +/// structure. +typedef struct cmdline_info CmdlineInfo; +struct cmdline_info { + char *cmdbuff; ///< pointer to command line buffer + int cmdbufflen; ///< length of cmdbuff + int cmdlen; ///< number of chars in command line + int cmdpos; ///< current cursor position + int cmdspos; ///< cursor column on screen + int cmdfirstc; ///< ':', '/', '?', '=', '>' or NUL + int cmdindent; ///< number of spaces before cmdline + char *cmdprompt; ///< message in front of cmdline + int cmdattr; ///< attributes for prompt + int overstrike; ///< Typing mode on the command line. Shared by + ///< getcmdline() and put_on_cmdline(). + expand_T *xpc; ///< struct being used for expansion, xp_pattern + ///< may point into cmdbuff + int xp_context; ///< type of expansion + char *xp_arg; ///< user-defined expansion arg + int input_fn; ///< when true Invoked for input() function + unsigned prompt_id; ///< Prompt number, used to disable coloring on errors. + Callback highlight_callback; ///< Callback used for coloring user input. + ColoredCmdline last_colors; ///< Last cmdline colors + int level; ///< current cmdline level + CmdlineInfo *prev_ccline; ///< pointer to saved cmdline state + char special_char; ///< last putcmdline char (used for redraws) + bool special_shift; ///< shift of last putcmdline char + CmdRedraw redraw_state; ///< needed redraw for external cmdline +}; diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h index e1bc64bfee..6e41bef298 100644 --- a/src/nvim/getchar.h +++ b/src/nvim/getchar.h @@ -1,11 +1,11 @@ #pragma once -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/getchar_defs.h" // IWYU pragma: export -#include "nvim/os/fileio.h" +#include "nvim/os/fileio_defs.h" #include "nvim/types_defs.h" // IWYU pragma: keep /// Argument for flush_buffers(). diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h index 72e7984c8a..55f213f377 100644 --- a/src/nvim/os/fileio.h +++ b/src/nvim/os/fileio.h @@ -1,20 +1,8 @@ #pragma once -#include -#include +#include // IWYU pragma: keep -#include "nvim/func_attr.h" -#include "nvim/rbuffer.h" - -/// Structure used to read from/write to file -typedef struct { - int fd; ///< File descriptor. - int _error; ///< Error code for use with RBuffer callbacks or zero. - RBuffer *rv; ///< Read or write buffer. - bool wr; ///< True if file is in write mode. - bool eof; ///< True if end of file was encountered. - bool non_blocking; ///< True if EAGAIN should not restart syscalls. -} FileDescriptor; +#include "nvim/os/fileio_defs.h" // IWYU pragma: export /// file_open() flags typedef enum { @@ -37,33 +25,6 @@ typedef enum { kFileMkDir = 256, } FileOpenFlags; -static inline bool file_eof(const FileDescriptor *fp) - REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; - -/// Check whether end of file was encountered -/// -/// @param[in] fp File to check. -/// -/// @return true if it was, false if it was not or read operation was never -/// performed. -static inline bool file_eof(const FileDescriptor *const fp) -{ - return fp->eof && rbuffer_size(fp->rv) == 0; -} - -static inline int file_fd(const FileDescriptor *fp) - REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; - -/// Return the file descriptor associated with the FileDescriptor structure -/// -/// @param[in] fp File to check. -/// -/// @return File descriptor. -static inline int file_fd(const FileDescriptor *const fp) -{ - return fp->fd; -} - enum { /// Read or write buffer size /// diff --git a/src/nvim/os/fileio_defs.h b/src/nvim/os/fileio_defs.h new file mode 100644 index 0000000000..3dc8c7b22a --- /dev/null +++ b/src/nvim/os/fileio_defs.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include "nvim/func_attr.h" +#include "nvim/rbuffer_defs.h" + +/// Structure used to read from/write to file +typedef struct { + int fd; ///< File descriptor. + int _error; ///< Error code for use with RBuffer callbacks or zero. + RBuffer *rv; ///< Read or write buffer. + bool wr; ///< True if file is in write mode. + bool eof; ///< True if end of file was encountered. + bool non_blocking; ///< True if EAGAIN should not restart syscalls. +} FileDescriptor; + +static inline bool file_eof(const FileDescriptor *fp) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; + +/// Check whether end of file was encountered +/// +/// @param[in] fp File to check. +/// +/// @return true if it was, false if it was not or read operation was never +/// performed. +static inline bool file_eof(const FileDescriptor *const fp) +{ + return fp->eof && rbuffer_size(fp->rv) == 0; +} + +static inline int file_fd(const FileDescriptor *fp) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; + +/// Return the file descriptor associated with the FileDescriptor structure +/// +/// @param[in] fp File to check. +/// +/// @return File descriptor. +static inline int file_fd(const FileDescriptor *const fp) +{ + return fp->fd; +} diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index aff06ee31b..d2fae5388f 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -29,27 +29,12 @@ RBuffer *rbuffer_new(size_t capacity) return rv; } -void rbuffer_free(RBuffer *buf) +void rbuffer_free(RBuffer *buf) FUNC_ATTR_NONNULL_ALL { xfree(buf->temp); xfree(buf); } -size_t rbuffer_size(RBuffer *buf) FUNC_ATTR_NONNULL_ALL -{ - return buf->size; -} - -size_t rbuffer_capacity(RBuffer *buf) FUNC_ATTR_NONNULL_ALL -{ - return (size_t)(buf->end_ptr - buf->start_ptr); -} - -size_t rbuffer_space(RBuffer *buf) FUNC_ATTR_NONNULL_ALL -{ - return rbuffer_capacity(buf) - buf->size; -} - /// Return a pointer to a raw buffer containing the first empty slot available /// for writing. The second argument is a pointer to the maximum number of /// bytes that could be written. diff --git a/src/nvim/rbuffer.h b/src/nvim/rbuffer.h index 55e9849d3d..78483b2a50 100644 --- a/src/nvim/rbuffer.h +++ b/src/nvim/rbuffer.h @@ -16,6 +16,8 @@ #include #include +#include "nvim/rbuffer_defs.h" // IWYU pragma: export + // Macros that simplify working with the read/write pointers directly by hiding // ring buffer wrap logic. Some examples: // @@ -64,22 +66,6 @@ i-- > 0 ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \ ) -typedef struct rbuffer RBuffer; -/// Type of function invoked during certain events: -/// - When the RBuffer switches to the full state -/// - When the RBuffer switches to the non-full state -typedef void (*rbuffer_callback)(RBuffer *buf, void *data); - -struct rbuffer { - rbuffer_callback full_cb, nonfull_cb; - void *data; - size_t size; - // helper memory used to by rbuffer_reset if required - char *temp; - char *end_ptr, *read_ptr, *write_ptr; - char start_ptr[]; -}; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "rbuffer.h.generated.h" #endif diff --git a/src/nvim/rbuffer_defs.h b/src/nvim/rbuffer_defs.h new file mode 100644 index 0000000000..51dc349846 --- /dev/null +++ b/src/nvim/rbuffer_defs.h @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include "nvim/func_attr.h" + +typedef struct rbuffer RBuffer; +/// Type of function invoked during certain events: +/// - When the RBuffer switches to the full state +/// - When the RBuffer switches to the non-full state +typedef void (*rbuffer_callback)(RBuffer *buf, void *data); + +struct rbuffer { + rbuffer_callback full_cb, nonfull_cb; + void *data; + size_t size; + // helper memory used to by rbuffer_reset if required + char *temp; + char *end_ptr, *read_ptr, *write_ptr; + char start_ptr[]; +}; + +static inline size_t rbuffer_size(RBuffer *buf) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL; + +static inline size_t rbuffer_size(RBuffer *buf) +{ + return buf->size; +} + +static inline size_t rbuffer_capacity(RBuffer *buf) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL; + +static inline size_t rbuffer_capacity(RBuffer *buf) +{ + return (size_t)(buf->end_ptr - buf->start_ptr); +} + +static inline size_t rbuffer_space(RBuffer *buf) + REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL; + +static inline size_t rbuffer_space(RBuffer *buf) +{ + return rbuffer_capacity(buf) - buf->size; +} diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index b9e2d2c9ee..1e14f3fee9 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -13,6 +13,7 @@ #include "nvim/memory.h" #include "nvim/option_vars.h" #include "nvim/os/os.h" +#include "nvim/rbuffer.h" #include "nvim/strings.h" #include "nvim/tui/input.h" #include "nvim/tui/input_defs.h" diff --git a/src/nvim/tui/input.h b/src/nvim/tui/input.h index 27a0291f5b..9d276277de 100644 --- a/src/nvim/tui/input.h +++ b/src/nvim/tui/input.h @@ -7,7 +7,7 @@ #include "nvim/event/loop.h" #include "nvim/event/stream.h" #include "nvim/event/time.h" -#include "nvim/rbuffer.h" +#include "nvim/rbuffer_defs.h" #include "nvim/tui/input_defs.h" // IWYU pragma: export #include "nvim/tui/tui.h" #include "nvim/types_defs.h"