Hide macro replacement

This commit is contained in:
Jonathan Müller 2017-07-17 16:24:21 +02:00
commit 38dd1c9d18
3 changed files with 11 additions and 2 deletions

View file

@ -160,6 +160,7 @@ namespace cppast
exclude_return, //< Exclude the return type of a function entity. exclude_return, //< Exclude the return type of a function entity.
exclude_target, //< Exclude the underlying entity of an alias (e.g. typedef). exclude_target, //< Exclude the underlying entity of an alias (e.g. typedef).
declaration, //< Only write declaration. declaration, //< Only write declaration.
/// For a macro, it won't show the replacement if this flag is set
_flag_set_size, //< \exclude _flag_set_size, //< \exclude
}; };

View file

@ -92,7 +92,7 @@ namespace
output << preprocessor_token("(") << bracket_ws output << preprocessor_token("(") << bracket_ws
<< preprocessor_token(def.parameters().value()) << bracket_ws << preprocessor_token(def.parameters().value()) << bracket_ws
<< preprocessor_token(")"); << preprocessor_token(")");
if (!def.replacement().empty()) if (!def.replacement().empty() && !output.options().is_set(code_generator::declaration))
output << whitespace << preprocessor_token(def.replacement()) << newl; output << whitespace << preprocessor_token(def.replacement()) << newl;
else else
output << newl; output << newl;

View file

@ -147,7 +147,6 @@ struct foo{
} }
SECTION("exclude") SECTION("exclude")
{ {
// exclude all entities starting with `e`
class exclude_generator : public test_generator class exclude_generator : public test_generator
{ {
public: public:
@ -157,7 +156,12 @@ struct foo{
generation_options do_get_options(const cpp_entity& e) override generation_options do_get_options(const cpp_entity& e) override
{ {
if (e.name().front() == 'e') if (e.name().front() == 'e')
// exclude all entities starting with `e`
// add declaration flag to detect check for equality
return code_generator::exclude | code_generator::declaration; return code_generator::exclude | code_generator::declaration;
else if (e.name() == "FOO")
// don't show macro replacement
return code_generator::declaration;
return {}; return {};
} }
}; };
@ -167,6 +171,8 @@ void e();
void func(int a, int e, int c); void func(int a, int e, int c);
#define FOO hidden
template <typename e1, typename e2> template <typename e1, typename e2>
void tfunc(int a); void tfunc(int a);
@ -196,6 +202,8 @@ private:
auto synopsis = R"(void func(int a,int c); auto synopsis = R"(void func(int a,int c);
#define FOO
void tfunc(int a); void tfunc(int a);
struct base{ struct base{