diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 260b73c..7fdce67 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -120,6 +120,10 @@ class CMockHeaderParser # let's clean up the encoding in case they've done anything weird with the characters we might find source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil) + # smush multiline macros into single line (checking for continuation character at end of line '\') + # If the user uses a define to declare an inline function, it's easier to remove later + source.gsub!(/\s*\\\s*/m, ' ') + # - Just looking for static|inline in the gsub is a bit too aggressive (functions that are named like this, ...), so we try to be a bit smarter # Instead, look for "static inline" and parse it: # - Everything before the match should just be copied, we don't want @@ -156,6 +160,16 @@ class CMockHeaderParser puts inline_function_match.post_match puts + # Determine if we are dealing with a user defined macro to declare inline functions + if /(#define\s*)\z/ === inline_function_match.pre_match + puts "DEFINE, REMOVE" + stripped_pre_match = inline_function_match.pre_match.sub(/(#define\s*)\z/,'') + stripped_post_match = inline_function_match.post_match.sub(/\A(.*[\n]?)/,'') + source = stripped_pre_match + stripped_post_match + puts source + next + end + # 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(";") diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index de12202..9e22b84 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -2154,4 +2154,37 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(expected, @parser.transform_inline_functions(source)) end + it "Transform inline functions TODO" do + source = + "#define INLINE static __inline__ __attribute__ ((always_inline))\n" + + "#define INLINE_TWO \\\nstatic\\\ninline\n" + + "INLINE uint16_t _somefunc (uint32_t a)\n" + + "{\n" + + " return _someotherfunc (a);\n" + + "}\n" + + "static __inline__ uint16_t _somefunc_0 (uint32_t a)\n" + + "{\n" + + " return (uint16_t) a;\n" + + "}\n" + + "static __inline__ __attribute__ \(\(always_inline\)\) uint16_t _somefunc_1 (uint32_t a)\n" + + "{\n" + + " return (uint16_t) a;\n" + + "}\n" + + "INLINE_TWO uint16_t _somefunc_2(uint32_t a)\n" + + "{\n" + + " return (uint16_t) a;\n" + + "}\n" + + "#define INLINE_THREE \\\nstatic\\\ninline" + + expected = + "uint16_t _somefunc (uint32_t a);\n" + + "uint16_t _somefunc_0 (uint32_t a);\n" + + "uint16_t _somefunc_1 (uint32_t a);\n" + + "uint16_t _somefunc_2(uint32_t a);\n" + + @parser.treat_inlines = :include + @parser.inline_function_patterns = ['INLINE_THREE', 'INLINE_TWO', 'INLINE', 'static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__'] + assert_equal(expected, @parser.transform_inline_functions(source)) + end + end