diff --git a/xo-expression2/CMakeLists.txt b/xo-expression2/CMakeLists.txt index f286f2ad..52e9d380 100644 --- a/xo-expression2/CMakeLists.txt +++ b/xo-expression2/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/xo-expression2/idl/IPrintable_DConstant.json5 b/xo-expression2/idl/IPrintable_DConstant.json5 new file mode 100644 index 00000000..1d955d79 --- /dev/null +++ b/xo-expression2/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/xo-expression2/include/xo/expression2/DConstant.hpp b/xo-expression2/include/xo/expression2/DConstant.hpp index a73ea2df..81561e68 100644 --- a/xo-expression2/include/xo/expression2/DConstant.hpp +++ b/xo-expression2/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/xo-expression2/include/xo/expression2/detail/IPrintable_DConstant.hpp b/xo-expression2/include/xo/expression2/detail/IPrintable_DConstant.hpp new file mode 100644 index 00000000..a1e31382 --- /dev/null +++ b/xo-expression2/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/xo-expression2/src/expression2/CMakeLists.txt b/xo-expression2/src/expression2/CMakeLists.txt index f2dfe7e7..17c34275 100644 --- a/xo-expression2/src/expression2/CMakeLists.txt +++ b/xo-expression2/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/xo-expression2/src/expression2/DConstant.cpp b/xo-expression2/src/expression2/DConstant.cpp index 5bf98bfc..a0b255a6 100644 --- a/xo-expression2/src/expression2/DConstant.cpp +++ b/xo-expression2/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/xo-expression2/src/expression2/DDefineExpr.cpp b/xo-expression2/src/expression2/DDefineExpr.cpp index e193c4d4..47465c0e 100644 --- a/xo-expression2/src/expression2/DDefineExpr.cpp +++ b/xo-expression2/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/xo-expression2/src/expression2/IPrintable_DConstant.cpp b/xo-expression2/src/expression2/IPrintable_DConstant.cpp new file mode 100644 index 00000000..1bacfb9d --- /dev/null +++ b/xo-expression2/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/xo-expression2/src/expression2/expression2_register_facets.cpp b/xo-expression2/src/expression2/expression2_register_facets.cpp index e6715769..1854f3eb 100644 --- a/xo-expression2/src/expression2/expression2_register_facets.cpp +++ b/xo-expression2/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())); diff --git a/xo-facet/include/xo/facet/FacetRegistry.hpp b/xo-facet/include/xo/facet/FacetRegistry.hpp index aa481a0c..da3a6676 100644 --- a/xo-facet/include/xo/facet/FacetRegistry.hpp +++ b/xo-facet/include/xo/facet/FacetRegistry.hpp @@ -128,7 +128,8 @@ namespace xo { if (!retval) throw std::runtime_error(tostr("FacetRegistry::try_variant failed", xtag("AFrom.tseq", typeseq::id()), - xtag("ATo.tseq", typeseq::id()))); + xtag("ATo.tseq", typeseq::id()), + xtag("DRepr", from._typeseq()))); return retval; } diff --git a/xo-reader2/src/reader2/DDefineSsm.cpp b/xo-reader2/src/reader2/DDefineSsm.cpp index 6de3bd93..21ff70f0 100644 --- a/xo-reader2/src/reader2/DDefineSsm.cpp +++ b/xo-reader2/src/reader2/DDefineSsm.cpp @@ -11,6 +11,7 @@ #include "ssm/IPrintable_DDefineSsm.hpp" #include #include +#include #ifdef NOT_YET #include "parserstatemachine.hpp" @@ -22,6 +23,7 @@ namespace xo { using xo::print::APrintable; + using xo::facet::FacetRegistry; using xo::facet::with_facet; using xo::facet::typeseq; @@ -617,7 +619,7 @@ namespace xo { bool DDefineSsm::pretty(const ppindentinfo & ppii) const { - auto expr = with_facet::mkobj(def_expr_.data()); + auto expr = FacetRegistry::instance().variant(def_expr_); return ppii.pps()->pretty_struct (ppii, diff --git a/xo-reader2/src/reader2/DProgressSsm.cpp b/xo-reader2/src/reader2/DProgressSsm.cpp index f202728e..ec19e994 100644 --- a/xo-reader2/src/reader2/DProgressSsm.cpp +++ b/xo-reader2/src/reader2/DProgressSsm.cpp @@ -5,7 +5,10 @@ #include "DProgressSsm.hpp" #include "ssm/ISyntaxStateMachine_DProgressSsm.hpp" +#include +#include #include +#include #ifdef NOT_YET #include "apply_xs.hpp" @@ -25,6 +28,8 @@ namespace xo { using xo::scm::Variable; using xo::scm::Apply; #endif + using xo::print::APrintable; + using xo::facet::FacetRegistry; using xo::facet::with_facet; using xo::reflect::typeseq; @@ -211,12 +216,23 @@ namespace xo { DProgressSsm::on_semicolon_token(const Token & tk, ParserStateMachine * p_psm) { + constexpr bool c_debug_flag = true; + scope log(XO_DEBUG(c_debug_flag)); + /* note: implementation should parallel .on_rightparen_token() */ (void)tk; obj expr = this->assemble_expr(p_psm); + { + obj expr_pr = FacetRegistry::instance().variant(expr); + + assert(expr_pr); + + log && log(xtag("expr", expr_pr)); + } + p_psm->pop_ssm(); p_psm->on_parsed_expression_with_semicolon(expr); @@ -951,12 +967,23 @@ namespace xo { bool DProgressSsm::pretty(const xo::print::ppindentinfo & ppii) const { + scope log(XO_DEBUG(true)); + log && log(xtag("lhs_.tseq", lhs_._typeseq())); + log && log(xtag("rhs_.tseq", rhs_._typeseq())); + + obj lhs + = FacetRegistry::instance().variant(lhs_); + + obj rhs; + if (rhs_) + rhs = FacetRegistry::instance().variant(rhs_); + return ppii.pps()->pretty_struct (ppii, "DProgressSsm", - refrtag("lhs", lhs_), + refrtag("lhs", lhs), refrtag("op", op_type_), - refrtag("rhs", rhs_)); + cond(rhs, refrtag("rhs", rhs), "nullptr")); #ifdef NOPE if (ppii.upto()) {