From 4e06906876034f1f0dcce79933a864540eaedc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 17 Jul 2017 16:18:14 +0200 Subject: [PATCH 1/3] Fix code generation exclusion --- include/cppast/code_generator.hpp | 2 +- test/code_generator.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index 85abd35..48c2c5f 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -193,7 +193,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. diff --git a/test/code_generator.cpp b/test/code_generator.cpp index 35513d9..c731fc1 100644 --- a/test/code_generator.cpp +++ b/test/code_generator.cpp @@ -157,7 +157,7 @@ struct foo{ generation_options do_get_options(const cpp_entity& e) override { if (e.name().front() == 'e') - return code_generator::exclude; + return code_generator::exclude | code_generator::declaration; return {}; } }; From 38dd1c9d183edc5b1e990d95eb7154afd4de678b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 17 Jul 2017 16:24:21 +0200 Subject: [PATCH 2/3] Hide macro replacement --- include/cppast/code_generator.hpp | 1 + src/code_generator.cpp | 2 +- test/code_generator.cpp | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index 48c2c5f..e2855e7 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -160,6 +160,7 @@ namespace cppast 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. + /// For a macro, it won't show the replacement if this flag is set _flag_set_size, //< \exclude }; diff --git a/src/code_generator.cpp b/src/code_generator.cpp index 6079194..04e1391 100644 --- a/src/code_generator.cpp +++ b/src/code_generator.cpp @@ -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; diff --git a/test/code_generator.cpp b/test/code_generator.cpp index c731fc1..fde5708 100644 --- a/test/code_generator.cpp +++ b/test/code_generator.cpp @@ -147,7 +147,6 @@ struct foo{ } SECTION("exclude") { - // exclude all entities starting with `e` class exclude_generator : public test_generator { public: @@ -157,7 +156,12 @@ struct foo{ generation_options do_get_options(const cpp_entity& e) override { 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; + else if (e.name() == "FOO") + // don't show macro replacement + return code_generator::declaration; return {}; } }; @@ -167,6 +171,8 @@ void e(); void func(int a, int e, int c); +#define FOO hidden + template void tfunc(int a); @@ -196,6 +202,8 @@ private: auto synopsis = R"(void func(int a,int c); +#define FOO + void tfunc(int a); struct base{ From 495b82158df9bbe6c3ff63473723f7598a4aa183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 17 Jul 2017 16:36:59 +0200 Subject: [PATCH 3/3] Hide noexcept condition --- include/cppast/code_generator.hpp | 3 ++- src/code_generator.cpp | 9 ++++++++- test/code_generator.cpp | 10 +++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index e2855e7..a81f6a4 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -159,7 +159,8 @@ 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 }; diff --git a/src/code_generator.cpp b/src/code_generator.cpp index 04e1391..2f1007e 100644 --- a/src/code_generator.cpp +++ b/src/code_generator.cpp @@ -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(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(")"); } } diff --git a/test/code_generator.cpp b/test/code_generator.cpp index fde5708..637471e 100644 --- a/test/code_generator.cpp +++ b/test/code_generator.cpp @@ -162,7 +162,7 @@ struct foo{ else if (e.name() == "FOO") // don't show macro replacement return code_generator::declaration; - return {}; + return code_generator::exclude_noexcept_condition; } }; @@ -174,7 +174,7 @@ void func(int a, int e, int c); #define FOO hidden template -void tfunc(int a); +void tfunc(int a) noexcept(false); struct base {}; struct e_t {}; @@ -198,13 +198,15 @@ public: private: int e3; }; + +void func2() noexcept(0 == 1 && 42); )"; auto synopsis = R"(void func(int a,int c); #define FOO -void tfunc(int a); +void tfunc(int a)noexcept(false); struct base{ }; @@ -221,6 +223,8 @@ class foo{ public: int c; }; + +void func2()noexcept(excluded); )"; auto file = parse({}, "code_generator_exclude.cpp", code);