(c/cpp) Add return when void (#22)

This commit is contained in:
danymat
2021-11-10 11:39:39 +01:00
parent c9763c65b2
commit 2cc90eb8d5

View File

@@ -73,7 +73,7 @@ local c_function_extractor = function(node)
-- function implementation -- function implementation
return res.return_statement return res.return_statement
elseif res.function_declarator and res.primitive_type then elseif res.function_declarator and res.primitive_type then
if res.primitive_type[1] ~= "void" or res.pointer_declarator then if res.primitive_type or res.pointer_declarator then
-- function prototype -- function prototype
return res.primitive_type return res.primitive_type
end end
@@ -91,7 +91,13 @@ end
return { return {
parent = { parent = {
func = { "function_declaration", "function_definition", "declaration", "field_declaration", "template_declaration" }, func = {
"function_declaration",
"function_definition",
"declaration",
"field_declaration",
"template_declaration",
},
}, },
data = { data = {
@@ -104,22 +110,22 @@ return {
}, },
}, },
locator = function(node_info, nodes_to_match) locator = function(node_info, nodes_to_match)
local result = neogen.default_locator(node_info, nodes_to_match) local result = neogen.default_locator(node_info, nodes_to_match)
if not result then if not result then
return nil return nil
end end
-- if the function happens to be a function template we want to place -- if the function happens to be a function template we want to place
-- the annotation before the template statement and extract the -- the annotation before the template statement and extract the
-- template parameters names as well -- template parameters names as well
if node_info.current:parent() == nil then if node_info.current:parent() == nil then
return result return result
end end
if node_info.current:parent():type() == "template_declaration" then if node_info.current:parent():type() == "template_declaration" then
return result:parent() return result:parent()
end end
return result return result
end, end,
-- Use default granulator and generator -- Use default granulator and generator
granulator = nil, granulator = nil,