diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 10c9ed5..ef789f8 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -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 diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 18048f5..56f5667 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -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,