Re: [Pharo-users] Question on MetaLink: access to the calling MessageNode from a MethodNode

2019-12-18 Thread Marcus Denker



> On 18 Dec 2019, at 14:06, Mehrdad Abdi  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





[Pharo-users] Question on MetaLink: access to the calling MessageNode from a MethodNode

2019-12-18 Thread Mehrdad Abdi
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