diff --git a/CMakeLists.txt b/CMakeLists.txt index f286f2ad..52e9d380 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ xo_add_genfacet( OUTPUT_CPP_DIR src/expression2 ) +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git xo_add_genfacetimpl( TARGET xo-expression2-facetimpl-expression-constant @@ -56,6 +58,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/expression2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-expression2-facetimpl-printable-constant + FACET_PKG xo_printable2 + FACET Printable + REPR Constant + INPUT idl/IPrintable_DConstant.json5 + OUTPUT_HPP_DIR include/xo/expression2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/expression2 +) + # ---------------------------------------------------------------- # note: manual target; generated code committed to git diff --git a/idl/IPrintable_DConstant.json5 b/idl/IPrintable_DConstant.json5 new file mode 100644 index 00000000..1d955d79 --- /dev/null +++ b/idl/IPrintable_DConstant.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DConstant", + using_doxygen: true, + repr: "DConstant", + doc: [ "implement APrintable for DConstant" ], +} diff --git a/include/xo/expression2/DConstant.hpp b/include/xo/expression2/DConstant.hpp index a73ea2df..81561e68 100644 --- a/include/xo/expression2/DConstant.hpp +++ b/include/xo/expression2/DConstant.hpp @@ -22,6 +22,7 @@ namespace xo { using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; using typeseq = xo::reflect::typeseq; + using ppindentinfo = xo::print::ppindentinfo; public: explicit DConstant(obj value) noexcept; @@ -45,6 +46,8 @@ namespace xo { void assign_valuetype(TypeDescr td) noexcept { typeref_.resolve(td); } + bool pretty(const ppindentinfo & ppii) const; + private: static TypeDescr _lookup_td(typeseq tseq); diff --git a/include/xo/expression2/detail/IPrintable_DConstant.hpp b/include/xo/expression2/detail/IPrintable_DConstant.hpp new file mode 100644 index 00000000..a1e31382 --- /dev/null +++ b/include/xo/expression2/detail/IPrintable_DConstant.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DConstant.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DConstant.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DConstant.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DConstant.hpp" + +namespace xo { namespace scm { class IPrintable_DConstant; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DConstant + **/ + class IPrintable_DConstant { + public: + /** @defgroup scm-printable-dconstant-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dconstant-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DConstant & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/expression2/CMakeLists.txt b/src/expression2/CMakeLists.txt index f2dfe7e7..17c34275 100644 --- a/src/expression2/CMakeLists.txt +++ b/src/expression2/CMakeLists.txt @@ -11,7 +11,9 @@ set(SELF_SRCS TypeRef.cpp IExpression_Any.cpp + IExpression_DConstant.cpp + IPrintable_DConstant.cpp IExpression_DVariable.cpp IPrintable_DVariable.cpp diff --git a/src/expression2/DConstant.cpp b/src/expression2/DConstant.cpp index 5bf98bfc..a0b255a6 100644 --- a/src/expression2/DConstant.cpp +++ b/src/expression2/DConstant.cpp @@ -7,12 +7,16 @@ #include "TypeDescr.hpp" #include #include +#include #include +#include #include namespace xo { using xo::scm::DFloat; using xo::scm::DInteger; + using xo::print::APrintable; + using xo::facet::FacetRegistry; using xo::reflect::Reflect; using xo::reflect::TypeDescr; using xo::reflect::typeseq; @@ -57,6 +61,20 @@ namespace xo { return nullptr; } + + bool + DConstant::pretty(const ppindentinfo & ppii) const + { + obj value + = FacetRegistry::instance().variant(value_); + + return ppii.pps()->pretty_struct + (ppii, + "DConstant", + refrtag("value_.tseq", value_._typeseq()), + refrtag("value.tseq", value._typeseq()), + refrtag("value", value)); + } } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/expression2/DDefineExpr.cpp b/src/expression2/DDefineExpr.cpp index e193c4d4..47465c0e 100644 --- a/src/expression2/DDefineExpr.cpp +++ b/src/expression2/DDefineExpr.cpp @@ -79,11 +79,21 @@ namespace xo { auto rhs = FacetRegistry::instance().try_variant(rhs_); - return ppii.pps()->pretty_struct - (ppii, - "DDefineExpr", - refrtag("lhs", lhs), - refrtag("rhs", cond(rhs_, rhs, "nullptr"))); + // note: xo::print::cond() doesn't resolve the way we want here + + if (rhs) { + return ppii.pps()->pretty_struct + (ppii, + "DDefineExpr", + refrtag("lhs", lhs), + refrtag("rhs", rhs)); + } else { + return ppii.pps()->pretty_struct + (ppii, + "DDefineExpr", + refrtag("lhs", lhs)); + + } } } /*namespace scm*/ diff --git a/src/expression2/IPrintable_DConstant.cpp b/src/expression2/IPrintable_DConstant.cpp new file mode 100644 index 00000000..1bacfb9d --- /dev/null +++ b/src/expression2/IPrintable_DConstant.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DConstant.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DConstant.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DConstant.json5] +**/ + +#include "detail/IPrintable_DConstant.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DConstant::pretty(const DConstant & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DConstant.cpp */ \ No newline at end of file diff --git a/src/expression2/expression2_register_facets.cpp b/src/expression2/expression2_register_facets.cpp index e6715769..1854f3eb 100644 --- a/src/expression2/expression2_register_facets.cpp +++ b/src/expression2/expression2_register_facets.cpp @@ -8,10 +8,15 @@ #include #include +#include #include +#include #include +#include +#include + #include #include #include @@ -32,13 +37,24 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); - FacetRegistry::register_impl(); + // Expression + // +- Constant + // +- Variable + // \- DefineExpr + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + log && log(xtag("DUniqueString.tseq", typeseq::id())); log && log(xtag("DDefineExpr.tseq", typeseq::id())); log && log(xtag("DVariable.tseq", typeseq::id())); + log && log(xtag("DConstant.tseq", typeseq::id())); log && log(xtag("AExpression.tqseq", typeseq::id()));