xo-reader2 xo-expression2: define example working and printing

def foo : f64 = 3.141593;
This commit is contained in:
Roland Conybeare 2026-01-22 18:40:42 -05:00
commit 855cdb08b7
9 changed files with 172 additions and 6 deletions

View file

@ -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

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 DConstant",
using_doxygen: true,
repr: "DConstant",
doc: [ "implement APrintable for DConstant" ],
}

View file

@ -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<AGCObject> 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);

View file

@ -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 <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DConstant.hpp"
namespace xo { namespace scm { class IPrintable_DConstant; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DConstant>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DConstant,
xo::scm::IPrintable_DConstant>;
};
}
}
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 */

View file

@ -11,7 +11,9 @@ set(SELF_SRCS
TypeRef.cpp
IExpression_Any.cpp
IExpression_DConstant.cpp
IPrintable_DConstant.cpp
IExpression_DVariable.cpp
IPrintable_DVariable.cpp

View file

@ -7,12 +7,16 @@
#include "TypeDescr.hpp"
#include <xo/object2/DFloat.hpp>
#include <xo/object2/DInteger.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/reflect/Reflect.hpp>
#include <xo/printable2/Printable.hpp>
#include <xo/reflectutil/typeseq.hpp>
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<APrintable> value
= FacetRegistry::instance().variant<APrintable,AGCObject>(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*/

View file

@ -79,11 +79,21 @@ namespace xo {
auto rhs = FacetRegistry::instance().try_variant<APrintable,
AExpression>(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*/

View file

@ -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 */

View file

@ -8,10 +8,15 @@
#include <xo/expression2/detail/IGCObject_DUniqueString.hpp>
#include <xo/expression2/detail/IPrintable_DUniqueString.hpp>
#include <xo/expression2/detail/IExpression_DDefineExpr.hpp>
#include <xo/expression2/detail/IPrintable_DDefineExpr.hpp>
#include <xo/expression2/detail/IExpression_DVariable.hpp>
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
#include <xo/expression2/detail/IExpression_DConstant.hpp>
#include <xo/expression2/detail/IPrintable_DConstant.hpp>
#include <xo/gc/detail/AGCObject.hpp>
#include <xo/printable2/detail/APrintable.hpp>
#include <xo/facet/FacetRegistry.hpp>
@ -32,13 +37,24 @@ namespace xo {
FacetRegistry::register_impl<AGCObject, DUniqueString>();
FacetRegistry::register_impl<APrintable, DUniqueString>();
FacetRegistry::register_impl<APrintable, DDefineExpr>();
// Expression
// +- Constant
// +- Variable
// \- DefineExpr
FacetRegistry::register_impl<AExpression, DConstant>();
FacetRegistry::register_impl<APrintable, DConstant>();
FacetRegistry::register_impl<AExpression, DVariable>();
FacetRegistry::register_impl<APrintable, DVariable>();
FacetRegistry::register_impl<AExpression, DDefineExpr>();
FacetRegistry::register_impl<APrintable, DDefineExpr>();
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("DConstant.tseq", typeseq::id<DConstant>()));
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));