xo-reader2 xo-expression2: pprint for DDefineExpr + DVariable

This commit is contained in:
Roland Conybeare 2026-01-20 15:06:58 -05:00
commit 807513a556
14 changed files with 311 additions and 3 deletions

View file

@ -56,6 +56,8 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/expression2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-expression-variable
@ -68,6 +70,20 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/expression2
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-printable-variable
FACET_PKG xo_printable2
FACET Printable
REPR Variable
INPUT idl/IPrintable_DVariable.json5
OUTPUT_HPP_DIR include/xo/expression2
OUTPUT_IMPL_SUBDIR detail
OUTPUT_CPP_DIR src/expression2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-expression2-facetimpl-expression-defineexpr
@ -80,6 +96,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-defineexpr
FACET_PKG xo_printable2
FACET Printable
REPR DefineExpr
INPUT idl/IPrintable_DDefineExpr.json5
OUTPUT_HPP_DIR include/xo/expression2
OUTPUT_IMPL_SUBDIR detail
OUTPUT_CPP_DIR src/expression2
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Printable.json5",
brief: "provide APrintable interface for DDefineExpr",
using_doxygen: true,
repr: "DDefineExpr",
doc: [ "implement APrintable for DDefineExpr" ],
}

View file

@ -0,0 +1,13 @@
{
mode: "implementation",
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Printable.json5",
brief: "provide APrintable interface for DVariable",
using_doxygen: true,
repr: "DVariable",
doc: [ "implement APrintable for DVariable" ],
}

View file

@ -8,6 +8,7 @@
#include "Expression.hpp"
#include "DVariable.hpp"
#include <xo/alloc2/Allocator.hpp>
#include <xo/indentlog/print/pretty.hpp>
namespace xo {
namespace scm {
@ -21,6 +22,7 @@ namespace xo {
**/
class DDefineExpr {
public:
using ppindentinfo = xo::print::ppindentinfo;
using AAllocator = xo::mm::AAllocator;
using TypeDescr = xo::reflect::TypeDescr;
@ -62,6 +64,12 @@ namespace xo {
void assign_valuetype(TypeDescr td) noexcept;
///@}
/** @defgroup scm-defineexpr-printable-facet **/
///@{
bool pretty(const ppindentinfo & ppii) const;
///@}
private:
/** @defgrouop scm-defineexpr-instance-vars **/

View file

@ -10,6 +10,7 @@
#include "TypeRef.hpp"
#include "exprtype.hpp"
#include <xo/reflect/TypeDescr.hpp>
#include <xo/indentlog/print/pretty.hpp>
namespace xo {
namespace scm {
@ -19,6 +20,7 @@ namespace xo {
**/
class DVariable {
public:
using ppindentinfo = xo::print::ppindentinfo;
using AAllocator = xo::mm::AAllocator;
using TypeDescr = xo::reflect::TypeDescr;
@ -46,7 +48,7 @@ namespace xo {
void assign_name(const DUniqueString * name) { this->name_ = name; }
/** @defgroup scm-variable-expression-facet**/
/** @defgroup scm-variable-expression-facet **/
///@{
exprtype extype() const noexcept { return exprtype::variable; }
@ -55,6 +57,12 @@ namespace xo {
void assign_valuetype(TypeDescr td) noexcept;
///@}
/** @defgroup scm-variable-printable-facet **/
///@{
bool pretty(const ppindentinfo & ppii) const;
///@}
private:
/** symbol name **/

View file

@ -55,7 +55,7 @@ namespace xo {
static TypeDescr valuetype(const DVariable & self) noexcept;
// non-const methods
/** assing to valuetype member. Useful when scaffolding expressions **/
/** assign to valuetype member. Useful when scaffolding expressions **/
static void assign_valuetype(DVariable & self, TypeDescr td) noexcept;
///@}
};
@ -63,4 +63,4 @@ namespace xo {
} /*namespace scm*/
} /*namespace xo*/
/* end */
/* end */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DDefineExpr.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DDefineExpr.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DDefineExpr.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DDefineExpr.hpp"
namespace xo { namespace scm { class IPrintable_DDefineExpr; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DDefineExpr>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DDefineExpr,
xo::scm::IPrintable_DDefineExpr>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DDefineExpr
**/
class IPrintable_DDefineExpr {
public:
/** @defgroup scm-printable-ddefineexpr-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-ddefineexpr-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DDefineExpr & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,62 @@
/** @file IPrintable_DVariable.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DVariable.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DVariable.json5]
**/
#pragma once
#include "Printable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DVariable.hpp"
namespace xo { namespace scm { class IPrintable_DVariable; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DVariable>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DVariable,
xo::scm::IPrintable_DVariable>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DVariable
**/
class IPrintable_DVariable {
public:
/** @defgroup scm-printable-dvariable-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
using Copaque = xo::print::APrintable::Copaque;
using Opaque = xo::print::APrintable::Opaque;
///@}
/** @defgroup scm-printable-dvariable-methods **/
///@{
// const methods
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
static bool pretty(const DVariable & self, const ppindentinfo & ppii);
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -12,8 +12,12 @@ set(SELF_SRCS
IExpression_Any.cpp
IExpression_DConstant.cpp
IExpression_DVariable.cpp
IPrintable_DVariable.cpp
IExpression_DDefineExpr.cpp
IPrintable_DDefineExpr.cpp
DLocalSymtab.cpp
DGlobalSymtab.cpp

View file

@ -4,9 +4,14 @@
**/
#include "DDefineExpr.hpp"
#include "detail/IPrintable_DVariable.hpp"
#include <xo/printable2/Printable.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::print::APrintable;
using xo::facet::FacetRegistry;
using xo::facet::typeseq;
namespace scm {
@ -60,6 +65,30 @@ namespace xo {
{
lhs_var_->assign_valuetype(td);
}
bool
DDefineExpr::pretty(const ppindentinfo & ppii) const
{
auto lhs = obj<APrintable,DVariable>(lhs_var_);
auto rhs = FacetRegistry::instance().try_variant<APrintable,
AExpression>(rhs_);
if (rhs_) {
assert(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*/
} /*namespace xo*/

View file

@ -35,6 +35,19 @@ namespace xo {
typeref_.resolve(td);
}
bool
DVariable::pretty(const ppindentinfo & ppii) const
{
auto name = (name_
? std::string_view(*name_)
: std::string_view(""));
return ppii.pps()->pretty_struct
(ppii,
"DVariable",
refrtag("name", name));
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DDefineExpr.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DDefineExpr.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DDefineExpr.json5]
**/
#include "detail/IPrintable_DDefineExpr.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DDefineExpr::pretty(const DDefineExpr & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DDefineExpr.cpp */

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DVariable.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DVariable.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DVariable.json5]
**/
#include "detail/IPrintable_DVariable.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DVariable::pretty(const DVariable & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DVariable.cpp */

View file

@ -8,6 +8,10 @@
#include <xo/expression2/detail/IGCObject_DUniqueString.hpp>
#include <xo/expression2/detail/IPrintable_DUniqueString.hpp>
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/gc/detail/AGCObject.hpp>
#include <xo/printable2/detail/APrintable.hpp>
#include <xo/facet/FacetRegistry.hpp>
@ -28,7 +32,15 @@ namespace xo {
FacetRegistry::register_impl<AGCObject, DUniqueString>();
FacetRegistry::register_impl<APrintable, DUniqueString>();
FacetRegistry::register_impl<APrintable, DDefineExpr>();
FacetRegistry::register_impl<APrintable, DVariable>();
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
return true;
}