diff options
Diffstat (limited to 'src/nvim/generators/gen_declarations.lua')
-rw-r--r-- | src/nvim/generators/gen_declarations.lua | 200 |
1 files changed, 94 insertions, 106 deletions
diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua index f9e9c6b0a8..5d1e586fe6 100644 --- a/src/nvim/generators/gen_declarations.lua +++ b/src/nvim/generators/gen_declarations.lua @@ -5,9 +5,9 @@ local preproc_fname = arg[4] local lpeg = vim.lpeg -local fold = function (func, ...) +local fold = function(func, ...) local result = nil - for _, v in ipairs({...}) do + for _, v in ipairs({ ... }) do if result == nil then result = v else @@ -17,144 +17,112 @@ local fold = function (func, ...) return result end -local folder = function (func) - return function (...) +local folder = function(func) + return function(...) return fold(func, ...) end end local lit = lpeg.P local set = function(...) - return lpeg.S(fold(function (a, b) return a .. b end, ...)) + return lpeg.S(fold(function(a, b) + return a .. b + end, ...)) end local any_character = lpeg.P(1) -local rng = function(s, e) return lpeg.R(s .. e) end -local concat = folder(function (a, b) return a * b end) -local branch = folder(function (a, b) return a + b end) -local one_or_more = function(v) return v ^ 1 end -local two_or_more = function(v) return v ^ 2 end -local any_amount = function(v) return v ^ 0 end -local one_or_no = function(v) return v ^ -1 end +local rng = function(s, e) + return lpeg.R(s .. e) +end +local concat = folder(function(a, b) + return a * b +end) +local branch = folder(function(a, b) + return a + b +end) +local one_or_more = function(v) + return v ^ 1 +end +local two_or_more = function(v) + return v ^ 2 +end +local any_amount = function(v) + return v ^ 0 +end +local one_or_no = function(v) + return v ^ -1 +end local look_behind = lpeg.B -local look_ahead = function(v) return #v end -local neg_look_ahead = function(v) return -v end -local neg_look_behind = function(v) return -look_behind(v) end +local look_ahead = function(v) + return #v +end +local neg_look_ahead = function(v) + return -v +end +local neg_look_behind = function(v) + return -look_behind(v) +end -local w = branch( - rng('a', 'z'), - rng('A', 'Z'), - lit('_') -) -local aw = branch( - w, - rng('0', '9') -) +local w = branch(rng('a', 'z'), rng('A', 'Z'), lit('_')) +local aw = branch(w, rng('0', '9')) local s = set(' ', '\n', '\t') local raw_word = concat(w, any_amount(aw)) -local right_word = concat( - raw_word, - neg_look_ahead(aw) -) +local right_word = concat(raw_word, neg_look_ahead(aw)) local word = branch( concat( branch(lit('ArrayOf('), lit('DictionaryOf('), lit('Dict(')), -- typed container macro one_or_more(any_character - lit(')')), lit(')') ), - concat( - neg_look_behind(aw), - right_word - ) -) -local inline_comment = concat( - lit('/*'), - any_amount(concat( - neg_look_ahead(lit('*/')), - any_character - )), - lit('*/') + concat(neg_look_behind(aw), right_word) ) +local inline_comment = + concat(lit('/*'), any_amount(concat(neg_look_ahead(lit('*/')), any_character)), lit('*/')) local spaces = any_amount(branch( s, -- Comments are really handled by preprocessor, so the following is not needed inline_comment, - concat( - lit('//'), - any_amount(concat( - neg_look_ahead(lit('\n')), - any_character - )), - lit('\n') - ), + concat(lit('//'), any_amount(concat(neg_look_ahead(lit('\n')), any_character)), lit('\n')), -- Linemarker inserted by preprocessor - concat( - lit('# '), - any_amount(concat( - neg_look_ahead(lit('\n')), - any_character - )), - lit('\n') - ) + concat(lit('# '), any_amount(concat(neg_look_ahead(lit('\n')), any_character)), lit('\n')) )) -local typ_part = concat( - word, - any_amount(concat( - spaces, - lit('*') - )), - spaces -) +local typ_part = concat(word, any_amount(concat(spaces, lit('*'))), spaces) local typ_id = two_or_more(typ_part) -local arg = typ_id -- argument name is swallowed by typ +local arg = typ_id -- argument name is swallowed by typ local pattern = concat( any_amount(branch(set(' ', '\t'), inline_comment)), - typ_id, -- return type with function name + typ_id, -- return type with function name spaces, lit('('), spaces, - one_or_no(branch( -- function arguments + one_or_no(branch( -- function arguments concat( - arg, -- first argument, does not require comma - any_amount(concat( -- following arguments, start with a comma + arg, -- first argument, does not require comma + any_amount(concat( -- following arguments, start with a comma spaces, lit(','), spaces, arg, - any_amount(concat( - lit('['), - spaces, - any_amount(aw), - spaces, - lit(']') - )) + any_amount(concat(lit('['), spaces, any_amount(aw), spaces, lit(']'))) )), - one_or_no(concat( - spaces, - lit(','), - spaces, - lit('...') - )) + one_or_no(concat(spaces, lit(','), spaces, lit('...'))) ), - lit('void') -- also accepts just void + lit('void') -- also accepts just void )), spaces, lit(')'), - any_amount(concat( -- optional attributes + any_amount(concat( -- optional attributes spaces, lit('FUNC_'), any_amount(aw), - one_or_no(concat( -- attribute argument + one_or_no(concat( -- attribute argument spaces, lit('('), - any_amount(concat( - neg_look_ahead(lit(')')), - any_character - )), + any_amount(concat(neg_look_ahead(lit(')')), any_character)), lit(')') )) )), - look_ahead(concat( -- definition must be followed by "{" + look_ahead(concat( -- definition must be followed by "{" spaces, lit('{') )) @@ -164,7 +132,7 @@ if fname == '--help' then print([[ Usage: - gendeclarations.lua definitions.c static.h non-static.h definitions.i + gen_declarations.lua definitions.c static.h non-static.h definitions.i Generates declarations for a C file definitions.c, putting declarations for static functions into static.h and declarations for non-static functions into @@ -198,21 +166,13 @@ Additionally uses the following environment variables: end local preproc_f = io.open(preproc_fname) -local text = preproc_f:read("*all") +local text = preproc_f:read('*all') preproc_f:close() - -local header = [[ +local non_static = [[ #define DEFINE_FUNC_ATTRIBUTES #include "nvim/func_attr.h" #undef DEFINE_FUNC_ATTRIBUTES -]] - -local footer = [[ -#include "nvim/func_attr.h" -]] - -local non_static = header .. [[ #ifndef DLLEXPORT # ifdef MSWIN # define DLLEXPORT __declspec(dllexport) @@ -222,7 +182,20 @@ local non_static = header .. [[ #endif ]] -local static = header +local static = [[ +#define DEFINE_FUNC_ATTRIBUTES +#include "nvim/func_attr.h" +#undef DEFINE_FUNC_ATTRIBUTES +]] + +local non_static_footer = [[ +#include "nvim/func_attr.h" +]] + +local static_footer = [[ +#define DEFINE_EMPTY_ATTRIBUTES +#include "nvim/func_attr.h" // IWYU pragma: export +]] if fname:find('.*/src/nvim/.*%.c$') then -- Add an IWYU pragma comment if the corresponding .h file exists. @@ -234,6 +207,22 @@ if fname:find('.*/src/nvim/.*%.c$') then // IWYU pragma: private, include "%s" ]]):format(header_fname:gsub('.*/src/nvim/', 'nvim/')) .. non_static end +elseif non_static_fname:find('/include/api/private/dispatch_wrappers%.h%.generated%.h$') then + non_static = [[ +// IWYU pragma: private, include "nvim/api/private/dispatch.h" +]] .. non_static +elseif non_static_fname:find('/include/ui_events_call%.h%.generated%.h$') then + non_static = [[ +// IWYU pragma: private, include "nvim/ui.h" +]] .. non_static +elseif non_static_fname:find('/include/ui_events_client%.h%.generated%.h$') then + non_static = [[ +// IWYU pragma: private, include "nvim/ui_client.h" +]] .. non_static +elseif non_static_fname:find('/include/ui_events_remote%.h%.generated%.h$') then + non_static = [[ +// IWYU pragma: private, include "nvim/api/ui.h" +]] .. non_static end local filepattern = '^#%a* (%d+) "([^"]-)/?([^"/]+)"' @@ -283,8 +272,7 @@ while init ~= nil do declaration = declaration .. ';' if os.getenv('NVIM_GEN_DECLARATIONS_LINE_NUMBERS') == '1' then - declaration = declaration .. (' // %s/%s:%u'):format( - curdir, curfile, declline) + declaration = declaration .. (' // %s/%s:%u'):format(curdir, curfile, declline) end declaration = declaration .. '\n' if declaration:sub(1, 6) == 'static' then @@ -307,8 +295,8 @@ while init ~= nil do end end -non_static = non_static .. footer -static = static .. footer +non_static = non_static .. non_static_footer +static = static .. static_footer local F F = io.open(static_fname, 'w') |