Add getter to retrieve main entity being outputted

This commit is contained in:
Jonathan Müller 2017-09-20 12:51:25 +02:00
commit 17ef990bb2
2 changed files with 14 additions and 2 deletions

View file

@ -379,6 +379,12 @@ namespace cppast
return cur_output_.value();
}
/// \returns The entity whose code is being generated with [cppast::generate_code()]().
const cpp_entity& main_entity() const noexcept
{
return main_entity_.value();
}
private:
/// \returns The formatting options that should be used.
/// The base class version has no flags set.
@ -498,7 +504,10 @@ namespace cppast
do_write_token_seq(" ");
}
type_safe::optional_ref<const output> cur_output_;
type_safe::optional_ref<const output> cur_output_;
type_safe::optional_ref<const cpp_entity> main_entity_;
friend bool generate_code(code_generator& generator, const cpp_entity& e);
};
/// Generates code for the given entity.

View file

@ -1099,7 +1099,10 @@ namespace
bool cppast::generate_code(code_generator& generator, const cpp_entity& e)
{
return generate_code_impl(generator, e, cpp_public);
generator.main_entity_ = type_safe::ref(e);
auto result = generate_code_impl(generator, e, cpp_public);
generator.main_entity_ = nullptr;
return result;
}
void detail::write_template_arguments(