diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index a6e95f5..ade030b 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -275,10 +275,16 @@ namespace cppast template const output& operator<<(const basic_cpp_entity_ref& ref) const { - gen_->do_write_reference(ref.id(), ref.name()); + was_excluded_ = !gen_->do_write_reference(ref.id(), ref.name()); return *this; } + /// \returns Whether or not the last reference was excluded. + bool was_reference_excluded() const + { + return was_excluded_; + } + /// \effects Calls `do_write_punctuation()`. const output& operator<<(const punctuation& punct) const { @@ -353,6 +359,7 @@ namespace cppast type_safe::object_ref gen_; type_safe::object_ref e_; generation_options options_; + mutable bool was_excluded_ = false; }; protected: @@ -427,6 +434,7 @@ namespace cppast /// \effects Writes the specified special token. /// The base class version simply forwards to `do_write_token_seq()`. + /// \returns `do_write_reference()` returns `false`, if the reference was excluded. /// \notes This is useful for syntax highlighting, for example. /// \group write virtual void do_write_keyword(string_view keyword) @@ -439,11 +447,12 @@ namespace cppast do_write_token_seq(identifier); } /// \group write - virtual void do_write_reference(type_safe::array_ref id, + virtual bool do_write_reference(type_safe::array_ref id, string_view name) { (void)id; do_write_token_seq(name); + return true; } /// \group write virtual void do_write_punctuation(string_view punct) diff --git a/src/cpp_type.cpp b/src/cpp_type.cpp index c2dc88a..8c98a8c 100644 --- a/src/cpp_type.cpp +++ b/src/cpp_type.cpp @@ -481,6 +481,9 @@ namespace const cpp_template_instantiation_type& type) { output << type.primary_template(); + if (output.was_reference_excluded()) + return; + if (type.arguments_exposed()) detail::write_template_arguments(output, type.arguments()); else