Hi, I know that I can see senders and implementers of a method but is there
any way to see all methods that are used in a method ? or any way to see all the send messages to other methods limited to scope of a method ? Thanks, Aria -- View this message in context: http://forum.world.st/Seeing-all-the-methods-that-is-used-in-a-method-tp4772098.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
2014-08-07 5:11 GMT+02:00 aria2end <[hidden email]>:
This is impossible. The method called for each message send can only been known at runtime, because it depends on the receiver class. The only thing you could see is the list of selectors (name of methods) called from this method. This is possible by sending #messages to the compiledMethod.
Example: you have a method named #foo:bar: implemented in MyClass: MyClass>>foo: arg1 bar: arg2 ^ self baz: arg1 + arg2
You can open a workspace, and run: (MyClass >>#foo:bar:) messages which answers: a Set(#baz: #+) but you cannot see the methods called, because depending on the class of arg1, the method called for #+ may be any of these methods: AJMem>>#+ Collection>>#+ Color>>#+ DateAndTime>>#+ Duration>>#+ Float>>#+ FloatArray>>#+ Fraction>>#+ Integer>>#+ Interval>>#+ KMComposedModifier>>#+ KMKeyCombinationSequence>>#+ KMModifier>>#+ KMNoShortcut>>#+ LargeInteger>>#+ Number>>#+ Point>>#+ ROAbstractComponent>>#+ ROShape>>#+ ROShape class>>#+ ScaledDecimal>>#+ SmallInteger>>#+ String>>#+ Timespan>>#+ TraitComposition>>#+ TraitDescription>>#+ TraitTransformation>>#+ WordArray>>#+ TComposingDescription>>#+ Or perhaps you want to see all the potential methods called. Then you can open a workspace and run this script: | methods mb |
methods := ((CompiledMethod>>#foo:bar:) messages collect: [ :selector | selector implementors ]) flattened. mb := MethodBrowser new.
mb openWithSpec. mb methods: methods
all the send messages to other methods ? Well for that you'll need type inference to find out which variables are actually methods, and then see what messages are sent to those variables. But why would one want to do that ?
|
Marcus has shown me previously ast with nodesDo: for example this code show me the full ast for my class method blenderOpen of my class Ephestos. (Ephestos class compiledMethodAt: #blenderOpen ) ast nodesDo: [ :node| node inspect] and it opens one inspector per node messages that are "method calls" are nodes of RBMessageNode class. I see a instance variable "selector" which returns the name of the selector and an instance variable "receiver" returns the name of the receiver. Instance variable "parent" describes the container of the message . For example in my case the only RBMessageNode is contained inside a variable assignment.
So I think its a good start for finding "method calls" messages. On Thu, Aug 7, 2014 at 11:18 AM, Clément Bera <[hidden email]> wrote:
|
cant you also use the ast to find out how exactly Pharo which object and which method it executes ? On Thu, Aug 7, 2014 at 11:39 AM, kilon alios <[hidden email]> wrote:
|
In reply to this post by Clément Béra
Yes Exactly. I want to see all the potential methods called from from this method which is the second case. but I receive error using that script.
MessageNotUnderstood: ByteSymbol>>implementors |
In reply to this post by kilon.alios
Hi, I would suggest that you take a look at the support from GTInspector to understand the AST. For that, you can just download the latest moose image (https://ci.inria.fr/moose/job/moose-5.0/lastSuccessfulBuild/artifact/moose-5.0.zip) and inspect your method. You will get multiple views on that method including the AST and a preview of the sources. See the picture from the attachment.
Cheers, Doru
On Thu, Aug 7, 2014 at 10:39 AM, kilon alios <[hidden email]> wrote:
"Every thing has its own flow"
|
In reply to this post by kilon.alios
On 07 Aug 2014, at 10:41 , kilon alios <[hidden email]> wrote: > cant you also use the ast to find out how exactly Pharo which object and which method it executes ? No. Consider: #do: aBlock aBlock value Finding the methods actually executed by this is a hard problem. You’d at least need inferred types (to find the values of block that are actually sent to THIS #do: implementation) to even attempt to make a somewhat accurate prediction. Cheers, Henry signature.asc (859 bytes) Download Attachment |
In reply to this post by aria2end
2014-08-07 10:47 GMT+02:00 aria2end <[hidden email]>: Yes Exactly. I want to see all the potential methods called from from this Ok this method is implemented in the image I use (Pharo-40151). The code is Symbol>>implementors ^SystemNavigation new allImplementorsOf: self
Sorry I didn't know this code was not in Pharo 3.
|
In reply to this post by Henrik Sperre Johansen
as far I can see with my test its returns a RBlockNode and all the code of the node is contained inside as regular nodes. Sure its not exactly simple to do, you will have to refactor through the classes to see which class corresponds to which message but looks doable to me and not very hard to do. I would go through each node and find the ones that are messages then ask the class of the receiver and search for the selector and then iterate through super classes if I cannot find it. Same thing that Pharo already does with message passing.
Do I miss something here ? On Thu, Aug 7, 2014 at 11:53 AM, Henrik Johansen <[hidden email]> wrote:
|
In reply to this post by aria2end
which post?
We received several post from you. As soon as you register to the mailing, sending a mail with the correct account publish mails to the mailing-lists. On 7/8/14 04:52, aria2end wrote: > why is it that my post is not yet accepted by the mailing list yet. what > should I do ? > > > > -- > View this message in context: http://forum.world.st/Seeing-all-the-methods-that-is-used-in-a-method-tp4771587p4772097.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > > |
Free forum by Nabble | Edit this page |