This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[c++, cxx-reflection] Initial thoughts on type reflection.
- From: Phil Edwards <phil at jaj dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 9 Mar 2003 22:20:49 -0500
- Subject: [c++, cxx-reflection] Initial thoughts on type reflection.
Gaby and I have been discussing this in private, on and off, for a few weeks.
I've made 3 or 4 implementations with varying tradeoffs. Even though the
cxx-reflection-branch is experimental, it would nice to get some public
discussion before any code starts getting checked in.
One of the many things we'd like to be able to do is access -- in user-level
code -- some of the information that only the compiler knows. For example,
"is arbitrary type T a user-defined class? if so, does it have a trivial
copy constructor?" So to start with, we propose a number of builtin types,
created by the compiler at startup and accessible to users, that look
something like this:
/* the values of the enums are omitted here */
enum __EntityKind__
{
__ek_namespace, __ek_type, __ek_function, __ek_member,
__ek_template, __ek_variable, __ek_value
};
enum __CVQualifier__
{
__cv_none, __cv_const, __cv_volatile, __cv_restrict,
__cv_const_volatile, __cv_const_restrict, __cv_volatile_restrict,
__cv_const_volatile_restrict
};
enum __TypeKind__
{
__tk_void, __tk_integral, __tk_floating_point, __tk_array,
__tk_pointer, __tk_reference, __tk_enum, __tk_union, __tk_class,
__tk_member_pointer, __tk_function
};
enum __SpecialFunctions__
{
__sf_default_ctor, __sf_copy_ctor, __sf_dtor, __sf_dtor_virtual,
__sf_assign_op, __sf_default_ctor_trivial, __sf_copy_ctor_trivial,
__sf_assign_op_trivial, __sf_dtor_trivial
};
/* more enums and/or values as needed */
Then code can be written like this
/* assume a type T */
if (magic_TypeKind_expression (T) == __tk_class
&& magic_SpecialFunctions_expression (T) == __sf_copy_ctor_trivial)
{
...
}
where the precise spelling of magic_*_expression doesn't matter here and
is left for later email debate. :-)
Important here is that the magic expressions and their results can all be
used as integral constant expressions.
The working implementation involves a .c file containing only framework,
and a .def file containing (among other things) the list of enums.
Reactions from anybody, before I raise the more controversial issues in a
few days?
Phil
--
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace. We seek
not your counsel, nor your arms. Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen. - Samuel Adams