Question on MetaLink: access to the calling MessageNode from a MethodNode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on MetaLink: access to the calling MessageNode from a MethodNode

Mehrdad
Hello

For a specific method, I need to log some information when the method is called, like the state of the receiver, values of arguments, where the method is called, ... .

Using following MetaLink, I’m able to capture the receiver and arguments and context.

link := MetaLink new
                        metaObject: self;
                        selector:
                                #linkBeforeMethodArguments:receiver:selector:context:;
                        control: #before;
                        level: 0;
                        arguments: #( arguments receiver selector context ).
aMethod := MyClass methodNamed: #myMethodArg1:arg2.
aMethod ast link: link

For capturing the information related to where this method is called, It's possible to extract it from Context, but it’s a dirty way.
Is there any way to access the MessageNode which called this MethodNode?

Best regards,
Mehrdad
Reply | Threaded
Open this post in threaded view
|

Re: Question on MetaLink: access to the calling MessageNode from a MethodNode

Marcus Denker-4


> On 18 Dec 2019, at 14:06, Mehrdad Abdi <[hidden email]> wrote:
>
> Hello
>
> For a specific method, I need to log some information when the method is called, like the state of the receiver, values of arguments, where the method is called, ... .
>
> Using following MetaLink, I’m able to capture the receiver and arguments and context.
>
> link := MetaLink new
>        metaObject: self;
>        selector:
>        #linkBeforeMethodArguments:receiver:selector:context:;
>        control: #before;
>        level: 0;
>        arguments: #( arguments receiver selector context ).
> aMethod := MyClass methodNamed: #myMethodArg1:arg2.
> aMethod ast link: link
>
> For capturing the information related to where this method is called, It's possible to extract it from Context, but it’s a dirty way.
> Is there any way to access the MessageNode which called this MethodNode?
>
No, the information is only available via the context… even the #sender reification is internally is compiled to "thisContext sender receiver”.

You could add your own reification (that is a class similar to RFSenderReification and implement your own “sendingMethodNode” reification, but
this would just make it look nicer, not be different from an implementation point of view…

        Marcus