Time for std.reflection

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Jul 22 09:15:16 PDT 2012


On 7/22/12, Philippe Sigaud <philippe.sigaud at gmail.com> wrote:
> 2) Why classes, as opposed to structs?

I think either way you'd need reference semantics. For example maybe
you're doing code-generation at compile-time but you need to rename a
class name in a typeinfo returned by std.reflection before doing any
processign. With reference semantics you only have to change one class
and all other types which refer to such a class will have access to
the new name.

You could use structs as well, and actually I use structs in my
codegenerator (with a similar layout to what Andrei posted). Each
struct (e.g. Class/Function) stores Symbols, which are structs with an
ID and a Type. I can look up each symbol in a SymTable which actually
holds the structures with data. So a Symbol is like a fake pointer,
and the SymTable would be the memory. I originally planned to use
classes but some serialization frameworks didn't work with those so I
settled using structs and a bit of template mixin magic instead.

All of this std.reflection talk is quite exciting actually. If you had
AST information about your entire D library you could do some really
cool things. You could make a better documentation generator than
ddoc, or export the AST into a file for a code-completion plugin, or
create a wrapper C library which enables other languages to use your D
library.


More information about the Digitalmars-d mailing list