C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to implement reflection in C++

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Siegfried
Guest





PostPosted: Sun Nov 27, 2005 5:30 am    Post subject: How to implement reflection in C++ Reply with 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?

Thanks,
Siegfried

Back to top
roberts.noah@gmail.com
Guest





PostPosted: Sun Nov 27, 2005 7:18 am    Post subject: Re: How to implement reflection in C++ Reply with quote




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





PostPosted: Sun Nov 27, 2005 9:51 am    Post subject: Re: How to implement reflection in C++ Reply with quote



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





PostPosted: Sun Nov 27, 2005 11:10 am    Post subject: Re: How to implement reflection in C++ Reply with quote

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





PostPosted: Sun Nov 27, 2005 12:00 pm    Post subject: Re: How to implement reflection in C++ Reply with quote

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





PostPosted: Sun Nov 27, 2005 7:06 pm    Post subject: Re: How to implement reflection in C++ Reply with quote

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





PostPosted: Mon Nov 28, 2005 2:37 pm    Post subject: Re: How to implement reflection in C++ Reply with quote

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





PostPosted: Wed Dec 07, 2005 3:35 am    Post subject: Re: How to implement reflection in C++ Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.