From 91bb49c4a8e941d40a6212da4aac8b8fbb7024d5 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 9 Jan 2023 14:50:56 -0500 Subject: [PATCH 1/3] Fix same bug as PR #354, but as one line. --- lib/cmock_generator.rb | 2 +- test/unit/cmock_generator_main_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 826bf8b..c3896df 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -22,7 +22,7 @@ class CMockGenerator @exclude_setjmp_h = @config.exclude_setjmp_h @subdir = @config.subdir - @includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map { |h| h =~ / Date: Tue, 10 Jan 2023 15:35:54 -0500 Subject: [PATCH 2/3] Fix bug in parenthetical statements being misinterpreted as functions. (Issue #414) --- lib/cmock_header_parser.rb | 2 +- test/system/test_compilation/parsing.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 8dd1f46..491e467 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -14,7 +14,7 @@ class CMockHeaderParser @c_calling_conventions = cfg.c_calling_conventions.uniq @treat_as_array = cfg.treat_as_array @treat_as_void = (['void'] + cfg.treat_as_void).uniq - @function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)' + @function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]*?\w[\w\s\*\(\),\[\]]*?)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)' @declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m @standards = (%w[int short char long unsigned signed] + cfg.treat_as.keys).uniq @array_size_name = cfg.array_size_name diff --git a/test/system/test_compilation/parsing.h b/test/system/test_compilation/parsing.h index d4734f4..1c4bcd1 100644 --- a/test/system/test_compilation/parsing.h +++ b/test/system/test_compilation/parsing.h @@ -16,8 +16,8 @@ typedef struct _POINT_T int y; } POINT_T; -// typedef edge case; -// not ANSI C but it has been done and will break cmock if not handled +/* typedef edge case; + not ANSI C but it has been done and will break cmock if not handled */ typedef void VOID_TYPE_CRAZINESS; /* fun parsing & mock generation cases */ @@ -36,6 +36,9 @@ char int a, unsigned int b); +/* this isn't a function, despite the parenthesis */ +static const unsigned int foo = (1); + U16 *ptr_return1(int a); U16* ptr_return2(int a); U16 * ptr_return3(int a); From a58808d4246fe4e06afcc07d902c5a9bd5706515 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 11 Jan 2023 15:43:48 -0500 Subject: [PATCH 3/3] Fixed bug #402, getting confused with __attribute__ directives with spacing. --- lib/cmock_config.rb | 4 ++-- test/unit/cmock_header_parser_test.rb | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 716a0c5..c7db945 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -15,7 +15,7 @@ class CMockConfig :weak => '', :subdir => nil, :plugins => [], - :strippables => ['(?:__attribute__\s*\(+.*?\)+)'], + :strippables => ['(?:__attribute__\s*\([ (]*.*?[ )]*\)+)'], :attributes => %w[__ramfunc __irq __fiq register extern], :c_calling_conventions => %w[__stdcall __cdecl __fastcall], :enforce_strict_ordering => false, @@ -50,7 +50,7 @@ class CMockConfig # - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff), # so we check for word boundaries when searching for them # - We first remove "static inline" combinations and boil down to single inline or static statements - :inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*'] # Last part (\s*) is just to remove whitespaces (only to prettify the output) + :inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*', '(?:static\s*)?(?:__inline__)?__attribute__\s*\([ (]*always_inline[ )]*\)', 'static __inline__'] # Last part (\s*) is just to remove whitespaces (only to prettify the output) }.freeze def initialize(options = nil) diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index eedc0cb..3437de3 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -121,7 +121,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do " 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" + + " __attribute__ ( (format (printf, 2, 3)) );\n" + " void __attribute__ ((interrupt)) universal_handler ();\n" expected = @@ -2755,6 +2755,28 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(expected, @parser.transform_inline_functions(source)) end + it "Transform inline functions using gnu attribute notation" do + source = + "static __inline__ __attribute__ ((always_inline)) uint16_t _somefunc (uint32_t a)\n" + + "{\n" + + " return _someotherfunc (a);\n" + + "}\n" + + "static __attribute__ (( always_inline )) uint16_t _somefunc_0 (uint32_t a)\n" + + "{\n" + + " return (uint16_t) a;\n" + + "}\n" + + "\n" + + expected = + "uint16_t _somefunc (uint32_t a);\n" + + "uint16_t _somefunc_0 (uint32_t a);\n" + + "\n" + + @parser.treat_inlines = :include + @parser.inline_function_patterns = ['(?:static\s*)?(?:__inline__)?__attribute__\s*\([ (]*always_inline[ )]*\)', 'static __inline__'] + assert_equal(expected, @parser.transform_inline_functions(source)) + end + it "Transform inline functions takes user provided patterns into account" do source = "static __inline__ __attribute__ ((always_inline)) uint16_t _somefunc (uint32_t a)\n" +