From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/viml/parser/expressions.c | 1 - src/nvim/viml/parser/parser.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/viml/parser') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 8b637fbb9b..11f5276053 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -59,7 +59,6 @@ #include "nvim/assert_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" -#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/keycodes.h" #include "nvim/macros_defs.h" diff --git a/src/nvim/viml/parser/parser.c b/src/nvim/viml/parser/parser.c index b854aedca6..d8679208c3 100644 --- a/src/nvim/viml/parser/parser.c +++ b/src/nvim/viml/parser/parser.c @@ -5,6 +5,7 @@ #endif void parser_simple_get_line(void *cookie, ParserLine *ret_pline) + FUNC_ATTR_NONNULL_ALL { ParserLine **plines_p = (ParserLine **)cookie; *ret_pline = **plines_p; -- cgit From af93a74a0f4afa9a3a4f55ffdf28141eaf776d22 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 18 Dec 2023 10:55:23 +0100 Subject: refactor: run IWYU on entire repo Reference: https://github.com/neovim/neovim/issues/6371. --- src/nvim/viml/parser/parser.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/viml/parser') diff --git a/src/nvim/viml/parser/parser.h b/src/nvim/viml/parser/parser.h index cd5a493643..b29a77b5ef 100644 --- a/src/nvim/viml/parser/parser.h +++ b/src/nvim/viml/parser/parser.h @@ -7,7 +7,6 @@ #include "klib/kvec.h" #include "nvim/func_attr.h" #include "nvim/mbyte.h" -#include "nvim/mbyte_defs.h" #include "nvim/memory.h" /// One parsed line -- cgit From 089b934352437ab310a6dd3b138c7ed9445a3d7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Dec 2023 12:24:23 +0800 Subject: refactor(options): generate BV_ and WV_ constants (#26705) --- src/nvim/viml/parser/expressions.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/viml/parser') diff --git a/src/nvim/viml/parser/expressions.h b/src/nvim/viml/parser/expressions.h index 94287ea4e1..ff33b9ead1 100644 --- a/src/nvim/viml/parser/expressions.h +++ b/src/nvim/viml/parser/expressions.h @@ -8,8 +8,6 @@ #include "nvim/types_defs.h" #include "nvim/viml/parser/parser.h" -struct expr_ast_node; - // Defines whether to ignore case: // == kCCStrategyUseOption // ==# kCCStrategyMatchCase -- cgit From 1813661a6197c76ea6621284570aca1d56597099 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 4 Jan 2024 15:38:16 +0100 Subject: refactor(IWYU): fix headers Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want. --- src/nvim/viml/parser/expressions.c | 2 +- src/nvim/viml/parser/expressions.h | 2 +- src/nvim/viml/parser/parser.c | 62 ++++++++++++++++ src/nvim/viml/parser/parser.h | 142 +------------------------------------ src/nvim/viml/parser/parser_defs.h | 79 +++++++++++++++++++++ 5 files changed, 145 insertions(+), 142 deletions(-) create mode 100644 src/nvim/viml/parser/parser_defs.h (limited to 'src/nvim/viml/parser') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 11f5276053..3403fb7926 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -59,7 +59,7 @@ #include "nvim/assert_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" -#include "nvim/gettext.h" +#include "nvim/gettext_defs.h" #include "nvim/keycodes.h" #include "nvim/macros_defs.h" #include "nvim/mbyte.h" diff --git a/src/nvim/viml/parser/expressions.h b/src/nvim/viml/parser/expressions.h index ff33b9ead1..ba54c4de07 100644 --- a/src/nvim/viml/parser/expressions.h +++ b/src/nvim/viml/parser/expressions.h @@ -6,7 +6,7 @@ #include "nvim/eval/typval_defs.h" #include "nvim/types_defs.h" -#include "nvim/viml/parser/parser.h" +#include "nvim/viml/parser/parser_defs.h" // Defines whether to ignore case: // == kCCStrategyUseOption diff --git a/src/nvim/viml/parser/parser.c b/src/nvim/viml/parser/parser.c index d8679208c3..bdade3fae2 100644 --- a/src/nvim/viml/parser/parser.c +++ b/src/nvim/viml/parser/parser.c @@ -1,3 +1,6 @@ +#include "nvim/func_attr.h" +#include "nvim/mbyte.h" +#include "nvim/memory.h" #include "nvim/viml/parser/parser.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -11,3 +14,62 @@ void parser_simple_get_line(void *cookie, ParserLine *ret_pline) *ret_pline = **plines_p; (*plines_p)++; } + +/// Get currently parsed line, shifted to pstate->pos.col +/// +/// @param pstate Parser state to operate on. +/// +/// @return True if there is a line, false in case of EOF. +bool viml_parser_get_remaining_line(ParserState *const pstate, ParserLine *const ret_pline) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL +{ + const size_t num_lines = kv_size(pstate->reader.lines); + if (pstate->pos.line == num_lines) { + viml_preader_get_line(&pstate->reader, ret_pline); + } else { + *ret_pline = kv_last(pstate->reader.lines); + } + assert(pstate->pos.line == kv_size(pstate->reader.lines) - 1); + if (ret_pline->data != NULL) { + ret_pline->data += pstate->pos.col; + ret_pline->size -= pstate->pos.col; + } + return ret_pline->data != NULL; +} + +/// Get one line from ParserInputReader +static void viml_preader_get_line(ParserInputReader *const preader, ParserLine *const ret_pline) + FUNC_ATTR_NONNULL_ALL +{ + ParserLine pline; + preader->get_line(preader->cookie, &pline); + if (preader->conv.vc_type != CONV_NONE && pline.size) { + ParserLine cpline = { + .allocated = true, + .size = pline.size, + }; + cpline.data = string_convert(&preader->conv, (char *)pline.data, &cpline.size); + if (pline.allocated) { + xfree((void *)pline.data); + } + pline = cpline; + } + kvi_push(preader->lines, pline); + *ret_pline = pline; +} + +/// Free all memory allocated by the parser on heap +/// +/// @param pstate Parser state to free. +void viml_parser_destroy(ParserState *const pstate) + FUNC_ATTR_NONNULL_ALL +{ + for (size_t i = 0; i < kv_size(pstate->reader.lines); i++) { + ParserLine pline = kv_A(pstate->reader.lines, i); + if (pline.allocated) { + xfree((void *)pline.data); + } + } + kvi_destroy(pstate->reader.lines); + kvi_destroy(pstate->stack); +} diff --git a/src/nvim/viml/parser/parser.h b/src/nvim/viml/parser/parser.h index b29a77b5ef..31decdc798 100644 --- a/src/nvim/viml/parser/parser.h +++ b/src/nvim/viml/parser/parser.h @@ -6,79 +6,8 @@ #include "klib/kvec.h" #include "nvim/func_attr.h" -#include "nvim/mbyte.h" -#include "nvim/memory.h" - -/// One parsed line -typedef struct { - const char *data; ///< Parsed line pointer - size_t size; ///< Parsed line size - bool allocated; ///< True if line may be freed. -} ParserLine; - -/// Line getter type for parser -/// -/// Line getter must return {NULL, 0} for EOF. -typedef void (*ParserLineGetter)(void *cookie, ParserLine *ret_pline); - -/// Parser position in the input -typedef struct { - size_t line; ///< Line index in ParserInputReader.lines. - size_t col; ///< Byte index in the line. -} ParserPosition; - -/// Parser state item. -typedef struct { - enum { - kPTopStateParsingCommand = 0, - kPTopStateParsingExpression, - } type; - union { - struct { - enum { - kExprUnknown = 0, - } type; - } expr; - } data; -} ParserStateItem; - -/// Structure defining input reader -typedef struct { - /// Function used to get next line. - ParserLineGetter get_line; - /// Data for get_line function. - void *cookie; - /// All lines obtained by get_line. - kvec_withinit_t(ParserLine, 4) lines; - /// Conversion, for :scriptencoding. - vimconv_T conv; -} ParserInputReader; - -/// Highlighted region definition -/// -/// Note: one chunk may highlight only one line. -typedef struct { - ParserPosition start; ///< Start of the highlight: line and column. - size_t end_col; ///< End column, points to the start of the next character. - const char *group; ///< Highlight group. -} ParserHighlightChunk; - -/// Highlighting defined by a parser -typedef kvec_withinit_t(ParserHighlightChunk, 16) ParserHighlight; - -/// Structure defining parser state -typedef struct { - /// Line reader. - ParserInputReader reader; - /// Position up to which input was parsed. - ParserPosition pos; - /// Parser state stack. - kvec_withinit_t(ParserStateItem, 16) stack; - /// Highlighting support. - ParserHighlight *colors; - /// True if line continuation can be used. - bool can_continuate; -} ParserState; +#include "nvim/mbyte_defs.h" +#include "nvim/viml/parser/parser_defs.h" // IWYU pragma: keep static inline void viml_parser_init(ParserState *ret_pstate, ParserLineGetter get_line, void *cookie, ParserHighlight *colors) @@ -108,73 +37,6 @@ static inline void viml_parser_init(ParserState *const ret_pstate, const ParserL kvi_init(ret_pstate->stack); } -static inline void viml_parser_destroy(ParserState *pstate) - REAL_FATTR_NONNULL_ALL REAL_FATTR_ALWAYS_INLINE; - -/// Free all memory allocated by the parser on heap -/// -/// @param pstate Parser state to free. -static inline void viml_parser_destroy(ParserState *const pstate) -{ - for (size_t i = 0; i < kv_size(pstate->reader.lines); i++) { - ParserLine pline = kv_A(pstate->reader.lines, i); - if (pline.allocated) { - xfree((void *)pline.data); - } - } - kvi_destroy(pstate->reader.lines); - kvi_destroy(pstate->stack); -} - -static inline void viml_preader_get_line(ParserInputReader *preader, ParserLine *ret_pline) - REAL_FATTR_NONNULL_ALL; - -/// Get one line from ParserInputReader -static inline void viml_preader_get_line(ParserInputReader *const preader, - ParserLine *const ret_pline) -{ - ParserLine pline; - preader->get_line(preader->cookie, &pline); - if (preader->conv.vc_type != CONV_NONE && pline.size) { - ParserLine cpline = { - .allocated = true, - .size = pline.size, - }; - cpline.data = string_convert(&preader->conv, (char *)pline.data, &cpline.size); - if (pline.allocated) { - xfree((void *)pline.data); - } - pline = cpline; - } - kvi_push(preader->lines, pline); - *ret_pline = pline; -} - -static inline bool viml_parser_get_remaining_line(ParserState *pstate, ParserLine *ret_pline) - REAL_FATTR_ALWAYS_INLINE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_NONNULL_ALL; - -/// Get currently parsed line, shifted to pstate->pos.col -/// -/// @param pstate Parser state to operate on. -/// -/// @return True if there is a line, false in case of EOF. -static inline bool viml_parser_get_remaining_line(ParserState *const pstate, - ParserLine *const ret_pline) -{ - const size_t num_lines = kv_size(pstate->reader.lines); - if (pstate->pos.line == num_lines) { - viml_preader_get_line(&pstate->reader, ret_pline); - } else { - *ret_pline = kv_last(pstate->reader.lines); - } - assert(pstate->pos.line == kv_size(pstate->reader.lines) - 1); - if (ret_pline->data != NULL) { - ret_pline->data += pstate->pos.col; - ret_pline->size -= pstate->pos.col; - } - return ret_pline->data != NULL; -} - static inline void viml_parser_advance(ParserState *pstate, size_t len) REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL; diff --git a/src/nvim/viml/parser/parser_defs.h b/src/nvim/viml/parser/parser_defs.h new file mode 100644 index 0000000000..59fab23054 --- /dev/null +++ b/src/nvim/viml/parser/parser_defs.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include +#include + +#include "klib/kvec.h" +#include "nvim/mbyte_defs.h" + +/// One parsed line +typedef struct { + const char *data; ///< Parsed line pointer + size_t size; ///< Parsed line size + bool allocated; ///< True if line may be freed. +} ParserLine; + +/// Line getter type for parser +/// +/// Line getter must return {NULL, 0} for EOF. +typedef void (*ParserLineGetter)(void *cookie, ParserLine *ret_pline); + +/// Parser position in the input +typedef struct { + size_t line; ///< Line index in ParserInputReader.lines. + size_t col; ///< Byte index in the line. +} ParserPosition; + +/// Parser state item. +typedef struct { + enum { + kPTopStateParsingCommand = 0, + kPTopStateParsingExpression, + } type; + union { + struct { + enum { + kExprUnknown = 0, + } type; + } expr; + } data; +} ParserStateItem; + +/// Structure defining input reader +typedef struct { + /// Function used to get next line. + ParserLineGetter get_line; + /// Data for get_line function. + void *cookie; + /// All lines obtained by get_line. + kvec_withinit_t(ParserLine, 4) lines; + /// Conversion, for :scriptencoding. + vimconv_T conv; +} ParserInputReader; + +/// Highlighted region definition +/// +/// Note: one chunk may highlight only one line. +typedef struct { + ParserPosition start; ///< Start of the highlight: line and column. + size_t end_col; ///< End column, points to the start of the next character. + const char *group; ///< Highlight group. +} ParserHighlightChunk; + +/// Highlighting defined by a parser +typedef kvec_withinit_t(ParserHighlightChunk, 16) ParserHighlight; + +/// Structure defining parser state +typedef struct { + /// Line reader. + ParserInputReader reader; + /// Position up to which input was parsed. + ParserPosition pos; + /// Parser state stack. + kvec_withinit_t(ParserStateItem, 16) stack; + /// Highlighting support. + ParserHighlight *colors; + /// True if line continuation can be used. + bool can_continuate; +} ParserState; -- cgit