diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index ebdb3b2..2b7e16f 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -90,6 +90,9 @@ class CMockHeaderParser source.gsub!(/\)(\w)/, ') \1') # add space between parenthese and alphanumeric source.gsub!(/(^|\W+)(?:#{@c_strippables.join('|')})(?=$|\W+)/,'\1') unless @c_strippables.empty? # remove known attributes slated to be stripped + #scan standalone function pointers and remove them, because they can just be ignored + source.gsub!(/\w+\s*\(\s*\*\s*\w+\s*\)\s*\([^)]*\)\s*;/,';') + #scan for functions which return function pointers, because they are a pain source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |m| functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}" diff --git a/test/system/test_compilation/parsing.h b/test/system/test_compilation/parsing.h index a9f7548..aaf5d47 100644 --- a/test/system/test_compilation/parsing.h +++ b/test/system/test_compilation/parsing.h @@ -50,3 +50,14 @@ extern unsigned long int incredible_descriptors(register const unsigned short a) int32_t example_c99_type(int32_t param1); void I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void)); + +/* these are function pointers, not function declarations USING a function pointer, and so should NOT get mocked */ +int (* func_pointer)(void); +extern int (*another_func_pointer)(unsigned int argument); +struct struct_to_be_ignored { + union { + int i32; + void *p; + } variant; + void (*a_function_pointer_in_a_struct)(void *); +}; diff --git a/test/system/test_interactions/function_pointer_handling.yml b/test/system/test_interactions/function_pointer_handling.yml index 9462bdd..4119770 100644 --- a/test/system/test_interactions/function_pointer_handling.yml +++ b/test/system/test_interactions/function_pointer_handling.yml @@ -15,11 +15,11 @@ void takes_const_function_ptr( unsigned int (* const)(int, char) ); unsigned short (*returns_function_ptr( const char op_code ))( int, long int ); - :source: + :source: :header: | void exercise_function_pointer_param(void); unsigned short (*exercise_function_pointer_return( const char op_code ))( int, long int ); - + // functions for function pointer tests unsigned int dummy_function1(int a, char b); unsigned short dummy_function2(int a, long int b); @@ -28,7 +28,7 @@ /* * functions used in tests */ - + unsigned int dummy_function1(int a, char b) { // prevent compiler warnings by using everything