Handle user defined inline macro's

First squash all multiline macro's, it makes parsing easier. Otherwise
the regex to remove the macro would become more comples if we have to
deal with newlines etc.

When we have a match, we check if the last line in the pre_match is
the beginning of a macro declaration.
If it is, we remove the beginning of this macro
declaration (#define<space>) and remove the body of the macro from the
post_match, which is basically everything until the next newline.
There is a possible edge case (pretty unlikely but still):
if there is no newline in the post_match, meaning it is a macro at the
end of the line, we should delete it as well, hence the '[\n]?' in the
post match regex.
This commit is contained in:
laurensmiers
2020-01-14 22:18:17 +01:00
parent 3254aef5e5
commit cfe1b4ef3d
2 changed files with 47 additions and 0 deletions
+33
View File
@@ -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