diff --git a/xo-expression2/include/xo/expression2/TypeRef.hpp b/xo-expression2/include/xo/expression2/TypeRef.hpp index 01401d28..7ec6e388 100644 --- a/xo-expression2/include/xo/expression2/TypeRef.hpp +++ b/xo-expression2/include/xo/expression2/TypeRef.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace xo { namespace scm { @@ -22,6 +23,7 @@ namespace xo { using TypeDescr = xo::reflect::TypeDescr; using type_var = flatstring<20>; using prefix_type = flatstring<8>; + using ppindentinfo = xo::print::ppindentinfo; public: TypeRef() = default; @@ -54,6 +56,9 @@ namespace xo { /** resolve TypeRef by supplying final type-description **/ void resolve(TypeDescr td) noexcept { td_ = td; } + /** pretty-printer support **/ + bool pretty(const ppindentinfo & ppii) const; + private: /** unique (probably generated) name for type at this location **/ type_var id_; @@ -64,6 +69,18 @@ namespace xo { TypeDescr td_; }; } /*namespace scm*/ + + namespace print { + /** pretty printer in relies on this specialization + * to handle TypeRef instances + **/ + template <> + struct ppdetail { + static inline bool print_pretty(const ppindentinfo & ppii, const xo::scm::TypeRef x) { + return x.pretty(ppii); + } + }; + } } /*namespace xo*/ /* end TypeRef.hpp */ diff --git a/xo-expression2/src/expression2/DVariable.cpp b/xo-expression2/src/expression2/DVariable.cpp index 4adbe841..4550a102 100644 --- a/xo-expression2/src/expression2/DVariable.cpp +++ b/xo-expression2/src/expression2/DVariable.cpp @@ -5,6 +5,7 @@ #include "DVariable.hpp" #include "exprtype.hpp" +#include namespace xo { using xo::facet::typeseq; @@ -38,6 +39,8 @@ namespace xo { bool DVariable::pretty(const ppindentinfo & ppii) const { + using xo::print::quot; + auto name = (name_ ? std::string_view(*name_) : std::string_view("")); @@ -45,7 +48,8 @@ namespace xo { return ppii.pps()->pretty_struct (ppii, "DVariable", - refrtag("name", name)); + refrtag("name", quot(name)), + refrtag("typeref", typeref_)); } } /*namespace scm*/ diff --git a/xo-expression2/src/expression2/TypeRef.cpp b/xo-expression2/src/expression2/TypeRef.cpp index 7b187ecd..01cb043c 100644 --- a/xo-expression2/src/expression2/TypeRef.cpp +++ b/xo-expression2/src/expression2/TypeRef.cpp @@ -4,6 +4,8 @@ **/ #include "TypeRef.hpp" +#include +#include namespace xo { namespace scm { @@ -62,6 +64,18 @@ namespace xo { return (td_ != nullptr); } + bool + TypeRef::pretty(const ppindentinfo & ppii) const + { + using xo::print::quot; + + return ppii.pps()->pretty_struct + (ppii, + "TypeRef", + refrtag("id", quot(id_)), + refrtag("td", td_)); + } + } /*namespace scm*/ } /*namespace xo*/