[fpc-devel] [] property overloads
Ondrej Pokorny
lazarus at kluug.net
Tue Jul 2 09:16:57 CEST 2019
On 02.07.2019 08:17, Michael Van Canneyt wrote:
> On Tue, 2 Jul 2019, Ondrej Pokorny wrote:
>> I happened to study this part of FPC code back in 2015 when I worked
>> on issue #28820. I can say that FPC directly transfers indexed
>> properties
>
> Stop... How does FPC decide it is an indexed property ?
First of all I have to correct my notation (because I now re-checked FPC
sources).
"Indexed property" from FPC POV is a property with an index defined (
https://www.freepascal.org/docs-html/ref/refsu34.html ):
property X : Longint index 1 read GetCoord Write SetCoord;
- the property above is referred to as "indexed property" in FPC source
comments and it has the ppo_indexed option in tpropertyoptions.
Delphi documentation understands with "indexed property" the "array
property" - see
http://docwiki.embarcadero.com/RADStudio/Rio/en/Properties_(Delphi)
"Array properties are indexed properties":
property Objects[Index: Integer]: TObject read GetObject write SetObject;
I will now use the notation "array property" instead of the ambiguous
"indexed property".
---
Q: How does FPC decide it is an array property ?
This is simple. If the compiler encounters
MyTest.StringArray
it looks into the symtable. If a property is found (tpropertysym), it
calls the "compiler property handler procedure" handle_propertysym.
See
procedure handle_propertysym(propsym : tpropertysym;st : TSymtable;var
p1 : tnode);
in in pexpr.pas.
handle_propertysym checks if it is an array property (ppo_hasparameters
in tpropertysym.propoptions) - in this case the compiler expects some
parameters (even empty parameters are allowed) - see that the
"try_to_consume(_LECKKLAMMER)"=false result is silently ignored and also
it is not checked if paras are empty.
The compiler passes then the "paras" parameters to the getter/setter
call (that automatically searches for a valid method overload with the
used parameters).
Ondrej
More information about the fpc-devel
mailing list