diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 4877172..3aaf9a1 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -156,6 +156,16 @@ class CMockHeaderParser puts inline_function_match.post_match puts + # Determine if we are dealing with a declaration or a function definition + first_open_bracket = inline_function_match.post_match.index("{") + first_semicolon = inline_function_match.post_match.index(";") + + if first_semicolon < first_open_bracket + puts "DECLARATION, IGNORE" + source = inline_function_match.pre_match + inline_function_match.post_match + next + end + total_pairs_to_remove = count_number_of_pairs_of_braces_in_function(inline_function_match.post_match) if 0 == total_pairs_to_remove # Bad source? diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 2a567af..fc8fdaa 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -2083,30 +2083,25 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(expected, @parser.parse("module", source)[:functions]) end - it "Transform inline functions takes user provided patterns into account" do + it "Transform inline functions does not touch inline function declarations" do source = + "static inline int dummy_func_decl(int a, char b, float c);\n" + # First declaration user pattern "static inline int staticinlinefunc(struct my_struct *s)\n" + # 'normal' inline pattern "{\n" + - " return s->a;\n" + + " return dummy_func_decl(1, 1, 1);\n" + "}\n" + - "static __inline__ int dummy_func_2(int a, char b, float c) {\n" + # First user pattern - " c += 3.14;\n" + - " b -= 32;\n" + - " return a + (int)(b) + (int)c;\n" + - "}\n" + - "static __inline__ __attribute__ ((always_inline)) uint16_t attributealwaysinlinefuncname(void) {\n" + # Second user pattern - " return (uint16_t)(42);\n" + + "static inline int dummy_func_decl(int a, char b, float c) {\n" + # Second user pattern + " return 42;\n" + "}\n" + "\n" expected = + "int dummy_func_decl(int a, char b, float c);\n" + "int staticinlinefunc(struct my_struct *s);\n" + - "int dummy_func_2(int a, char b, float c);\n" + - "uint16_t attributealwaysinlinefuncname(void);\n" + + "int dummy_func_decl(int a, char b, float c);\n" + "\n" @parser.treat_inlines = :include - @parser.inline_function_patterns = ['static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__', 'static inline'] assert_equal(expected, @parser.transform_inline_functions(source)) end