xo-expression2: + SymbolTable facet
This commit is contained in:
parent
2178d78540
commit
00f8146af5
8 changed files with 457 additions and 0 deletions
59
xo-expression2/idl/SymbolTable.json5
Normal file
59
xo-expression2/idl/SymbolTable.json5
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
mode: "facet",
|
||||
includes: [
|
||||
"\"Binding.hpp\"",
|
||||
"\"DUniqueString.hpp\""
|
||||
],
|
||||
// extra includes in SymbolTable.hpp, if any
|
||||
user_hpp_includes: [],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
// text after includes, before ASymbolTable
|
||||
pretext: [ "// {pretext} here" ],
|
||||
facet: "SymbolTable",
|
||||
detail_subdir: "symtab",
|
||||
brief: "symbol table derived from a set of schematika expressions",
|
||||
using_doxygen: true,
|
||||
doc: [
|
||||
"Map symbols to schematika expressions. Output of schematika parser"
|
||||
],
|
||||
types: [
|
||||
// { name: string, doc: [ string ], definition: string },
|
||||
],
|
||||
const_methods: [
|
||||
|
||||
{
|
||||
// bool is_global_symtab() const noexcept;
|
||||
name: "is_global_symtab",
|
||||
doc: ["true iff this is toplevel (global) symbol table."],
|
||||
return_type: "bool",
|
||||
args: [],
|
||||
const: true,
|
||||
noexcept: true,
|
||||
attributes: [],
|
||||
},
|
||||
|
||||
{
|
||||
// Binding lookup_binding(const DUniqueString * sym) const noexcept;
|
||||
name: "lookup_binding",
|
||||
doc: ["report ingredients needed to address variable at runtime."],
|
||||
return_type: "Binding",
|
||||
args: [
|
||||
{type: "const DUniqueString *", name: "sym"},
|
||||
],
|
||||
const: true,
|
||||
noexcept: true,
|
||||
attributes: [],
|
||||
},
|
||||
|
||||
// //
|
||||
// obj<AExpression> lookup_var(const DUniqueString * sym) const noexcept;
|
||||
|
||||
// //
|
||||
// obj<AExpression> lookup_local(const DUniqueString * sym) const noexcept;
|
||||
],
|
||||
nonconst_methods: [
|
||||
// // Variable gives both {name, type}
|
||||
// void upsert_local(DVariable * target) = 0;
|
||||
],
|
||||
}
|
||||
22
xo-expression2/include/xo/expression2/SymbolTable.hpp
Normal file
22
xo-expression2/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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -3,15 +3,23 @@
|
|||
set(SELF_LIB xo_expression2)
|
||||
set(SELF_SRCS
|
||||
init_expression2.cpp
|
||||
|
||||
DConstant.cpp
|
||||
DVariable.cpp
|
||||
|
||||
TypeRef.cpp
|
||||
|
||||
IExpression_Any.cpp
|
||||
IExpression_DConstant.cpp
|
||||
|
||||
ISymbolTable_Any.cpp
|
||||
|
||||
StringTable.cpp
|
||||
|
||||
DUniqueString.cpp
|
||||
IGCObject_DUniqueString.cpp
|
||||
IPrintable_DUniqueString.cpp
|
||||
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
)
|
||||
|
|
|
|||
41
xo-expression2/src/expression2/ISymbolTable_Any.cpp
Normal file
41
xo-expression2/src/expression2/ISymbolTable_Any.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file ISymbolTable_Any.cpp
|
||||
*
|
||||
**/
|
||||
|
||||
#include "symtab/ISymbolTable_Any.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
using xo::facet::DVariantPlaceholder;
|
||||
using xo::facet::typeseq;
|
||||
using xo::facet::valid_facet_implementation;
|
||||
|
||||
void
|
||||
ISymbolTable_Any::_fatal()
|
||||
{
|
||||
/* control here on uninitialized IAllocator_Any.
|
||||
* Initialized instance will have specific implementation type
|
||||
*/
|
||||
std::cerr << "fatal"
|
||||
<< ": attempt to call uninitialized"
|
||||
<< " ISymbolTable_Any method"
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
typeseq
|
||||
ISymbolTable_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
|
||||
|
||||
bool
|
||||
ISymbolTable_Any::_valid
|
||||
= valid_facet_implementation<ASymbolTable, ISymbolTable_Any>();
|
||||
|
||||
// nonconst methods
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISymbolTable_Any.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue