xo-expression2: + SymbolTable facet
This commit is contained in:
parent
a23307aabb
commit
37b0ea3c3e
8 changed files with 457 additions and 0 deletions
22
include/xo/expression2/SymbolTable.hpp
Normal file
22
include/xo/expression2/SymbolTable.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @file SymbolTable.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
* [facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/SymbolTable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "symtab/ASymbolTable.hpp"
|
||||
#include "symtab/ISymbolTable_Any.hpp"
|
||||
#include "symtab/ISymbolTable_Xfer.hpp"
|
||||
#include "symtab/RSymbolTable.hpp"
|
||||
|
||||
|
||||
/* end SymbolTable.hpp */
|
||||
75
include/xo/expression2/symtab/ASymbolTable.hpp
Normal file
75
include/xo/expression2/symtab/ASymbolTable.hpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/** @file ASymbolTable.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [abstract_facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/SymbolTable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
// includes (via {facet_includes})
|
||||
#include "Binding.hpp"
|
||||
#include "DUniqueString.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
||||
// {pretext} here
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/**
|
||||
Map symbols to schematika expressions. Output of schematika parser
|
||||
**/
|
||||
class ASymbolTable {
|
||||
public:
|
||||
/** @defgroup scm-symboltable-type-traits **/
|
||||
///@{
|
||||
// types
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-symboltable-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** true iff this is toplevel (global) symbol table. **/
|
||||
virtual bool is_global_symtab(Copaque data) const noexcept = 0;
|
||||
/** report ingredients needed to address variable at runtime. **/
|
||||
virtual Binding lookup_binding(Copaque data, const DUniqueString * sym) const noexcept = 0;
|
||||
|
||||
// nonconst methods
|
||||
///@}
|
||||
}; /*ASymbolTable*/
|
||||
|
||||
/** Implementation ISymbolTable_DRepr of ASymbolTable for state DRepr
|
||||
* should provide a specialization:
|
||||
*
|
||||
* template <>
|
||||
* struct xo::facet::FacetImplementation<ASymbolTable, DRepr> {
|
||||
* using Impltype = ISymbolTable_DRepr;
|
||||
* };
|
||||
*
|
||||
* then ISymbolTable_ImplType<DRepr> --> ISymbolTable_DRepr
|
||||
**/
|
||||
template <typename DRepr>
|
||||
using ISymbolTable_ImplType = xo::facet::FacetImplType<ASymbolTable, DRepr>;
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* ASymbolTable.hpp */
|
||||
86
include/xo/expression2/symtab/ISymbolTable_Any.hpp
Normal file
86
include/xo/expression2/symtab/ISymbolTable_Any.hpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/** @file ISymbolTable_Any.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/SymbolTable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ASymbolTable.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo { namespace scm { class ISymbolTable_Any; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASymbolTable,
|
||||
DVariantPlaceholder>
|
||||
{
|
||||
using ImplType = xo::scm::ISymbolTable_Any;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class ISymbolTable_Any
|
||||
* @brief ASymbolTable implementation for empty variant instance
|
||||
**/
|
||||
class ISymbolTable_Any : public ASymbolTable {
|
||||
public:
|
||||
/** @defgroup scm-symboltable-any-type-traits **/
|
||||
///@{
|
||||
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-symboltable-any-methods **/
|
||||
///@{
|
||||
|
||||
const ASymbolTable * iface() const { return std::launder(this); }
|
||||
|
||||
// from ASymbolTable
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] bool is_global_symtab(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] Binding lookup_binding(Copaque, const DUniqueString *) const noexcept override { _fatal(); }
|
||||
|
||||
// nonconst methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgraoup scm-symboltable-any-private-methods **/
|
||||
///@{
|
||||
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
///@}
|
||||
|
||||
public:
|
||||
/** @defgroup scm-symboltable-any-member-vars **/
|
||||
///@{
|
||||
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm */
|
||||
} /*namespace xo */
|
||||
|
||||
/* ISymbolTable_Any.hpp */
|
||||
84
include/xo/expression2/symtab/ISymbolTable_Xfer.hpp
Normal file
84
include/xo/expression2/symtab/ISymbolTable_Xfer.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file ISymbolTable_Xfer.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/SymbolTable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Binding.hpp"
|
||||
#include "DUniqueString.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISymbolTable_Xfer
|
||||
**/
|
||||
template <typename DRepr, typename ISymbolTable_DRepr>
|
||||
class ISymbolTable_Xfer : public ASymbolTable {
|
||||
public:
|
||||
/** @defgroup scm-symboltable-xfer-type-traits **/
|
||||
///@{
|
||||
/** actual implementation (not generated; often delegates to DRepr) **/
|
||||
using Impl = ISymbolTable_DRepr;
|
||||
/** integer identifying a type **/
|
||||
using typeseq = ASymbolTable::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-symboltable-xfer-methods **/
|
||||
///@{
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
||||
// from ASymbolTable
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
bool is_global_symtab(Copaque data) const noexcept override {
|
||||
return I::is_global_symtab(_dcast(data));
|
||||
}
|
||||
Binding lookup_binding(Copaque data, const DUniqueString * sym) const noexcept override {
|
||||
return I::lookup_binding(_dcast(data), sym);
|
||||
}
|
||||
|
||||
// non-const methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-symboltable-xfer-member-vars **/
|
||||
///@{
|
||||
|
||||
/** typeseq for template parameter DRepr **/
|
||||
static typeseq s_typeseq;
|
||||
/** true iff satisfies facet implementation **/
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename DRepr, typename ISymbolTable_DRepr>
|
||||
xo::facet::typeseq
|
||||
ISymbolTable_Xfer<DRepr, ISymbolTable_DRepr>::s_typeseq
|
||||
= xo::facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename ISymbolTable_DRepr>
|
||||
bool
|
||||
ISymbolTable_Xfer<DRepr, ISymbolTable_DRepr>::_valid
|
||||
= xo::facet::valid_facet_implementation<ASymbolTable,
|
||||
ISymbolTable_Xfer>();
|
||||
|
||||
} /*namespace scm */
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISymbolTable_Xfer.hpp */
|
||||
82
include/xo/expression2/symtab/RSymbolTable.hpp
Normal file
82
include/xo/expression2/symtab/RSymbolTable.hpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/** @file RSymbolTable.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/SymbolTable.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/SymbolTable.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ASymbolTable.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class RSymbolTable
|
||||
**/
|
||||
template <typename Object>
|
||||
class RSymbolTable : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-symboltable-router-type-traits **/
|
||||
///@{
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-symboltable-router-ctors **/
|
||||
///@{
|
||||
RSymbolTable() {}
|
||||
RSymbolTable(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
RSymbolTable(const ASymbolTable * iface, void * data)
|
||||
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
|
||||
: Object(iface, data) {}
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-symboltable-router-methods **/
|
||||
///@{
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
bool is_global_symtab() const noexcept {
|
||||
return O::iface()->is_global_symtab(O::data());
|
||||
}
|
||||
Binding lookup_binding(const DUniqueString * sym) const noexcept {
|
||||
return O::iface()->lookup_binding(O::data(), sym);
|
||||
}
|
||||
|
||||
// non-const methods (still const in router!)
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-symboltable-member-vars **/
|
||||
///@{
|
||||
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RSymbolTable<Object>::_valid = xo::facet::valid_object_router<Object>();
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace xo { namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::scm::ASymbolTable, Object> {
|
||||
using RoutingType = xo::scm::RSymbolTable<Object>;
|
||||
};
|
||||
} }
|
||||
|
||||
/* end RSymbolTable.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue