| View previous topic :: View next topic |
| Author |
Message |
Siegfried Guest
|
Posted: Sun Nov 27, 2005 5:30 am Post subject: How to implement reflection in C++ |
|
|
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
Thanks,
Siegfried
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Sun Nov 27, 2005 7:18 am Post subject: Re: How to implement reflection in C++ |
|
|
Siegfried wrote:
| Quote: | Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
|
I'm gonna bet that such a thing isn't available. Maybe if you explain
why you need it, or think you need it, someone could help you find a
more available solution.
|
|
| Back to top |
|
 |
peter steiner Guest
|
Posted: Sun Nov 27, 2005 9:51 am Post subject: Re: How to implement reflection in C++ |
|
|
Siegfried wrote:
| Quote: | Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
|
have a look at the objdump(1) sources which reads symbols from gcc
generated object files.
but i don't think you will be able to get the information that you need
from the object files, as these linker input files do not necessarily
contain the original C++ object layout in processable form.
you will need C++ parser output to get full identifier information for
C++ source files.
if you don't want to use a full-blown C++ parser implementation, for
example the wrapper/interface generator tool swig has a mode to output
a XML or lisp s-expression formatted abstract syntax tree for given
source files. this gives you parseable data to further work with.
see http://www.swig.org
-- peter
|
|
| Back to top |
|
 |
Roland Pibinger Guest
|
Posted: Sun Nov 27, 2005 11:10 am Post subject: Re: How to implement reflection in C++ |
|
|
On 27 Nov 2005 01:51:05 -0800, "peter steiner" <pnsteiner (AT) gmail (DOT) com>
wrote:
| Quote: | Siegfried wrote:
Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
have a look at the objdump(1) sources which reads symbols from gcc
generated object files.
|
or nm
(http://www.gnu.org/software/binutils/manual/html_chapter/binutils_2.html)
on Unix or dumpbin for VC++.
Best wishes,
Roland Pibinger
|
|
| Back to top |
|
 |
Julián Albo Guest
|
Posted: Sun Nov 27, 2005 12:00 pm Post subject: Re: How to implement reflection in C++ |
|
|
Siegfried wrote:
| Quote: | I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
|
Supposing that you find or write such a tool, you must consider that the
member functions of a class can be spawned over several .o files.
--
Salu2
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Sun Nov 27, 2005 7:06 pm Post subject: Re: How to implement reflection in C++ |
|
|
Siegfried wrote:
| Quote: | Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
|
Go ask the gcc people. It's not standard C++ (I wish it was too) so
it's off topic here.
|
|
| Back to top |
|
 |
WaRCHieFX Guest
|
Posted: Mon Nov 28, 2005 2:37 pm Post subject: Re: How to implement reflection in C++ |
|
|
Take a look at the RTTI chapter in Thinking in C++
([url]www.bruceeckel.com)[/url], i don't remember which volume.
|
|
| Back to top |
|
 |
Ira Baxter Guest
|
Posted: Wed Dec 07, 2005 3:35 am Post subject: Re: How to implement reflection in C++ |
|
|
"peter steiner" <pnsteiner (AT) gmail (DOT) com> wrote
| Quote: | Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?
you will need C++ parser output to get full identifier information for
C++ source files.
|
A front end C++ parser that can be straightforwardly configure to do this
can be seen at
www.semanticdesigns.com/Products/FrontEnds/CppFrontEnd
It handles full GCC.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
|
|
| Back to top |
|
 |
|