[fpc-devel] RTTI generating
Michael Van Canneyt
michael at freepascal.org
Fri Sep 19 12:44:04 CEST 2014
On Fri, 19 Sep 2014, Adriaan van Os wrote:
>
> This is a copy of a post on the macpascal mailing list, where it was
> suggested to re-ask on the fpc-devel list.
>
> -----
>
> The RTTI generating logic in the FPC compiler puzzles me ....
>
> Chapter 40 of FreePascal Run-Time Library Reference guide describes the
> typinfo unit. It says
>
> ; The TypeInfo unit contains many routines which can be used for the querying
> of the Run-Time
> ; Type Information (RTTI) which is generated by the compiler for classes that
> are compiled under the
> ; {$M+} switch
>
> Great so far !
>
> ; This information can be used to retrieve or set property values for
> published properties
> ; for totally unknown classes. In particular, it can be used to stream
> classes
>
> This is what I fail to understand. Why is RTTI information tied to properties
> and why is it restricted to what is in the published/public sections of classes (or objects
> in macpas mode) ?
Because the Delphi specs - at the time - said that RTTI is generated only for published sections.
> For
> example, when I want to implement an object browser for debugging purposes, I
> want to see anything.
RTTI cannot be used for this, you need debug info for that.
RTTI is not a substitute for debug info.
Your remarks seem to imply that you think RTTI can be used to inspect any aspect of an object.
It was/is not meant for that.
> What I am allowed in the code to do with the methods and fields is irrelevant
> and whether fields are properties or not is irrelevant too.
Of course it is relevant. Properties may use getters, fields cannot.
RTTI is not restricted to property values.
It says "can be used to retrieve or set property values for published properties for totally unknown classes"
That implies that it can be used for other things as well (as indeed it is).
But only for published sections. Since RTTI cannot be generated for any type (a Delphi spec),
the list of types that can be used in a published section is restricted.
(basically, anything non-structured that fits in a pointer)
> When I try it, $M+ refuses public non-property class fields. With $M-
> ClassInfo, GetTypeData and
> the ParentInfo field work. However, FieldAddress and MethodName do not work.
Can you post some sample code, because I do not understand these sentences ?
> The field count in the FieldTable field of the VMT is 0.
> Is there a special reason why the compiler can't fill in the VMT's FieldTable ?
I think the compiler people need to confirm this, but I think the FieldTable is not used in FPC ?
At least, I know of no use for this table, it probably exists for Delphi compatibility.
> Jonas Maebe replied that RTTI information has been implemented according to
> Delphi conventions. Marco van de Voort mentioned D2010 and work being done on
> the extended RTTI ($RTTI directive). Paul Ishenin remembered Joost
> implemented some prototype in a branch, that had some problems and was not
> merged to trunk yet.
This is all correct.
Michael.
More information about the fpc-devel
mailing list