Skip to content

How can I remove a macro from a typedef using :strippables: regex? #515

@parmi93

Description

@parmi93
// Works for GCC and Clang compiler
#if defined(__GNUC__) || defined(__clang__)
#define PACK(...) __VA_ARGS__ __attribute__((__packed__))                
#endif

// Works for Microsoft compilers
#if _MSC_VER
#define PACK(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
#endif

typedef PACK(struct {
    int a;
    int b;
}) my_struct;

PACK(struct my_struct2 {
    int a;
    int b;
});

typedef PACK(enum {
    ENUM1 = 1,
    ENUM2,
}) my_enum;

PACK(enum my_enum2 {
    ENUM_1 = 1,
    ENUM_2,
});

CMock can't mock files that contain code wrapped in macros, so I'm looking for a regex that can help me remove the PACK() macro during mocking.
I tried to use PACK\s*\(\s*((?:.|\n)*?)\s*\) regex in the project.yml as follow, but it doesn't work:

:cmock:
  :strippables:  
    - '(?:__attribute__\s*\([ (]*.*?[ )]*\)+)'
    - '(PACK\s*\(\s*((?:.|\n)*?)\s*\))'

(I'm not sure if it's allowed to enter multiple regular expressions like I did above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions