From 7100ef0e6227d0234650bde8bae9e410bcb7a0a0 Mon Sep 17 00:00:00 2001 From: Ivan Siutsou Date: Sun, 7 Nov 2021 21:47:51 +0200 Subject: [PATCH] Fix parsing of calling conventions in function pointers --- lib/cmock_header_parser.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 9730bf4..e9a7302 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -484,17 +484,18 @@ class CMockHeaderParser arg_list.gsub!(/\*(\w)/, '* \1') # scan argument list for function pointers and replace them with custom types - arg_list.gsub!(/([\w\s\*]+)\(+\s*\*[\*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m| + arg_list.gsub!(/([\w\s\*]+)\(+([\w\s]*)\*[\*\s]*([\w\s]*)\s*\)+\s*\(((?:[\w\s\*]*,?)*)\s*\)*/) do |_m| functype = "cmock_#{parse_project[:module_name]}_func_ptr#{parse_project[:typedefs].size + 1}" funcret = Regexp.last_match(1).strip - funcname = Regexp.last_match(2).strip - funcargs = Regexp.last_match(3).strip + funcdecl = Regexp.last_match(2).strip + funcname = Regexp.last_match(3).strip + funcargs = Regexp.last_match(4).strip funconst = '' if funcname.include? 'const' funcname.gsub!('const', '').strip! funconst = 'const ' end - parse_project[:typedefs] << "typedef #{funcret}(*#{functype})(#{funcargs});" + parse_project[:typedefs] << "typedef #{funcret}(#{funcdecl} *#{functype})(#{funcargs});" funcname = "cmock_arg#{c += 1}" if funcname.empty? "#{functype} #{funconst}#{funcname}" end