How to remove method body?

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

How to remove method body?

Stephane Ducasse-3
Hi

to prepare some code for students I want to convert methods into a
kind of method skeleton
ie

printOn: aStream
    "super nice comment"
lk;lk;
    kl;;kl
    k;lkl;k
    ^ 42

into

printOn: aStream
    "super nice comment"
    ^ self

any idea?

In the past I know that we could access the method comment but I do
not find how to access the method signature (selector + variables).

So I'm trying at the AST level.

((ObjSkeletonMock >> #methodToSkeletonize2) ast body:
(ObjSkeletonMock >> #returnSelf) ast body).

But I do not get how I can recompile this.

Stef

Reply | Threaded
Open this post in threaded view
|

Re: How to remove method body?

Steven Costiou-2

Hi,

just after your modifications, from the compiled method try:

ObjSkeletonMock compile: self ast newSource

Maybe not the most elegant but it works.

 

Steven.

Le 2017-12-03 22:31, Stephane Ducasse a écrit :

Hi

to prepare some code for students I want to convert methods into a
kind of method skeleton
ie

printOn: aStream
    "super nice comment"
lk;lk;
    kl;;kl
    k;lkl;k
    ^ 42

into

printOn: aStream
    "super nice comment"
    ^ self

any idea?

In the past I know that we could access the method comment but I do
not find how to access the method signature (selector + variables).

So I'm trying at the AST level.

((ObjSkeletonMock >> #methodToSkeletonize2) ast body:
(ObjSkeletonMock >> #returnSelf) ast body).

But I do not get how I can recompile this.

Stef

 

--
kloum.io
Reply | Threaded
Open this post in threaded view
|

Re: How to remove method body?

Steven Costiou-2

For example that works for me:

|ast|
ast := (MyClass >> #printOn:) ast.
ast body: (MyClass >> #returnSelf) ast body.
MyClass compile: ast newSource

Le 2017-12-03 23:42, Steven Costiou a écrit :

Hi,

just after your modifications, from the compiled method try:

ObjSkeletonMock compile: self ast newSource

Maybe not the most elegant but it works.

 

Steven.

Le 2017-12-03 22:31, Stephane Ducasse a écrit :

Hi

to prepare some code for students I want to convert methods into a
kind of method skeleton
ie

printOn: aStream
    "super nice comment"
lk;lk;
    kl;;kl
    k;lkl;k
    ^ 42

into

printOn: aStream
    "super nice comment"
    ^ self

any idea?

In the past I know that we could access the method comment but I do
not find how to access the method signature (selector + variables).

So I'm trying at the AST level.

((ObjSkeletonMock >> #methodToSkeletonize2) ast body:
(ObjSkeletonMock >> #returnSelf) ast body).

But I do not get how I can recompile this.

Stef

 

--
kloum.io

 

--
kloum.io
Reply | Threaded
Open this post in threaded view
|

Re: How to remove method body?

Stephane Ducasse-3
Thanks steven

I was finally doing

| newTree |
newTree :=
(ObjSkeletonMock >> #methodToSkeletonize2) ast body:
(ObjSkeletonMock >> #returnSelf) ast body.
newTree formattedCode.
ObjSkeletonMock compile: newTree formattedCode classified: #foo



On Sun, Dec 3, 2017 at 11:45 PM, Steven Costiou <[hidden email]> wrote:

> For example that works for me:
>
> |ast|
> ast := (MyClass >> #printOn:) ast.
> ast body: (MyClass >> #returnSelf) ast body.
> MyClass compile: ast newSource
>
> Le 2017-12-03 23:42, Steven Costiou a écrit :
>
> Hi,
>
> just after your modifications, from the compiled method try:
>
> ObjSkeletonMock compile: self ast newSource
>
> Maybe not the most elegant but it works.
>
>
>
> Steven.
>
> Le 2017-12-03 22:31, Stephane Ducasse a écrit :
>
> Hi
>
> to prepare some code for students I want to convert methods into a
> kind of method skeleton
> ie
>
> printOn: aStream
>     "super nice comment"
> lk;lk;
>     kl;;kl
>     k;lkl;k
>     ^ 42
>
> into
>
> printOn: aStream
>     "super nice comment"
>     ^ self
>
> any idea?
>
> In the past I know that we could access the method comment but I do
> not find how to access the method signature (selector + variables).
>
> So I'm trying at the AST level.
>
> ((ObjSkeletonMock >> #methodToSkeletonize2) ast body:
> (ObjSkeletonMock >> #returnSelf) ast body).
>
> But I do not get how I can recompile this.
>
> Stef
>
>
>
> --
> kloum.io
>
>
>
> --
> kloum.io