Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-09

Obtain Class hierarchy (in MacPas mode)

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adriaan van Os

I am looking for a way to obtain the class hierarchy of a program in MacPas mode (where there are no published properties). TObject has ClassParent, so a list of Class types would be sufficient, I think. I can't find however a routine in the RTL to obtain such a list.

Regards,

Adriaan van Os

Reply by email

Michael Van Canneyt
to Adriaan van Os
Adriaan van Os wrote
I am looking for a way to obtain the class hierarchy of a program in MacPas mode (where there are no published properties). TObject has ClassParent, so a list of Class types would be sufficient, I think. I can't find however a routine in the RTL to obtain such a list.

There is no such routine in the RTL, to my knowledge.

Michael.

Reply by email

Adriaan van Os
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
On Tue, 21 Sep 2010, Adriaan van Os wrote: > I am looking for a way to obtain the class hierarchy of a program in > MacPas mode (where there are no published properties). TObject has > ClassParent, so a list of Class types would be sufficient, I think. I > can't find however a routine in the RTL to obtain such a list. There is no such routine in the RTL, to my knowledge.

Can I add it ? I guess a low-level pointer to a list of VMT's would be sufficient to implement it ? That is, for object definitions that do have virtual methods ...

Regards,

Adriaan van Os

Reply by email

Florian Klaempfl
to Adriaan van Os
Adriaan van Os wrote 14 lines
Michael Van Canneyt wrote: > > > On Tue, 21 Sep 2010, Adriaan van Os wrote: > >> I am looking for a way to obtain the class hierarchy of a program in >> MacPas mode (where there are no published properties). TObject has >> ClassParent, so a list of Class types would be sufficient, I think. I >> can't find however a routine in the RTL to obtain such a list. > > There is no such routine in the RTL, to my knowledge. Can I add it ? I guess a low-level pointer to a list of VMT's would be sufficient to implement it ?

Problem is: it breaks smartlinking.

Reply by email

Michael Van Canneyt
to Adriaan van Os: Can I add it ? I guess a low-level pointer to a list of VMT's would be sufficient to…
Adriaan van Os wrote 15 lines
Michael Van Canneyt wrote: > > > On Tue, 21 Sep 2010, Adriaan van Os wrote: > >> I am looking for a way to obtain the class hierarchy of a program in >> MacPas mode (where there are no published properties). TObject has >> ClassParent, so a list of Class types would be sufficient, I think. I >> can't find however a routine in the RTL to obtain such a list. > > There is no such routine in the RTL, to my knowledge. Can I add it ? I guess a low-level pointer to a list of VMT's would be sufficient to implement it ? That is, for object definitions that do have virtual methods ...

Where do you want to add it ? What is the method declaration you'd use ?

Michael.

Reply by email

Michael Van Canneyt
to Florian Klaempfl: Problem is: it breaks smartlinking.
Florian Klaempfl wrote 17 lines
Am 21.09.2010 13:42, schrieb Adriaan van Os: > Michael Van Canneyt wrote: >> >> >> On Tue, 21 Sep 2010, Adriaan van Os wrote: >> >>> I am looking for a way to obtain the class hierarchy of a program in >>> MacPas mode (where there are no published properties). TObject has >>> ClassParent, so a list of Class types would be sufficient, I think. I >>> can't find however a routine in the RTL to obtain such a list. >> >> There is no such routine in the RTL, to my knowledge. > > Can I add it ? I guess a low-level pointer to a list of VMT's would be > sufficient to implement it ? Problem is: it breaks smartlinking.

Why? It's just walking the ParentClass hierarchy of a given class; which is what RTTI does anyway ?

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote 24 lines
On Tue, 21 Sep 2010, Florian Klaempfl wrote: > Am 21.09.2010 13:42, schrieb Adriaan van Os: >> Michael Van Canneyt wrote: >>> >>> >>> On Tue, 21 Sep 2010, Adriaan van Os wrote: >>> >>>> I am looking for a way to obtain the class hierarchy of a program in >>>> MacPas mode (where there are no published properties). TObject has >>>> ClassParent, so a list of Class types would be sufficient, I think. I >>>> can't find however a routine in the RTL to obtain such a list. >>> >>> There is no such routine in the RTL, to my knowledge. >> >> Can I add it ? I guess a low-level pointer to a list of VMT's would be >> sufficient to implement it ? > > Problem is: it breaks smartlinking. Why? It's just walking the ParentClass hierarchy of a given class; which is what RTTI does anyway ?

If I understood it right he wants the complete hierachy (or the complete class tree) which is used in a program. So the opposite of "ClassParent".

Regards,
Sven

Reply by email

Adriaan van Os
to Michael Van Canneyt: Why? It's just walking the ParentClass hierarchy of a given class; which is what RTTI…
Michael Van Canneyt wrote 20 lines
On Tue, 21 Sep 2010, Florian Klaempfl wrote: > Am 21.09.2010 13:42, schrieb Adriaan van Os: >> Michael Van Canneyt wrote: >>> >>> >>> On Tue, 21 Sep 2010, Adriaan van Os wrote: >>> >>>> I am looking for a way to obtain the class hierarchy of a program in >>>> MacPas mode (where there are no published properties). TObject has >>>> ClassParent, so a list of Class types would be sufficient, I think. I >>>> can't find however a routine in the RTL to obtain such a list. >>> >>> There is no such routine in the RTL, to my knowledge. >> >> Can I add it ? I guess a low-level pointer to a list of VMT's would be >> sufficient to implement it ? > > Problem is: it breaks smartlinking.

Yes, I understand that. I looked at the assembly generated for a simple test program and there are separate al_globals entries for each vmt and separate al_rtti entries for the vmt rtti. I asssume the very reason for the separate entries is smart linking.

Hm, I guess I can look at the data section of the executable but it would be highly dependant of the executable binary format.

Is it possible to produce a separate data section/entry that refers to all al_globals and/or all al_rtti entries without breaking smart-linking ?

Why? It's just walking the ParentClass hierarchy of a given class; which is what RTTI does anyway ?

And the other way round (from a class to each subclass).

Regards,

Adriaan van Os

Reply by email

Michael Van Canneyt
to Adriaan van Os: Yes, I understand that. I looked at the assembly generated for a simple test program and…
Adriaan van Os wrote 32 lines
Michael Van Canneyt wrote: > > On Tue, 21 Sep 2010, Florian Klaempfl wrote: > >> Am 21.09.2010 13:42, schrieb Adriaan van Os: >>> Michael Van Canneyt wrote: >>>> >>>> >>>> On Tue, 21 Sep 2010, Adriaan van Os wrote: >>>> >>>>> I am looking for a way to obtain the class hierarchy of a program in >>>>> MacPas mode (where there are no published properties). TObject has >>>>> ClassParent, so a list of Class types would be sufficient, I think. I >>>>> can't find however a routine in the RTL to obtain such a list. >>>> >>>> There is no such routine in the RTL, to my knowledge. >>> >>> Can I add it ? I guess a low-level pointer to a list of VMT's would be >>> sufficient to implement it ? >> >> Problem is: it breaks smartlinking. Yes, I understand that. I looked at the assembly generated for a simple test program and there are separate al_globals entries for each vmt and separate al_rtti entries for the vmt rtti. I asssume the very reason for the separate entries is smart linking. Hm, I guess I can look at the data section of the executable but it would be highly dependant of the executable binary format. Is it possible to produce a separate data section/entry that refers to all al_globals and/or all al_rtti entries without breaking smart-linking ?

Maybe when doing whole-program optimization as implemented by Jonas. I guess the WPO could be extended to generate the tree you want.

But under 'normal' compilation, I don't think it is possible to do as you ask without breaking the smartlinking stuff; the tree would of necessity contain all declared classes of all loaded units.

Michael.

Reply by email

Adriaan van Os
to Michael Van Canneyt
Michael Van Canneyt wrote 44 lines
On Tue, 21 Sep 2010, Adriaan van Os wrote: > Michael Van Canneyt wrote: >> >> On Tue, 21 Sep 2010, Florian Klaempfl wrote: >> >>> Am 21.09.2010 13:42, schrieb Adriaan van Os: >>>> Michael Van Canneyt wrote: >>>>> >>>>> >>>>> On Tue, 21 Sep 2010, Adriaan van Os wrote: >>>>> >>>>>> I am looking for a way to obtain the class hierarchy of a program in >>>>>> MacPas mode (where there are no published properties). TObject has >>>>>> ClassParent, so a list of Class types would be sufficient, I >>>>>> think. I >>>>>> can't find however a routine in the RTL to obtain such a list. >>>>> >>>>> There is no such routine in the RTL, to my knowledge. >>>> >>>> Can I add it ? I guess a low-level pointer to a list of VMT's would be >>>> sufficient to implement it ? >>> >>> Problem is: it breaks smartlinking. > > Yes, I understand that. I looked at the assembly generated for a > simple test program and there are separate al_globals entries for each > vmt and separate al_rtti entries for the vmt rtti. I asssume the very > reason for the separate entries is smart linking. > > Hm, I guess I can look at the data section of the executable but it > would be highly dependant of the executable binary format. > > Is it possible to produce a separate data section/entry that refers to > all al_globals and/or all al_rtti entries without breaking > smart-linking ? Maybe when doing whole-program optimization as implemented by Jonas. I guess the WPO could be extended to generate the tree you want. But under 'normal' compilation, I don't think it is possible to do as you ask without breaking the smartlinking stuff; the tree would of necessity contain all declared classes of all loaded units.

I implemented it now by looking at the Mach-O symbol table. It works like a charm (only classes that are actually used are listed and it doesn't break smart-linking).

If someone feels like implementing this for other binary formats (with the purpose of adding it to the rtl), I can donate the Mach-O source code under the usual license.

Regards,

Adriaan van Os

Reply by email