6#ifndef MIMICPP_PRINTING_TYPE_NAME_PRINT_VISITOR_HPP
7#define MIMICPP_PRINTING_TYPE_NAME_PRINT_VISITOR_HPP
15#ifndef MIMICPP_DETAIL_IS_MODULE
18 #include <type_traits>
19 #include <unordered_map>
20 #include <unordered_set>
30 static std::unordered_map<StringViewT, StringViewT>
const aliases{
31 {
"(anonymous namespace)",
"{anon-ns}"},
32 {
"{anonymous}",
"{anon-ns}"},
33 {
"anonymous namespace",
"{anon-ns}"},
34 {
"anonymous-namespace",
"{anon-ns}"},
35 {
"<lambda()>",
"lambda"}
44 static std::unordered_set<StringViewT>
const collection{
51 template <pr
int_iterator OutIter>
56 explicit PrintVisitor(OutIter
out)
noexcept(std::is_nothrow_move_constructible_v<OutIter>)
57 : m_Out{std::move(
out)}
62 constexpr OutIter
out() const noexcept
76 static constexpr void end()
90 m_Context.push_scope();
95 if (!std::exchange(m_IgnoreNextScopeResolution,
false))
100 m_Context.pop_scope();
105 if (content.starts_with(
"{lambda(")
106 && content.ends_with(
'}'))
108 auto const closingIter = std::ranges::find(content.crbegin(), content.crend(),
')');
117 content.starts_with(lambdaPrefix)
118 && content.ends_with(
'\''))
120 print(content.substr(1u, content.size() - 2u));
126 if (
constexpr StringViewT lambdaPrefix{
"<lambda_"};
127 content.starts_with(lambdaPrefix)
128 && content.ends_with(
'>'))
132 auto const numberBegin = content.cbegin() + lambdaPrefix.size();
133 if (
auto const numberEnd = std::ranges::find_if_not(numberBegin, content.cend() - 1u,
lexing::is_digit);
134 numberBegin != numberEnd)
137 print({numberBegin, numberEnd});
143 if (content.starts_with(
'`')
144 && content.ends_with(
'\''))
147 if (std::ranges::all_of(content.substr(1u, content.size() - 2u),
lexing::is_digit))
149 m_IgnoreNextScopeResolution =
true;
154 content = content.substr(1u, content.size() - 2u);
159 m_IgnoreNextScopeResolution =
true;
165 if (
auto const iter = aliases.find(content);
166 iter != aliases.cend())
168 content = iter->second;
175 m_Context.push_arg_sequence();
184 m_Context.pop_arg_sequence();
211 m_Context.push_arg_sequence();
220 m_Context.pop_arg_sequence();
244 if (m_Context.is_spec_printable())
252 if (m_Context.is_spec_printable())
260 if (m_Context.is_spec_printable())
268 if (m_Context.is_spec_printable())
276 if (m_Context.is_spec_printable())
284 if (m_Context.is_spec_printable())
292 bool m_IgnoreNextScopeResolution{
false};
298 constexpr bool is_printable() const noexcept
300 if (
auto const size = m_Stack.size();
307 return Type::argSequence == m_Stack.front()
308 && Type::scope == m_Stack.back();
315 constexpr bool is_spec_printable() const noexcept
317 return 0 == m_ScopeDepth;
322 m_Stack.emplace_back(Type::scope);
330 MIMICPP_ASSERT(!m_Stack.empty() && Type::scope == m_Stack.back(),
"Context-stack out of sync.");
334 void push_arg_sequence()
336 m_Stack.emplace_back(Type::argSequence);
340 void pop_arg_sequence()
344 MIMICPP_ASSERT(!m_Stack.empty() && Type::argSequence == m_Stack.back(),
"Context-stack out of sync.");
349 enum class Type : std::uint8_t
355 std::vector<Type> m_Stack{};
364 if (m_Context.is_printable())
366 m_Out = std::ranges::copy(text, std::move(m_Out)).out;
#define MIMICPP_ASSERT(condition, msg)
Definition Config.hpp:51
constexpr void add_const()
Definition NamePrintVisitor.hpp:242
constexpr void end_function_args()
Definition NamePrintVisitor.hpp:216
constexpr void add_rvalue_ref()
Definition NamePrintVisitor.hpp:282
constexpr void unrecognized(StringViewT const content)
Definition NamePrintVisitor.hpp:67
constexpr void begin_operator_identifier()
Definition NamePrintVisitor.hpp:233
static constexpr void end_operator_identifier()
Definition NamePrintVisitor.hpp:238
constexpr void begin_function_ptr()
Definition NamePrintVisitor.hpp:223
constexpr void end_template_args()
Definition NamePrintVisitor.hpp:180
static constexpr void begin()
Definition NamePrintVisitor.hpp:72
constexpr void end_scope()
Definition NamePrintVisitor.hpp:93
constexpr void begin_scope()
Definition NamePrintVisitor.hpp:88
static constexpr void end_function()
Definition NamePrintVisitor.hpp:196
static constexpr void begin_type()
Definition NamePrintVisitor.hpp:80
constexpr void add_lvalue_ref()
Definition NamePrintVisitor.hpp:274
constexpr void begin_function_args(std::ptrdiff_t const count)
Definition NamePrintVisitor.hpp:209
constexpr OutIter out() const noexcept
Definition NamePrintVisitor.hpp:62
constexpr void add_identifier(StringViewT content)
Definition NamePrintVisitor.hpp:103
constexpr void begin_template_args(std::ptrdiff_t const count)
Definition NamePrintVisitor.hpp:173
constexpr void end_return_type()
Definition NamePrintVisitor.hpp:204
constexpr void add_ptr()
Definition NamePrintVisitor.hpp:266
constexpr void add_volatile()
Definition NamePrintVisitor.hpp:250
static constexpr void begin_function()
Definition NamePrintVisitor.hpp:192
constexpr void end_function_ptr()
Definition NamePrintVisitor.hpp:228
static constexpr void end()
Definition NamePrintVisitor.hpp:76
constexpr void add_arg()
Definition NamePrintVisitor.hpp:187
PrintVisitor(OutIter out) noexcept(std::is_nothrow_move_constructible_v< OutIter >)
Definition NamePrintVisitor.hpp:56
static constexpr void end_type()
Definition NamePrintVisitor.hpp:84
constexpr void add_noexcept()
Definition NamePrintVisitor.hpp:258
static constexpr void begin_return_type()
Definition NamePrintVisitor.hpp:200
constexpr printing::PrintFn print
Functional object, converting the given object to its textual representation.
Definition Print.hpp:183
auto constexpr is_digit
Definition NameLexer.hpp:34
auto const & alias_map()
Definition NamePrintVisitor.hpp:28
auto const & ignored_identifiers()
Definition NamePrintVisitor.hpp:42
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:392