Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to implement reflection in C++

Reply
Thread Tools

How to implement reflection in C++

 
 
Siegfried
Guest
Posts: n/a
 
      11-27-2005
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

 
Reply With Quote
 
 
 
 
roberts.noah@gmail.com
Guest
Posts: n/a
 
      11-27-2005

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.
>
> 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.

 
Reply With Quote
 
 
 
 
peter steiner
Guest
Posts: n/a
 
      11-27-2005
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.
>
> 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

 
Reply With Quote
 
Roland Pibinger
Guest
Posts: n/a
 
      11-27-2005
On 27 Nov 2005 01:51:05 -0800, "peter steiner" <>
wrote:
>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...inutils_2.html)
on Unix or dumpbin for VC++.

Best wishes,
Roland Pibinger
 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      11-27-2005
Siegfried wrote:

> 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
 
Reply With Quote
 
Gianni Mariani
Guest
Posts: n/a
 
      11-27-2005
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.
>
> 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.
 
Reply With Quote
 
WaRCHieFX
Guest
Posts: n/a
 
      11-28-2005
Take a look at the RTTI chapter in Thinking in C++
(www.bruceeckel.com), i don't remember which volume.

 
Reply With Quote
 
Ira Baxter
Guest
Posts: n/a
 
      12-07-2005

"peter steiner" <> wrote in message
news: oups.com...
> 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
http://www.semanticdesigns.com/Produ...ds/CppFrontEnd
It handles full GCC.


--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
doubts regarding dotnet reflection programming forvino@gmail.com ASP .Net 0 07-03-2005 03:23 PM
Datagrid columns using AutoGenerate via the autoGenColumnsArray private member array collection (reflection) Jason Coyne Gaijin42 ASP .Net 2 04-06-2004 01:24 PM
Reflection and COM Alan Seunarayan ASP .Net 3 01-14-2004 10:56 PM
[Reflection] Is it possible to Invoke a static method? [Gauthier] ASP .Net 2 12-03-2003 03:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57