- Just looking for static|inline in the gsub is a bit too aggressive.
Instead, look for the "static inline" and parse it:
- Everything before the match should just be copied, we don't want
to touch anything but the inline functions.
- Remove the implementation of the inline function (this is enclosed
in square brackets) and replace it with ";" to complete the
transformation to normal/non-inline function.
- Copy everything after the inline function implementation
Repeat the above step until we can't find "static inline" anymore
- To remove the inline implementation,
we count the number of square-bracket 'levels' in the inline function
and remove every pair. This ensures that constructs like:
inline void func(void) {
if (...) {
//NOP
}
else
{
//NOP
}
}
will not end up leaving the 'else' keyword unremoved:
inline void func(void);
else
If we count the number of levels, we don't end up in this scenario
since we remove 3 'pairs', the if-one, the else-one and finally the
main body.
- This way, @normalized_source will always be defined, which it should
because we are referencing it a few lines down, thanks to
@mvandervoord for the suggestion
- This prevents changing the original mock file that is generated,
it thinks it includes the 'original' header file that is being
mocked,
but if we place our newly generated header file in the same
directory as the mock_<header_file>.h, it will include our newly
generated header file.
- normalize_source() will convert the header-to-mock.
It will look for the inline function definitions and transform them
into function declarations for non-inline functions.
- treat_externs only has effect on "extern", not "inline" anymore
- when treat_inline = :include, we remove the "inline" so that the inline functions become 'normal' functions
- they are handled as as usual and will be mocked
- Add tests to check inline functions are not deleted when treat_inline=:include (and thus mocked)
We should be able to allocate up to CMock_Guts_MemBytesFree() minus
CMOCK_MEM_INDEX_SIZE. An incorrect less-than-or-equal prevented
allocating the very last byte.
Set CMock_Guts_FreePtr to CMOCK_MEM_ALIGN_SIZE initially (the same
value it is reset to by CMock_Guts_MemFreeAll(). This makes sure
that the value returned by CMock_Guts_MemBytesUsed() is 0 initially
and not a negative value.
The value of CMOCK_MEM_ALIGN changed depending on whether unity.h
or cmock.h was included first. Since cmock_internals.h uses
features from unity.h, it should include unity.h.