From e2cc43488308d160e1e96d21ca22b73abae6ad46 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Mon, 28 May 2012 17:24:22 +0000 Subject: [PATCH] - strips out gcc's __attribute__ tags git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@223 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_header_parser.rb | 3 +++ test/unit/cmock_header_parser_test.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) 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" +