[fpc-devel] Default properties

Sven Barth pascaldragon at googlemail.com
Fri Sep 7 13:27:44 CEST 2018


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Fr., 7. Sep. 2018,
11:59:

> I’m moving my technical questions about default properties here so I don’t
> clutter up the other list. I’m still new to the compiler please bear with
> me.
>
> The first problem I’m having is how to resolve duplicate functions with
> overloads. For example in TWrapper there’s multiple overloads for DoThis
> and we need to determine if TWrapper.DoThis should use TWrapper or the
> THelperA from the default property.
>
> type
>         THelperA = record
>                 procedure DoThis;
>         end;
>
> type
>         TWrapper = record
>                 objA: THelperA;
>                 property helperA: THelperA read objA write objA; default;
>                 procedure DoThis(param: integer); overload;
>                 procedure DoThis(param: string); overload;
>         end;
>
>
> var
>         wrapper: TWrapper;
> begin
>         wrapper.DoThis(1);      // DoThis is from TWrapper but how can we
> determine this?
>
>
>
> What I’m narrowing in on is:
>
> in pexpr.pas do_member_read() takes the load node and converts it to a
> call node and this is where I need to determine what definition the
> function belongs to. So in the example above we get “DoThis” how can we
> determine if TWrapper or THelperA has a matching function with matching
> parameters? searchsym_in_record usually returns the correct definition but
> I need to scan 2 possible definitions instead of just the first one
> specified in the load node.
>
> do_proc_call() parses parameters into a tcallparanode which is good.
>
> do_typecheckpass on the tcallnode from do_proc_call() will find procsym
> candidates in the record def which the node was created with. I would use
> this to query but it forces a syntax error which isn’t what I want.
>
> Hopefully that makes sense. So my question is, is there an existing way to
> search a tabstractrecorddef given a name and parameter list and return a
> found or not found answer? I could start pulling stuff out of
> do_typecheckpass() but I suspect there’s already a way to do this.
>

tcallcandidates in htypechk.pas is your friend. That is the *only* class
that deals with overload resolution and collects the eligible overloads
from various sources (e.g. loaded units, current type, helper types).
Essentially you only need to search for a procsym with the name of method
inside the default field (all proceeds with the same name share the same
procsym) and pass that on, the remainder of tcallcandidates will deal with
overload resolution (you only need to make sure that the correct "Self",
namely the default field is picked for that).

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180907/ea997aab/attachment.html>


More information about the fpc-devel mailing list