xo-reflect: + infra for reflecting functions
This commit is contained in:
parent
188825d449
commit
aa55e20e12
3 changed files with 116 additions and 27 deletions
|
|
@ -5,34 +5,37 @@
|
|||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace reflect {
|
||||
enum class Metatype { mt_invalid, mt_atomic, mt_pointer, mt_vector, mt_struct };
|
||||
namespace reflect {
|
||||
enum class Metatype { mt_invalid, mt_atomic, mt_pointer, mt_vector, mt_struct, mt_function };
|
||||
|
||||
inline std::ostream & operator<<(std::ostream & os,
|
||||
Metatype x) {
|
||||
switch(x) {
|
||||
case Metatype::mt_invalid:
|
||||
os << "invalid!";
|
||||
break;
|
||||
case Metatype::mt_atomic:
|
||||
os << "atomic";
|
||||
break;
|
||||
case Metatype::mt_pointer:
|
||||
os << "pointer";
|
||||
break;
|
||||
case Metatype::mt_vector:
|
||||
os << "vector";
|
||||
break;
|
||||
case Metatype::mt_struct:
|
||||
os << "struct";
|
||||
break;
|
||||
default:
|
||||
os << "???";
|
||||
}
|
||||
return os;
|
||||
} /*operator<<*/
|
||||
|
||||
} /*namespace reflect*/
|
||||
inline std::ostream & operator<<(std::ostream & os,
|
||||
Metatype x) {
|
||||
switch(x) {
|
||||
case Metatype::mt_invalid:
|
||||
os << "invalid!";
|
||||
break;
|
||||
case Metatype::mt_atomic:
|
||||
os << "atomic";
|
||||
break;
|
||||
case Metatype::mt_pointer:
|
||||
os << "pointer";
|
||||
break;
|
||||
case Metatype::mt_vector:
|
||||
os << "vector";
|
||||
break;
|
||||
case Metatype::mt_struct:
|
||||
os << "struct";
|
||||
break;
|
||||
case Metatype::mt_function:
|
||||
os << "function";
|
||||
break;
|
||||
default:
|
||||
os << "???";
|
||||
}
|
||||
return os;
|
||||
} /*operator<<*/
|
||||
|
||||
} /*namespace reflect*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Metatype.hpp */
|
||||
|
|
|
|||
49
include/xo/reflect/function/FunctionTdx.hpp
Normal file
49
include/xo/reflect/function/FunctionTdx.hpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/** @file FunctionTdx.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xo/reflect/TypeDescrExtra.hpp"
|
||||
#include "xo/reflect/EstablishTypeDescr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace reflect {
|
||||
/** Additional type-associated information for a function/procedure **/
|
||||
class FunctionTdx : public TypeDescrExtra {
|
||||
public:
|
||||
virtual ~FunctionTdx() = default;
|
||||
|
||||
/** create instance. Will be invoked exactly once for each reflected function type **/
|
||||
static std::unique_ptr<FunctionTdx> make_function(TypeDescr retval_td,
|
||||
std::vector<TypeDescr> arg_td_v);
|
||||
|
||||
|
||||
|
||||
// ----- Inherited from TypeDescrExtra -----
|
||||
|
||||
virtual Metatype metatype() const override { return Metatype::mt_function; }
|
||||
virtual uint32_t n_child(void * /*object*/) const override { return 0; }
|
||||
virtual TaggedPtr child_tp(uint32_t i, void * object) const override;
|
||||
const std::string & struct_member_name(uint32_t i) const override;
|
||||
|
||||
virtual uint32_t n_fn_arg() const override { return arg_td_v_.size(); }
|
||||
virtual TypeDescr fn_retval() const override { return retval_td_; }
|
||||
virtual TypeDescr fn_arg(uint32_t i) const override { return arg_td_v_[i]; }
|
||||
|
||||
private:
|
||||
FunctionTdx(TypeDescr retval_td,
|
||||
std::vector<TypeDescr> arg_td_v);
|
||||
|
||||
private:
|
||||
/** function return value **/
|
||||
TypeDescr retval_td_;
|
||||
/** function arguments, in positional order **/
|
||||
std::vector<TypeDescr> arg_td_v_;
|
||||
}; /*FunctionTdx*/
|
||||
} /*namespace reflect*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/** end FunctionTdx.hpp **/
|
||||
37
src/reflect/function/FunctionTdx.cpp
Normal file
37
src/reflect/function/FunctionTdx.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* @file FunctionTdx.cpp */
|
||||
|
||||
#include "function/FunctionTdx.hpp"
|
||||
#include "TaggedPtr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace reflect {
|
||||
/** create instance. Will be invoked exactly once for each reflected function type **/
|
||||
std::unique_ptr<FunctionTdx>
|
||||
FunctionTdx::make_function(TypeDescr retval_td,
|
||||
std::vector<TypeDescr> arg_td_v)
|
||||
{
|
||||
return std::unique_ptr<FunctionTdx>(new FunctionTdx(retval_td, std::move(arg_td_v)));
|
||||
}
|
||||
|
||||
FunctionTdx::FunctionTdx(TypeDescr retval_td,
|
||||
std::vector<TypeDescr> arg_td_v)
|
||||
: retval_td_{retval_td},
|
||||
arg_td_v_{std::move(arg_td_v)}
|
||||
{}
|
||||
|
||||
TaggedPtr
|
||||
FunctionTdx::child_tp(uint32_t /*i*/, void * /*object*/) const
|
||||
{
|
||||
return TaggedPtr::universal_null();
|
||||
}
|
||||
|
||||
const std::string &
|
||||
FunctionTdx::struct_member_name(uint32_t i) const
|
||||
{
|
||||
return TypeDescrExtra::struct_member_name(i);
|
||||
}
|
||||
} /*namespace reflect*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end FunctionTdx.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue