refactor: move extern variables out of _defs.h files (#26320)

This commit is contained in:
zeertzjq 2023-11-30 18:41:52 +08:00 committed by GitHub
parent ce56e0a845
commit 95dbf1af73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 205 additions and 183 deletions

View File

@ -880,18 +880,21 @@ def CheckForHeaderGuard(filename, lines, error):
error(filename, 0, 'build/header_guard', 5,
'No "#pragma once" found in header')
def CheckIncludes(filename, lines, error):
"""Checks that headers only include _defs headers
"""Checks that headers only include _defs headers.
Args:
filename: The name of the C++ header file.
lines: An array of strings, each representing a line of the file.
error: The function to call with any errors found.
"""
if filename.endswith('.c.h') or filename.endswith('.in.h') or FileInfo(filename).RelativePath() in {
if (filename.endswith('.c.h')
or filename.endswith('.in.h')
or FileInfo(filename).RelativePath() in {
'func_attr.h',
'os/pty_process.h',
}:
}):
return
# These should be synced with the ignored headers in the `iwyu` target in
@ -999,6 +1002,21 @@ def CheckIncludes(filename, lines, error):
'Headers should not include non-"_defs" headers')
def CheckNonSymbols(filename, lines, error):
"""Checks that a _defs.h header only contains non-symbols.
Args:
filename: The name of the C++ header file.
lines: An array of strings, each representing a line of the file.
error: The function to call with any errors found.
"""
for i, line in enumerate(lines):
# Only a check against extern variables for now.
if line.startswith('EXTERN ') or line.startswith('extern '):
error(filename, i, 'build/defs_header', 5,
'"_defs" headers should not contain extern variables')
def CheckForBadCharacters(filename, lines, error):
"""Logs an error for each line containing bad characters.
@ -2286,6 +2304,8 @@ def ProcessFileData(filename, file_extension, lines, error,
if file_extension == 'h':
CheckForHeaderGuard(filename, lines, error)
CheckIncludes(filename, lines, error)
if filename.endswith('/defs.h') or filename.endswith('_defs.h'):
CheckNonSymbols(filename, lines, error)
RemoveMultiLineComments(filename, lines, error)
clean_lines = CleansedLines(lines, init_lines)

View File

@ -357,8 +357,6 @@ typedef struct {
#define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, \
LUA_NOREF, LUA_NOREF, false, false }
EXTERN int curbuf_splice_pending INIT( = 0);
#define BUF_HAS_QF_ENTRY 1
#define BUF_HAS_LL_ENTRY 2
@ -904,12 +902,7 @@ enum {
kFloatAnchorSouth = 2,
};
// NW -> 0
// NE -> kFloatAnchorEast
// SW -> kFloatAnchorSouth
// SE -> kFloatAnchorSouth | kFloatAnchorEast
EXTERN const char *const float_anchor_str[] INIT( = { "NW", "NE", "SW", "SE" });
/// Keep in sync with float_relative_str in winfloat.h
typedef enum {
kFloatRelativeEditor = 0,
kFloatRelativeWindow = 1,
@ -917,9 +910,6 @@ typedef enum {
kFloatRelativeMouse = 3,
} FloatRelative;
EXTERN const char *const float_relative_str[] INIT( = { "editor", "win",
"cursor", "mouse" });
typedef enum {
kWinStyleUnused = 0,
kWinStyleMinimal, /// Minimal UI: no number column, eob markers, etc

View File

@ -13,7 +13,7 @@
#include "nvim/pos_defs.h"
#include "nvim/types_defs.h"
EXTERN int extmark_splice_pending INIT( = 0);
EXTERN int curbuf_splice_pending INIT( = 0);
typedef kvec_t(MTPair) ExtmarkInfoArray;

View File

@ -6,9 +6,100 @@
#include "nvim/api/private/defs.h" // IWYU pragma: keep
#include "nvim/buffer_defs.h" // IWYU pragma: keep
#include "nvim/highlight_defs.h" // IWYU pragma: export
#include "nvim/macros_defs.h"
#include "nvim/option_vars.h"
#include "nvim/types_defs.h"
#include "nvim/ui_defs.h" // IWYU pragma: keep
EXTERN const char *hlf_names[] INIT( = {
[HLF_8] = "SpecialKey",
[HLF_EOB] = "EndOfBuffer",
[HLF_TERM] = "TermCursor",
[HLF_TERMNC] = "TermCursorNC",
[HLF_AT] = "NonText",
[HLF_D] = "Directory",
[HLF_E] = "ErrorMsg",
[HLF_I] = "IncSearch",
[HLF_L] = "Search",
[HLF_LC] = "CurSearch",
[HLF_M] = "MoreMsg",
[HLF_CM] = "ModeMsg",
[HLF_N] = "LineNr",
[HLF_LNA] = "LineNrAbove",
[HLF_LNB] = "LineNrBelow",
[HLF_CLN] = "CursorLineNr",
[HLF_CLS] = "CursorLineSign",
[HLF_CLF] = "CursorLineFold",
[HLF_R] = "Question",
[HLF_S] = "StatusLine",
[HLF_SNC] = "StatusLineNC",
[HLF_C] = "WinSeparator",
[HLF_T] = "Title",
[HLF_V] = "Visual",
[HLF_VNC] = "VisualNC",
[HLF_VSP] = "VertSplit",
[HLF_W] = "WarningMsg",
[HLF_WM] = "WildMenu",
[HLF_FL] = "Folded",
[HLF_FC] = "FoldColumn",
[HLF_ADD] = "DiffAdd",
[HLF_CHD] = "DiffChange",
[HLF_DED] = "DiffDelete",
[HLF_TXD] = "DiffText",
[HLF_SC] = "SignColumn",
[HLF_CONCEAL] = "Conceal",
[HLF_SPB] = "SpellBad",
[HLF_SPC] = "SpellCap",
[HLF_SPR] = "SpellRare",
[HLF_SPL] = "SpellLocal",
[HLF_PNI] = "Pmenu",
[HLF_PSI] = "PmenuSel",
[HLF_PNK] = "PmenuKind",
[HLF_PSK] = "PmenuKindSel",
[HLF_PNX] = "PmenuExtra",
[HLF_PSX] = "PmenuExtraSel",
[HLF_PSB] = "PmenuSbar",
[HLF_PST] = "PmenuThumb",
[HLF_TP] = "TabLine",
[HLF_TPS] = "TabLineSel",
[HLF_TPF] = "TabLineFill",
[HLF_CUC] = "CursorColumn",
[HLF_CUL] = "CursorLine",
[HLF_MC] = "ColorColumn",
[HLF_QFL] = "QuickFixLine",
[HLF_0] = "Whitespace",
[HLF_INACTIVE] = "NormalNC",
[HLF_MSGSEP] = "MsgSeparator",
[HLF_NFLOAT] = "NormalFloat",
[HLF_MSG] = "MsgArea",
[HLF_BORDER] = "FloatBorder",
[HLF_WBR] = "WinBar",
[HLF_WBRNC] = "WinBarNC",
[HLF_CU] = "Cursor",
[HLF_BTITLE] = "FloatTitle",
[HLF_BFOOTER] = "FloatFooter",
});
EXTERN int highlight_attr[HLF_COUNT + 1]; // Highl. attr for each context.
EXTERN int highlight_attr_last[HLF_COUNT]; // copy for detecting changed groups
EXTERN int highlight_user[9]; // User[1-9] attributes
EXTERN int highlight_stlnc[9]; // On top of user
EXTERN int cterm_normal_fg_color INIT( = 0);
EXTERN int cterm_normal_bg_color INIT( = 0);
EXTERN RgbValue normal_fg INIT( = -1);
EXTERN RgbValue normal_bg INIT( = -1);
EXTERN RgbValue normal_sp INIT( = -1);
EXTERN NS ns_hl_global INIT( = 0); // global highlight namespace
EXTERN NS ns_hl_win INIT( = -1); // highlight namespace for the current window
EXTERN NS ns_hl_fast INIT( = -1); // highlight namespace specified in a fast callback
EXTERN NS ns_hl_active INIT( = 0); // currently active/cached namespace
EXTERN int *hl_attr_active INIT( = highlight_attr);
// Enums need a typecast to be used as array index.
#define HL_ATTR(n) hl_attr_active[(int)(n)]
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "highlight.h.generated.h"
#endif
@ -20,8 +111,6 @@ static inline int win_hl_attr(win_T *wp, int hlf)
return ((wp->w_ns_hl_attr && ns_hl_fast < 0) ? wp->w_ns_hl_attr : hl_attr_active)[hlf];
}
#define HLATTRS_DICT_SIZE 16
#define HL_SET_DEFAULT_COLORS(rgb_fg, rgb_bg, rgb_sp) \
do { \
bool dark_ = (*p_bg == 'd'); \
@ -29,6 +118,3 @@ static inline int win_hl_attr(win_T *wp, int hlf)
rgb_bg = rgb_bg != -1 ? rgb_bg : (dark_ ? 0x000000 : 0xFFFFFF); \
rgb_sp = rgb_sp != -1 ? rgb_sp : 0xFF0000; \
} while (0);
// Enums need a typecast to be used as array index.
#define HL_ATTR(n) hl_attr_active[(int)(n)]

View File

@ -1,9 +1,7 @@
#pragma once
#include <inttypes.h>
#include "nvim/macros_defs.h"
#include "nvim/types_defs.h"
#include <stdbool.h>
#include <stdint.h>
typedef int32_t RgbValue;
@ -54,164 +52,78 @@ typedef struct attr_entry {
}
/// Values for index in highlight_attr[].
/// When making changes, also update hlf_names below!
/// When making changes, also update hlf_names in highlight.h!
typedef enum {
HLF_8 = 0, // Meta & special keys listed with ":map", text that is
// displayed different from what it is
HLF_EOB, // after the last line in the buffer
HLF_TERM, // terminal cursor focused
HLF_TERMNC, // terminal cursor unfocused
HLF_AT, // @ characters at end of screen, characters that don't really exist in the text
HLF_D, // directories in CTRL-D listing
HLF_E, // error messages
HLF_I, // incremental search
HLF_L, // last search string
HLF_LC, // current search match
HLF_M, // "--More--" message
HLF_CM, // Mode (e.g., "-- INSERT --")
HLF_N, // line number for ":number" and ":#" commands
HLF_LNA, // LineNrAbove
HLF_LNB, // LineNrBelow
HLF_CLN, // current line number when 'cursorline' is set
HLF_CLS, // current line sign column
HLF_CLF, // current line fold
HLF_R, // return to continue message and yes/no questions
HLF_S, // status lines
HLF_SNC, // status lines of not-current windows
HLF_C, // window split separators
HLF_VSP, // VertSplit
HLF_T, // Titles for output from ":set all", ":autocmd" etc.
HLF_V, // Visual mode
HLF_VNC, // Visual mode, autoselecting and not clipboard owner
HLF_W, // warning messages
HLF_WM, // Wildmenu highlight
HLF_FL, // Folded line
HLF_FC, // Fold column
HLF_ADD, // Added diff line
HLF_CHD, // Changed diff line
HLF_DED, // Deleted diff line
HLF_TXD, // Text Changed in diff line
HLF_SC, // Sign column
HLF_CONCEAL, // Concealed text
HLF_SPB, // SpellBad
HLF_SPC, // SpellCap
HLF_SPR, // SpellRare
HLF_SPL, // SpellLocal
HLF_PNI, // popup menu normal item
HLF_PSI, // popup menu selected item
HLF_PNK, // popup menu normal item "kind"
HLF_PSK, // popup menu selected item "kind"
HLF_PNX, // popup menu normal item "menu" (extra text)
HLF_PSX, // popup menu selected item "menu" (extra text)
HLF_PSB, // popup menu scrollbar
HLF_PST, // popup menu scrollbar thumb
HLF_TP, // tabpage line
HLF_TPS, // tabpage line selected
HLF_TPF, // tabpage line filler
HLF_CUC, // 'cursorcolumn'
HLF_CUL, // 'cursorline'
HLF_MC, // 'colorcolumn'
HLF_QFL, // selected quickfix line
HLF_0, // Whitespace
HLF_INACTIVE, // NormalNC: Normal text in non-current windows
HLF_MSGSEP, // message separator line
HLF_NFLOAT, // Floating window
HLF_MSG, // Message area
HLF_BORDER, // Floating window border
HLF_WBR, // Window bars
HLF_WBRNC, // Window bars of not-current windows
HLF_CU, // Cursor
HLF_BTITLE, // Float Border Title
HLF_BFOOTER, // Float Border Footer
HLF_COUNT, // MUST be the last one
HLF_8 = 0, ///< Meta & special keys listed with ":map", text that is
///< displayed different from what it is
HLF_EOB, ///< after the last line in the buffer
HLF_TERM, ///< terminal cursor focused
HLF_TERMNC, ///< terminal cursor unfocused
HLF_AT, ///< @ characters at end of screen, characters that don't really exist in the text
HLF_D, ///< directories in CTRL-D listing
HLF_E, ///< error messages
HLF_I, ///< incremental search
HLF_L, ///< last search string
HLF_LC, ///< current search match
HLF_M, ///< "--More--" message
HLF_CM, ///< Mode (e.g., "-- INSERT --")
HLF_N, ///< line number for ":number" and ":#" commands
HLF_LNA, ///< LineNrAbove
HLF_LNB, ///< LineNrBelow
HLF_CLN, ///< current line number when 'cursorline' is set
HLF_CLS, ///< current line sign column
HLF_CLF, ///< current line fold
HLF_R, ///< return to continue message and yes/no questions
HLF_S, ///< status lines
HLF_SNC, ///< status lines of not-current windows
HLF_C, ///< window split separators
HLF_VSP, ///< VertSplit
HLF_T, ///< Titles for output from ":set all", ":autocmd" etc.
HLF_V, ///< Visual mode
HLF_VNC, ///< Visual mode, autoselecting and not clipboard owner
HLF_W, ///< warning messages
HLF_WM, ///< Wildmenu highlight
HLF_FL, ///< Folded line
HLF_FC, ///< Fold column
HLF_ADD, ///< Added diff line
HLF_CHD, ///< Changed diff line
HLF_DED, ///< Deleted diff line
HLF_TXD, ///< Text Changed in diff line
HLF_SC, ///< Sign column
HLF_CONCEAL, ///< Concealed text
HLF_SPB, ///< SpellBad
HLF_SPC, ///< SpellCap
HLF_SPR, ///< SpellRare
HLF_SPL, ///< SpellLocal
HLF_PNI, ///< popup menu normal item
HLF_PSI, ///< popup menu selected item
HLF_PNK, ///< popup menu normal item "kind"
HLF_PSK, ///< popup menu selected item "kind"
HLF_PNX, ///< popup menu normal item "menu" (extra text)
HLF_PSX, ///< popup menu selected item "menu" (extra text)
HLF_PSB, ///< popup menu scrollbar
HLF_PST, ///< popup menu scrollbar thumb
HLF_TP, ///< tabpage line
HLF_TPS, ///< tabpage line selected
HLF_TPF, ///< tabpage line filler
HLF_CUC, ///< 'cursorcolumn'
HLF_CUL, ///< 'cursorline'
HLF_MC, ///< 'colorcolumn'
HLF_QFL, ///< selected quickfix line
HLF_0, ///< Whitespace
HLF_INACTIVE, ///< NormalNC: Normal text in non-current windows
HLF_MSGSEP, ///< message separator line
HLF_NFLOAT, ///< Floating window
HLF_MSG, ///< Message area
HLF_BORDER, ///< Floating window border
HLF_WBR, ///< Window bars
HLF_WBRNC, ///< Window bars of not-current windows
HLF_CU, ///< Cursor
HLF_BTITLE, ///< Float Border Title
HLF_BFOOTER, ///< Float Border Footer
HLF_COUNT, ///< MUST be the last one
} hlf_T;
EXTERN const char *hlf_names[] INIT( = {
[HLF_8] = "SpecialKey",
[HLF_EOB] = "EndOfBuffer",
[HLF_TERM] = "TermCursor",
[HLF_TERMNC] = "TermCursorNC",
[HLF_AT] = "NonText",
[HLF_D] = "Directory",
[HLF_E] = "ErrorMsg",
[HLF_I] = "IncSearch",
[HLF_L] = "Search",
[HLF_LC] = "CurSearch",
[HLF_M] = "MoreMsg",
[HLF_CM] = "ModeMsg",
[HLF_N] = "LineNr",
[HLF_LNA] = "LineNrAbove",
[HLF_LNB] = "LineNrBelow",
[HLF_CLN] = "CursorLineNr",
[HLF_CLS] = "CursorLineSign",
[HLF_CLF] = "CursorLineFold",
[HLF_R] = "Question",
[HLF_S] = "StatusLine",
[HLF_SNC] = "StatusLineNC",
[HLF_C] = "WinSeparator",
[HLF_T] = "Title",
[HLF_V] = "Visual",
[HLF_VNC] = "VisualNC",
[HLF_VSP] = "VertSplit",
[HLF_W] = "WarningMsg",
[HLF_WM] = "WildMenu",
[HLF_FL] = "Folded",
[HLF_FC] = "FoldColumn",
[HLF_ADD] = "DiffAdd",
[HLF_CHD] = "DiffChange",
[HLF_DED] = "DiffDelete",
[HLF_TXD] = "DiffText",
[HLF_SC] = "SignColumn",
[HLF_CONCEAL] = "Conceal",
[HLF_SPB] = "SpellBad",
[HLF_SPC] = "SpellCap",
[HLF_SPR] = "SpellRare",
[HLF_SPL] = "SpellLocal",
[HLF_PNI] = "Pmenu",
[HLF_PSI] = "PmenuSel",
[HLF_PNK] = "PmenuKind",
[HLF_PSK] = "PmenuKindSel",
[HLF_PNX] = "PmenuExtra",
[HLF_PSX] = "PmenuExtraSel",
[HLF_PSB] = "PmenuSbar",
[HLF_PST] = "PmenuThumb",
[HLF_TP] = "TabLine",
[HLF_TPS] = "TabLineSel",
[HLF_TPF] = "TabLineFill",
[HLF_CUC] = "CursorColumn",
[HLF_CUL] = "CursorLine",
[HLF_MC] = "ColorColumn",
[HLF_QFL] = "QuickFixLine",
[HLF_0] = "Whitespace",
[HLF_INACTIVE] = "NormalNC",
[HLF_MSGSEP] = "MsgSeparator",
[HLF_NFLOAT] = "NormalFloat",
[HLF_MSG] = "MsgArea",
[HLF_BORDER] = "FloatBorder",
[HLF_WBR] = "WinBar",
[HLF_WBRNC] = "WinBarNC",
[HLF_CU] = "Cursor",
[HLF_BTITLE] = "FloatTitle",
[HLF_BFOOTER] = "FloatFooter",
});
EXTERN int highlight_attr[HLF_COUNT + 1]; // Highl. attr for each context.
EXTERN int highlight_attr_last[HLF_COUNT]; // copy for detecting changed groups
EXTERN int highlight_user[9]; // User[1-9] attributes
EXTERN int highlight_stlnc[9]; // On top of user
EXTERN int cterm_normal_fg_color INIT( = 0);
EXTERN int cterm_normal_bg_color INIT( = 0);
EXTERN RgbValue normal_fg INIT( = -1);
EXTERN RgbValue normal_bg INIT( = -1);
EXTERN RgbValue normal_sp INIT( = -1);
EXTERN NS ns_hl_global INIT( = 0); // global highlight namespace
EXTERN NS ns_hl_win INIT( = -1); // highlight namespace for the current window
EXTERN NS ns_hl_fast INIT( = -1); // highlight namespace specified in a fast callback
EXTERN NS ns_hl_active INIT( = 0); // currently active/cached namespace
EXTERN int *hl_attr_active INIT( = highlight_attr);
typedef enum {
kHlUnknown,
kHlUI,
@ -246,3 +158,5 @@ typedef struct {
} ColorItem;
#define COLOR_ITEM_INITIALIZER { .attr_id = -1, .link_id = -1, .version = -1, \
.is_default = false, .link_global = false }
enum { HLATTRS_DICT_SIZE = 16, };

View File

@ -26,7 +26,6 @@
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/channel.h"
#include "nvim/decoration.h"
#include "nvim/decoration_provider.h"
@ -42,6 +41,7 @@
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
@ -96,6 +96,7 @@
#include "nvim/version.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"
#include "nvim/winfloat.h"
#ifdef MSWIN
# include "nvim/os/os_win_console.h"
#endif

View File

@ -121,6 +121,9 @@ static inline void clearpos(pos_T *a)
a->coladd = 0;
}
/// Global marks (marks with file number or name)
EXTERN xfmark_T namedfm[NGLOBALMARKS] INIT( = { 0 });
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mark.h.generated.h"
#endif

View File

@ -84,6 +84,3 @@ typedef struct xfilemark {
} xfmark_T;
#define INIT_XFMARK { INIT_FMARK, NULL }
/// Global marks (marks with file number or name)
EXTERN xfmark_T namedfm[NGLOBALMARKS] INIT( = { 0 });

View File

@ -2,6 +2,17 @@
#include "nvim/api/private/defs.h" // IWYU pragma: keep
#include "nvim/buffer_defs.h" // IWYU pragma: keep
#include "nvim/macros_defs.h"
/// NW -> 0
/// NE -> kFloatAnchorEast
/// SW -> kFloatAnchorSouth
/// SE -> kFloatAnchorSouth | kFloatAnchorEast
EXTERN const char *const float_anchor_str[] INIT( = { "NW", "NE", "SW", "SE" });
/// Keep in sync with FloatRelative in buffer_defs.h
EXTERN const char *const float_relative_str[]
INIT( = { "editor", "win", "cursor", "mouse" });
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "winfloat.h.generated.h"