refactor(IWYU): move marktree types to marktree_defs.h (#26402)

This commit is contained in:
zeertzjq 2023-12-05 20:05:12 +08:00 committed by GitHub
parent 0b74ad0a64
commit 1457272726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 112 additions and 112 deletions

View File

@ -142,16 +142,13 @@ iwyu: build/.ran-cmake
cmake --preset iwyu
cmake --build build > build/iwyu.log
iwyu-fix-includes --only_re="src/nvim" --ignore_re="(src/nvim/eval/encode.c|src/nvim/auto/|src/nvim/os/lang.c|src/nvim/map.c\
|src/nvim/api/extmark.h\
|src/nvim/api/private/helpers.h\
|src/nvim/api/private/validate.h\
|src/nvim/assert_defs.h\
|src/nvim/autocmd.h\
|src/nvim/buffer.h\
|src/nvim/buffer_defs.h\
|src/nvim/channel.h\
|src/nvim/charset.h\
|src/nvim/decoration.h\
|src/nvim/drawline.h\
|src/nvim/eval.h\
|src/nvim/eval/encode.h\
@ -169,7 +166,6 @@ iwyu: build/.ran-cmake
|src/nvim/event/stream.h\
|src/nvim/event/time.h\
|src/nvim/event/wstream.h\
|src/nvim/extmark.h\
|src/nvim/garray.h\
|src/nvim/globals.h\
|src/nvim/grid.h\
@ -188,7 +184,6 @@ iwyu: build/.ran-cmake
|src/nvim/os/pty_conpty_win.h\
|src/nvim/os/pty_process_unix.h\
|src/nvim/os/pty_process_win.h\
|src/nvim/plines.h\
|src/nvim/tui/input.h\
|src/nvim/ui.h\
|src/nvim/viml/parser/expressions.h\

View File

@ -900,16 +900,13 @@ def CheckIncludes(filename, lines, error):
# These should be synced with the ignored headers in the `iwyu` target in
# the Makefile.
check_includes_ignore = [
"src/nvim/api/extmark.h",
"src/nvim/api/private/helpers.h",
"src/nvim/api/private/validate.h",
"src/nvim/assert_defs.h",
"src/nvim/autocmd.h",
"src/nvim/buffer.h",
"src/nvim/buffer_defs.h",
"src/nvim/channel.h",
"src/nvim/charset.h",
"src/nvim/decoration.h",
"src/nvim/drawline.h",
"src/nvim/eval.h",
"src/nvim/eval/encode.h",
@ -927,7 +924,6 @@ def CheckIncludes(filename, lines, error):
"src/nvim/event/stream.h",
"src/nvim/event/time.h",
"src/nvim/event/wstream.h",
"src/nvim/extmark.h",
"src/nvim/garray.h",
"src/nvim/globals.h",
"src/nvim/grid.h",
@ -946,7 +942,6 @@ def CheckIncludes(filename, lines, error):
"src/nvim/os/pty_conpty_win.h",
"src/nvim/os/pty_process_unix.h",
"src/nvim/os/pty_process_win.h",
"src/nvim/plines.h",
"src/nvim/tui/input.h",
"src/nvim/ui.h",
"src/nvim/viml/parser/expressions.h",

View File

@ -12,6 +12,7 @@
#include "nvim/api/buffer.h"
#include "nvim/api/keysets_defs.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/dispatch.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/validate.h"
#include "nvim/ascii_defs.h"

View File

@ -2,6 +2,10 @@
#include "nvim/api/private/defs.h"
typedef struct {
OptionalKeys is_set__empty_;
} Dict(empty);
typedef struct {
OptionalKeys is_set__context_;
Array types;
@ -337,10 +341,6 @@ typedef struct {
Boolean unload;
} Dict(buf_delete);
typedef struct {
OptionalKeys is_set__empty_;
} Dict(empty);
typedef struct {
OptionalKeys is_set__open_term_;
LuaRef on_input;

View File

@ -1,9 +1,10 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stddef.h> // IWYU pragma: keep
#include <stdint.h> // IWYU pragma: keep
#include "klib/kvec.h"
#include "nvim/api/private/defs.h" // IWYU pragma: keep
#include "nvim/autocmd_defs.h" // IWYU pragma: export
#include "nvim/buffer_defs.h"
@ -12,7 +13,6 @@
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
#include "nvim/macros_defs.h"
#include "nvim/pos_defs.h"
#include "nvim/types_defs.h"
// Set by the apply_autocmds_group function if the given event is equal to
// EVENT_FILETYPE. Used by the readfile function in order to determine if

View File

@ -26,7 +26,7 @@ typedef struct {
#include "nvim/map_defs.h"
#include "nvim/mapping_defs.h"
#include "nvim/mark_defs.h"
#include "nvim/marktree.h"
#include "nvim/marktree_defs.h"
#include "nvim/option_vars.h"
#include "nvim/pos_defs.h"
#include "nvim/statusline_defs.h"

View File

@ -14,6 +14,7 @@
#include "nvim/grid.h"
#include "nvim/highlight.h"
#include "nvim/highlight_group.h"
#include "nvim/marktree.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/option_vars.h"

View File

@ -8,7 +8,7 @@
#include "nvim/buffer_defs.h"
#include "nvim/decoration_defs.h" // IWYU pragma: export
#include "nvim/macros_defs.h"
#include "nvim/marktree.h"
#include "nvim/marktree_defs.h"
#include "nvim/pos_defs.h" // IWYU pragma: keep
#include "nvim/types_defs.h"

View File

@ -1,17 +1,15 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "klib/kvec.h"
#include "nvim/buffer_defs.h"
#include "nvim/decoration.h"
#include "nvim/buffer_defs.h" // IWYU pragma: keep
#include "nvim/decoration_defs.h" // IWYU pragma: keep
#include "nvim/extmark_defs.h" // IWYU pragma: export
#include "nvim/macros_defs.h"
#include "nvim/marktree.h"
#include "nvim/marktree_defs.h" // IWYU pragma: keep
#include "nvim/pos_defs.h"
#include "nvim/types_defs.h"
EXTERN int curbuf_splice_pending INIT( = 0);

View File

@ -50,15 +50,15 @@
#include <sys/types.h>
#include "klib/kvec.h"
#include "nvim/garray.h"
#include "nvim/macros_defs.h"
#include "nvim/map_defs.h"
#include "nvim/marktree.h"
#include "nvim/memory.h"
#include "nvim/pos_defs.h"
// only for debug functions
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/garray_defs.h"
#include "nvim/macros_defs.h"
#include "nvim/garray.h"
#define T MT_BRANCH_FACTOR
#define ILEN (sizeof(MTNode) + (2 * T) * sizeof(void *))
@ -2200,7 +2200,12 @@ String mt_inspect(MarkTree *b, bool keys, bool dot)
return ga_take_string(ga);
}
void mt_inspect_node(MarkTree *b, garray_T *ga, bool keys, MTNode *n, MTPos off)
static inline uint64_t mt_dbg_id(uint64_t id)
{
return (id >> 1) & 0xffffffff;
}
static void mt_inspect_node(MarkTree *b, garray_T *ga, bool keys, MTNode *n, MTPos off)
{
static char buf[1024];
GA_PUT("[");
@ -2240,7 +2245,7 @@ void mt_inspect_node(MarkTree *b, garray_T *ga, bool keys, MTNode *n, MTPos off)
ga_concat(ga, "]");
}
void mt_inspect_dotfile_node(MarkTree *b, garray_T *ga, MTNode *n, MTPos off, char *parent)
static void mt_inspect_dotfile_node(MarkTree *b, garray_T *ga, MTNode *n, MTPos off, char *parent)
{
static char buf[1024];
char namebuf[64];

View File

@ -1,69 +1,15 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stddef.h> // IWYU pragma: keep
#include <stdint.h>
#include "klib/kvec.h"
#include "nvim/decoration_defs.h"
#include "nvim/garray_defs.h" // IWYU pragma: keep
#include "nvim/map_defs.h"
#include "nvim/marktree_defs.h" // IWYU pragma: export
#include "nvim/pos_defs.h" // IWYU pragma: keep
// only for debug functions:
#include "nvim/api/private/defs.h" // IWYU pragma: keep
#define MT_MAX_DEPTH 20
#define MT_BRANCH_FACTOR 10
// note max branch is actually 2*MT_BRANCH_FACTOR
// and strictly this is ceil(log2(2*MT_BRANCH_FACTOR + 1))
// as we need a pseudo-index for "right before this node"
#define MT_LOG2_BRANCH 5
typedef struct {
int32_t row;
int32_t col;
} MTPos;
#define MTPos(r, c) ((MTPos){ .row = (r), .col = (c) })
typedef struct mtnode_s MTNode;
typedef struct {
MTPos pos;
int lvl;
MTNode *x;
int i;
struct {
int oldcol;
int i;
} s[MT_MAX_DEPTH];
size_t intersect_idx;
MTPos intersect_pos;
MTPos intersect_pos_x;
} MarkTreeIter;
#define marktree_itr_valid(itr) ((itr)->x != NULL)
// access raw key: flags in MT_FLAG_EXTERNAL_MASK and decor_data are safe to modify.
#define mt_itr_rawkey(itr) ((itr)->x->key[(itr)->i])
// Internal storage
//
// NB: actual marks have flags > 0, so we can use (row,col,0) pseudo-key for
// "space before (row,col)"
typedef struct {
MTPos pos;
uint32_t ns;
uint32_t id;
uint16_t flags;
DecorInlineData decor_data; // "ext" tag in flags
} MTKey;
typedef struct {
MTKey start;
MTPos end_pos;
bool end_right_gravity;
} MTPair;
#define MT_INVALID_KEY (MTKey) { { -1, -1 }, 0, 0, 0, { .hl = DECOR_HIGHLIGHT_INLINE_INIT } }
#define MT_FLAG_REAL (((uint16_t)1) << 0)
@ -179,31 +125,6 @@ static inline DecorInline mt_decor(MTKey key)
return (DecorInline){ .ext = key.flags & MT_FLAG_DECOR_EXT, .data = key.decor_data };
}
typedef kvec_withinit_t(uint64_t, 4) Intersection;
struct mtnode_s {
int32_t n;
int16_t level;
int16_t p_idx; // index in parent
Intersection intersect;
// TODO(bfredl): we could consider having a only-sometimes-valid
// index into parent for faster "cached" lookup.
MTNode *parent;
MTKey key[2 * MT_BRANCH_FACTOR - 1];
MTNode *ptr[];
};
static inline uint64_t mt_dbg_id(uint64_t id)
{
return (id>>1)&0xffffffff;
}
typedef struct {
MTNode *root;
size_t n_keys, n_nodes;
PMap(uint64_t) id2node[1];
} MarkTree;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "marktree.h.generated.h"
#endif

83
src/nvim/marktree_defs.h Normal file
View File

@ -0,0 +1,83 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "klib/kvec.h"
#include "nvim/decoration_defs.h"
#include "nvim/map_defs.h"
enum {
MT_MAX_DEPTH = 20,
MT_BRANCH_FACTOR = 10,
// note max branch is actually 2*MT_BRANCH_FACTOR
// and strictly this is ceil(log2(2*MT_BRANCH_FACTOR + 1))
// as we need a pseudo-index for "right before this node"
MT_LOG2_BRANCH = 5,
};
typedef struct {
int32_t row;
int32_t col;
} MTPos;
#define MTPos(r, c) ((MTPos){ .row = (r), .col = (c) })
typedef struct mtnode_s MTNode;
typedef struct {
MTPos pos;
int lvl;
MTNode *x;
int i;
struct {
int oldcol;
int i;
} s[MT_MAX_DEPTH];
size_t intersect_idx;
MTPos intersect_pos;
MTPos intersect_pos_x;
} MarkTreeIter;
#define marktree_itr_valid(itr) ((itr)->x != NULL)
// access raw key: flags in MT_FLAG_EXTERNAL_MASK and decor_data are safe to modify.
#define mt_itr_rawkey(itr) ((itr)->x->key[(itr)->i])
// Internal storage
//
// NB: actual marks have flags > 0, so we can use (row,col,0) pseudo-key for
// "space before (row,col)"
typedef struct {
MTPos pos;
uint32_t ns;
uint32_t id;
uint16_t flags;
DecorInlineData decor_data; // "ext" tag in flags
} MTKey;
typedef struct {
MTKey start;
MTPos end_pos;
bool end_right_gravity;
} MTPair;
typedef kvec_withinit_t(uint64_t, 4) Intersection;
struct mtnode_s {
int32_t n;
int16_t level;
int16_t p_idx; // index in parent
Intersection intersect;
// TODO(bfredl): we could consider having a only-sometimes-valid
// index into parent for faster "cached" lookup.
MTNode *parent;
MTKey key[2 * MT_BRANCH_FACTOR - 1];
MTNode *ptr[];
};
typedef struct {
MTNode *root;
size_t n_keys, n_nodes;
PMap(uint64_t) id2node[1];
} MarkTree;

View File

@ -14,6 +14,7 @@
#include "nvim/indent.h"
#include "nvim/macros_defs.h"
#include "nvim/mark.h"
#include "nvim/marktree.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/move.h"

View File

@ -1,10 +1,10 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdint.h> // IWYU pragma: keep
#include "nvim/buffer_defs.h"
#include "nvim/marktree.h"
#include "nvim/marktree_defs.h"
#include "nvim/pos_defs.h" // IWYU pragma: keep
/// Argument for lbr_chartabsize().