Keep function pointers from choking CMock (fixes issues #102, #222, #226)

This commit is contained in:
Mark VanderVoord
2019-07-09 22:23:40 -04:00
parent 4c6fe35bbf
commit 12c74c0349
3 changed files with 17 additions and 3 deletions
+3
View File
@@ -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}"
+11
View File
@@ -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 *);
};
@@ -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