(c) Add support for functions that return pointers

This commit is contained in:
Daniel Mathiot
2021-08-28 15:28:14 +02:00
parent c9ea7ee461
commit 460d022cc1

View File

@@ -1,10 +1,4 @@
local c_function_extractor = function(node) local c_params = {
local tree = {
{
retrieve = "first",
node_type = "function_declarator",
subtree = {
{
retrieve = "first", retrieve = "first",
node_type = "parameter_list", node_type = "parameter_list",
subtree = { subtree = {
@@ -16,8 +10,20 @@ local c_function_extractor = function(node)
}, },
}, },
}, },
}
local c_function_extractor = function(node)
local tree = {
{
retrieve = "first",
node_type = "function_declarator",
subtree = {
c_params,
}, },
}, },
{
retrieve = "first_recursive",
node_type = "function_declarator",
extract = true
}, },
{ {
retrieve = "first", retrieve = "first",
@@ -26,11 +32,19 @@ local c_function_extractor = function(node)
{ retrieve = "first", node_type = "return_statement", extract = true }, { retrieve = "first", node_type = "return_statement", extract = true },
}, },
}, },
c_params
} }
local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree)
local res = neogen.utilities.extractors:extract_from_matched(nodes) local res = neogen.utilities.extractors:extract_from_matched(nodes)
if nodes.function_declarator then
local subnodes = neogen.utilities.nodes:matching_nodes_from(nodes.function_declarator[1], tree)
local subres = neogen.utilities.extractors:extract_from_matched(subnodes)
res = vim.tbl_deep_extend("keep", res, subres)
end
return { return {
parameters = res.identifier, parameters = res.identifier,
return_statement = res.return_statement, return_statement = res.return_statement,