Skip to content

Commit 379a9a8

Browse files
authored
Merge pull request #420 from ThrowTheSwitch/bugfixes/batch1
Collection of Quick Fixes
2 parents bf37ffa + a58808d commit 379a9a8

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

lib/cmock_config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CMockConfig
1515
:weak => '',
1616
:subdir => nil,
1717
:plugins => [],
18-
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
18+
:strippables => ['(?:__attribute__\s*\([ (]*.*?[ )]*\)+)'],
1919
:attributes => %w[__ramfunc __irq __fiq register extern],
2020
:c_calling_conventions => %w[__stdcall __cdecl __fastcall],
2121
:enforce_strict_ordering => false,
@@ -50,7 +50,7 @@ class CMockConfig
5050
# - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff),
5151
# so we check for word boundaries when searching for them
5252
# - We first remove "static inline" combinations and boil down to single inline or static statements
53-
: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)
53+
: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)
5454
}.freeze
5555

5656
def initialize(options = nil)

lib/cmock_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(config, file_writer, utils, plugins)
2222
@exclude_setjmp_h = @config.exclude_setjmp_h
2323
@subdir = @config.subdir
2424

25-
@includes_h_pre_orig_header = (@config.includes || @config.includes_h_pre_orig_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
25+
@includes_h_pre_orig_header = ((@config.includes || []) + (@config.includes_h_pre_orig_header || [])).uniq.map { |h| h =~ /</ ? h : "\"#{h}\"" }
2626
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
2727
@includes_c_pre_header = (@config.includes_c_pre_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
2828
@includes_c_post_header = (@config.includes_c_post_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }

lib/cmock_header_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(cfg)
1414
@c_calling_conventions = cfg.c_calling_conventions.uniq
1515
@treat_as_array = cfg.treat_as_array
1616
@treat_as_void = (['void'] + cfg.treat_as_void).uniq
17-
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]+??)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)'
17+
@function_declaration_parse_base_match = '([\w\s\*\(\),\[\]]*?\w[\w\s\*\(\),\[\]]*?)\(([\w\s\*\(\),\.\[\]+\-\/]*)\)'
1818
@declaration_parse_matcher = /#{@function_declaration_parse_base_match}$/m
1919
@standards = (%w[int short char long unsigned signed] + cfg.treat_as.keys).uniq
2020
@array_size_name = cfg.array_size_name

test/system/test_compilation/parsing.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ typedef struct _POINT_T
1616
int y;
1717
} POINT_T;
1818

19-
// typedef edge case;
20-
// not ANSI C but it has been done and will break cmock if not handled
19+
/* typedef edge case;
20+
not ANSI C but it has been done and will break cmock if not handled */
2121
typedef void VOID_TYPE_CRAZINESS;
2222

2323
/* fun parsing & mock generation cases */
@@ -36,6 +36,9 @@ char
3636
int a,
3737
unsigned int b);
3838

39+
/* this isn't a function, despite the parenthesis */
40+
static const unsigned int foo = (1);
41+
3942
U16 *ptr_return1(int a);
4043
U16* ptr_return2(int a);
4144
U16 * ptr_return3(int a);

test/unit/cmock_generator_main_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def mock_implementation(name, args)
4848
@config.expect :enforce_strict_ordering, nil
4949
@config.expect :framework, :unity
5050
@config.expect :includes, ["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"]
51-
#@config.expect :includes_h_pre_orig_header, nil #not called because includes called
51+
@config.expect :includes_h_pre_orig_header, nil
5252
@config.expect :includes_h_post_orig_header, nil
5353
@config.expect :includes_c_pre_header, nil
5454
@config.expect :includes_c_post_header, nil

test/unit/cmock_header_parser_test.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
" my_realloc(void*, size_t) __attribute__((alloc_size(2)));\n" +
122122
"extern int\n" +
123123
" my_printf (void *my_object, const char *my_format, ...)\n" +
124-
" __attribute__ ((format (printf, 2, 3)));\n" +
124+
" __attribute__ ( (format (printf, 2, 3)) );\n" +
125125
" void __attribute__ ((interrupt)) universal_handler ();\n"
126126

127127
expected =
@@ -2755,6 +2755,28 @@ class Classy {
27552755
assert_equal(expected, @parser.transform_inline_functions(source))
27562756
end
27572757

2758+
it "Transform inline functions using gnu attribute notation" do
2759+
source =
2760+
"static __inline__ __attribute__ ((always_inline)) uint16_t _somefunc (uint32_t a)\n" +
2761+
"{\n" +
2762+
" return _someotherfunc (a);\n" +
2763+
"}\n" +
2764+
"static __attribute__ (( always_inline )) uint16_t _somefunc_0 (uint32_t a)\n" +
2765+
"{\n" +
2766+
" return (uint16_t) a;\n" +
2767+
"}\n" +
2768+
"\n"
2769+
2770+
expected =
2771+
"uint16_t _somefunc (uint32_t a);\n" +
2772+
"uint16_t _somefunc_0 (uint32_t a);\n" +
2773+
"\n"
2774+
2775+
@parser.treat_inlines = :include
2776+
@parser.inline_function_patterns = ['(?:static\s*)?(?:__inline__)?__attribute__\s*\([ (]*always_inline[ )]*\)', 'static __inline__']
2777+
assert_equal(expected, @parser.transform_inline_functions(source))
2778+
end
2779+
27582780
it "Transform inline functions takes user provided patterns into account" do
27592781
source =
27602782
"static __inline__ __attribute__ ((always_inline)) uint16_t _somefunc (uint32_t a)\n" +

0 commit comments

Comments
 (0)