From dbececfb04d644ec39dc214a464f0524f9aa2024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Wed, 20 Sep 2017 12:43:30 +0200 Subject: [PATCH] Add comment code generation text --- include/cppast/code_generator.hpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/include/cppast/code_generator.hpp b/include/cppast/code_generator.hpp index 5f12e2e..ccfd402 100644 --- a/include/cppast/code_generator.hpp +++ b/include/cppast/code_generator.hpp @@ -24,14 +24,10 @@ namespace cppast { public: /// \effects Creates it viewing the [std::string](). - string_view(const std::string& str) noexcept : str_(str.c_str()), length_(str.length()) - { - } + string_view(const std::string& str) noexcept : str_(str.c_str()), length_(str.length()) {} /// \effects Creates it viewing the C string `str`. - string_view(const char* str) noexcept : str_(str), length_(std::strlen(str)) - { - } + string_view(const char* str) noexcept : str_(str), length_(std::strlen(str)) {} /// \effects Creates it viewing the C string literal. template @@ -108,6 +104,9 @@ namespace cppast /// A special [cppast::string_view]() representing a C++ preprocessor token. using preprocessor_token = detail::semantic_string_view; + /// A special [cppast::string_view]() representing a comment. + using comment = detail::semantic_string_view; + /// A special [cppast::string_view]() representing a sequence of unknown C++ tokens. using token_seq = detail::semantic_string_view; @@ -321,6 +320,14 @@ namespace cppast return *this; } + /// \effects Calls `do_write_comment()`. + const output& operator<<(const comment& c) const + { + if (*this) + gen_->do_write_comment(c.str()); + return *this; + } + /// \effects Calls `do_write_token_seq()`. const output& operator<<(const token_seq& seq) const { @@ -451,6 +458,11 @@ namespace cppast { do_write_token_seq(punct); } + /// \group write + virtual void do_write_comment(string_view c) + { + do_write_token_seq(c); + } /// \effects Writes a string for an excluded target or return type for the given entity. /// The base class version writes the identifier `excluded`.