source code of a block context

Marcus Denker denker at iam.unibe.ch
Mon Aug 8 20:10:41 UTC 2005


Am 08.08.2005 um 20:41 schrieb Houssam Fakih:

> Hi all,
>
>
> I’m looking for a method that extracts the source code of a block.  
> For instance If I have the following blockContext: [^ self] I need  
> a method that returns the following string: ‘^self’. Is there any  
> method in Squeak that does this job or I have to write a new one?
You could use the decompiler, so something like this:

BlockContext>>printSource
     ^String streamContents: [:str | self decompile  
printStatementsOn: aStream indent: 0]

But this would loose all comments and reformate the code... as it's  
decompiled.

Another thing you could do is to just use the decompiler to build up  
the mapping from
bytecode --> source. (aMethod methodNode sourceMap), and then copy  
the string
directly from the text using the offsets the encoder gives you.

Overall: These parts of Squeak are really strange, it's very old  
stuff that realy should
be redone cleanly. If we would have a good meta-model, stuff like  
that would be trivial
to do.

     Marcus


More information about the Squeak-dev mailing list