Make sure that calling conventions within the argument list do not break parsing (Fixes #51)

This commit is contained in:
Mark VanderVoord
2026-06-26 14:44:57 -04:00
parent dc34a9000c
commit e851a39d58
2 changed files with 41 additions and 1 deletions
+14 -1
View File
@@ -598,11 +598,24 @@ class CMockHeaderParser
funcname = Regexp.last_match(2).strip
funcargs = Regexp.last_match(3).strip
funconst = ''
funcdecl = ''
if funcname.include? 'const'
funcname.gsub!('const', '').strip!
funconst = 'const '
end
parse_project[:typedefs] << "typedef #{funcret}(*#{functype})(#{funcargs});"
# Extract any calling convention from the return type (it belongs in the function pointer declaration)
@c_calling_conventions.each do |cc|
next unless funcret.include?(cc)
funcret = funcret.gsub(cc, '').strip
funcdecl = cc
break
end
parse_project[:typedefs] << if funcdecl.empty?
"typedef #{funcret}(*#{functype})(#{funcargs});"
else
"typedef #{funcret}(#{funcdecl} *#{functype})(#{funcargs});"
end
funcname = "cmock_arg#{c += 1}" if funcname.empty?
"#{functype} #{funconst}#{funcname}"
end
+27
View File
@@ -1515,6 +1515,33 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
assert_equal(typedefs, result[:typedefs])
end
it "extract functions using a function pointer with shorthand notation and a calling convention" do
source = "void FunkyTurkey(void __stdcall * func_ptr(int arg0))"
expected = [{ :var_arg=>nil,
:return=>{ :type => "void",
:name => 'cmock_to_return',
:ptr? => false,
:const? => false,
:const_ptr? => false,
:str => "void cmock_to_return",
:void? => true
},
:name=>"FunkyTurkey",
:unscoped_name=>"FunkyTurkey",
:namespace=>[],
:class=>nil,
:modifier=>"",
:contains_ptr? => false,
:args=>[ {:type=>"cmock_module_func_ptr1", :name=>"func_ptr", :ptr? => false, :string? => false, :const? => false, :const_ptr? => false}
],
:args_string=>"cmock_module_func_ptr1 func_ptr",
:args_call=>"func_ptr" }]
typedefs = ["typedef void *(__stdcall *cmock_module_func_ptr1)(int arg0);"]
result = @parser.parse("module", source)
assert_equal(expected, result[:functions])
assert_equal(typedefs, result[:typedefs])
end
it "extract functions containing a function pointer with a void" do
source = "void FunkyTurkey(void (*func_ptr)(void))"
expected = [{ :var_arg=>nil,