Jump to content
  • Advertisement
Sign in to follow this  
antareus

Implementing automatic object introspection in C++

This topic is 4776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been doing a bit of research as to how to implement automatic object introspection in C++. Here's a few things I've found: * GCC_XML lets you dump the GCC parse tree out to an XML file. It gets big very quickly, and isn't readable without other tools. * OpenC++ adds metaclass capabilities to C++ by precompiling the source file. Doesn't work with MSVC from what I've seen so far (I have no idea how these utilities actually connect to the compilers) * Qt has the MOC compiler available of course, but editing that would have a bit of a learning curve (to say the least) I played around with tokenizing C++ code, it is a bit intense for a newbie like me but I have something that seems to work for any source file I throw at it. (I only tokenize a bare minimum of what I need - basic operators and keywords/symbols.) I'm going to give the lexing side a try tonight if I get a chance. I'll probably start with enumerating the fields, then move up to automatic serialization of fundamental types. I'm curious if anyone has done any similar work.

Share this post


Link to post
Share on other sites
Advertisement
Can yours deal with templates?

And any IDE with code-completion must have some kind of parser in there somewhere. I know Code::Blocks does...

Share this post


Link to post
Share on other sites
I did a little thinking about using GCC_XML to have a go at coming up with automatic refactoring tools.

There are all kinds of things which make it far more difficult than developing refactoring tools for Java for example.

The preprocessor is one of them. This can affect the meaning of the program depending upon what the include paths are, whether it's a debug build etc. It's a nightmare! And to get the real information about what the file will be compiled to you have to run the preprocessor which takes time. The parser can then work out what the structure of the code is. It makes it difficult to have an interactive parser.

Good luck Antareus.

Share this post


Link to post
Share on other sites
Quote:
Original post by me22
Can yours deal with templates?

Yes. It correctly parses templates (in as much as GCC correctly parses templates... of which it does a pretty good job).

Quote:

And any IDE with code-completion must have some kind of parser in there somewhere. I know Code::Blocks does...

It's nothing really complex though.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
GCC XML doesn't follow preprocessor directives? Thats a shame, I'd love to work on toolchains more as time progresses.

I'm lexing just fine, need to add support for understanding (not parsing) templates into the tokenizer. I'm not certain where I should inject the actual generated code at this point:
* modify original file (eew, trigger one of those 'this file has been modified' boxes in editors)
* modify original file en route to compiler - seems tricky and I'd prefer the benefit of processing syntactically valid code
* pre-link, separate file - looks to be optimal

Share this post


Link to post
Share on other sites
I haven't been following C++0x developments for a while, but when I was, Bjarne Stroustrup had a proposal for adding reflection capabilities to the language, I think he called it XTI.

You might want to search comp.lang.c++.moderated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!