Add a couple of code gnerator flags
This commit is contained in:
commit
ad2d0f34f9
3 changed files with 30 additions and 9 deletions
|
|
@ -159,7 +159,9 @@ namespace cppast
|
|||
exclude, //< Exclude the entire entity.
|
||||
exclude_return, //< Exclude the return type of a function entity.
|
||||
exclude_target, //< Exclude the underlying entity of an alias (e.g. typedef).
|
||||
declaration, //< Only write declaration.
|
||||
exclude_noexcept_condition, //< Exclude the condition of a noexcept.`
|
||||
declaration, //< Only write declaration.
|
||||
/// For a macro, it won't show the replacement if this flag is set
|
||||
_flag_set_size, //< \exclude
|
||||
};
|
||||
|
||||
|
|
@ -193,7 +195,7 @@ namespace cppast
|
|||
/// the other functions have no effects.
|
||||
explicit operator bool() const noexcept
|
||||
{
|
||||
return options_ != exclude;
|
||||
return !options_.is_set(exclude);
|
||||
}
|
||||
|
||||
/// \returns The generation options.
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ namespace
|
|||
output << preprocessor_token("(") << bracket_ws
|
||||
<< preprocessor_token(def.parameters().value()) << bracket_ws
|
||||
<< preprocessor_token(")");
|
||||
if (!def.replacement().empty())
|
||||
if (!def.replacement().empty() && !output.options().is_set(code_generator::declaration))
|
||||
output << whitespace << preprocessor_token(def.replacement()) << newl;
|
||||
else
|
||||
output << newl;
|
||||
|
|
@ -500,7 +500,14 @@ namespace
|
|||
else
|
||||
{
|
||||
output << keyword("noexcept") << punctuation("(") << bracket_ws;
|
||||
detail::write_expression(output, cond);
|
||||
// update check when expression gets exposed
|
||||
if (cond.kind() == cpp_expression_kind::unexposed_t
|
||||
&& static_cast<const cpp_unexposed_expression&>(cond).expression() == "false")
|
||||
output << keyword("false");
|
||||
else if (output.options().is_set(code_generator::exclude_noexcept_condition))
|
||||
output.excluded(base);
|
||||
else
|
||||
detail::write_expression(output, cond);
|
||||
output << bracket_ws << punctuation(")");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,6 @@ struct foo{
|
|||
}
|
||||
SECTION("exclude")
|
||||
{
|
||||
// exclude all entities starting with `e`
|
||||
class exclude_generator : public test_generator
|
||||
{
|
||||
public:
|
||||
|
|
@ -157,8 +156,13 @@ struct foo{
|
|||
generation_options do_get_options(const cpp_entity& e) override
|
||||
{
|
||||
if (e.name().front() == 'e')
|
||||
return code_generator::exclude;
|
||||
return {};
|
||||
// exclude all entities starting with `e`
|
||||
// add declaration flag to detect check for equality
|
||||
return code_generator::exclude | code_generator::declaration;
|
||||
else if (e.name() == "FOO")
|
||||
// don't show macro replacement
|
||||
return code_generator::declaration;
|
||||
return code_generator::exclude_noexcept_condition;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -167,8 +171,10 @@ void e();
|
|||
|
||||
void func(int a, int e, int c);
|
||||
|
||||
#define FOO hidden
|
||||
|
||||
template <typename e1, typename e2>
|
||||
void tfunc(int a);
|
||||
void tfunc(int a) noexcept(false);
|
||||
|
||||
struct base {};
|
||||
struct e_t {};
|
||||
|
|
@ -192,11 +198,15 @@ public:
|
|||
private:
|
||||
int e3;
|
||||
};
|
||||
|
||||
void func2() noexcept(0 == 1 && 42);
|
||||
)";
|
||||
|
||||
auto synopsis = R"(void func(int a,int c);
|
||||
|
||||
void tfunc(int a);
|
||||
#define FOO
|
||||
|
||||
void tfunc(int a)noexcept(false);
|
||||
|
||||
struct base{
|
||||
};
|
||||
|
|
@ -213,6 +223,8 @@ class foo{
|
|||
public:
|
||||
int c;
|
||||
};
|
||||
|
||||
void func2()noexcept(excluded);
|
||||
)";
|
||||
|
||||
auto file = parse({}, "code_generator_exclude.cpp", code);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue