diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 2c50c52..f7971ce 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -66,6 +66,9 @@ class CMockHeaderParser # remove assembler pragma sections source.gsub!(/^\s*#\s*pragma\s+asm\s+.*?#\s*pragma\s+endasm/m, '') + # remove gcc's __attribute__ tags + source.gsub(/__attrbute__\s*\(\(\.*\)\)/, '') + # remove preprocessor statements and extern "C" source.gsub!(/^\s*#.*/, '') source.gsub!(/extern\s+\"C\"\s+\{/, '') diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 10af1cc..e0d49b7 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -85,6 +85,26 @@ class CMockHeaderParserTest < Test::Unit::TestCase end + should "remove gcc's function __attribute__'s" do + source = + "void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)));\n" + + "void\n" + + " my_realloc(void*, size_t) __attribute__((alloc_size(2)));\n" + + "extern int\n" + + " my_printf (void *my_object, const char *my_format, ...)\n" + + " __attribute__ ((format (printf, 2, 3)));\n" + + " void __attribute__ ((interrupt)) universal_handler ();\n" + + expected = + [ + "void* my_calloc(size_t, size_t)", + "void my_realloc(void*, size_t)", + "void universal_handler()" + ] + + assert_equal(expected, @parser.import_source(source)) + end + should "remove preprocessor directives" do source = "#when stuff_happens\n" +