AST #copy behavior

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

AST #copy behavior

Mark Rizun
Hi guys!

I'm using AST really often, and recently stumbled on problem with copying an AST.
It doesn't copy stuff related to computing sourceInterval of AST, and I need it to copy:)

I know there are #deepCopy and #veryDeepCopy, but they are too heavy methods for AST, especially in my case, as I need to copy AST all the time.

Earlier, I discussed this problem with Marcus Denker. He suggested to fix #copy of AST (to be more accurate #postCopy).
If I want to copy stuff related to sourceInterval, I would have to implement #postCopy for each RBNode... differently.

RBProgramNode>>#postCopy
        super postCopy.
        properties := properties copy

So for each RBNode... it will be like:

RBNode...>>#postCopy
        super postCopy.
        "here some different code each time"

I'm just interested: What do you think about it?

Thanks,
Mark
Reply | Threaded
Open this post in threaded view
|

Re: AST #copy behavior

Thierry Goubier


2014-11-10 14:38 GMT+01:00 Mark Rizun <[hidden email]>:
Hi guys!

I'm using AST really often, and recently stumbled on problem with copying an
AST.
It doesn't copy stuff related to computing sourceInterval of AST, and I need
it to copy:)

I know there are #deepCopy and #veryDeepCopy, but they are too heavy methods
for AST, especially in my case, as I need to copy AST all the time.

Earlier, I discussed this problem with Marcus Denker. He suggested to fix
#copy of AST (to be more accurate #postCopy).
If I want to copy stuff related to sourceInterval, I would have to implement
#postCopy for each RBNode... differently.

RBProgramNode>>#postCopy
        super postCopy.
        properties := properties copy

So for each RBNode... it will be like:

RBNode...>>#postCopy
        super postCopy.
        "here some different code each time"

I'm just interested: What do you think about it?

The AST generated by SmaCC has a postCopy in the same way that you describe, so I'd say this is OK.

Just be precise about what you copy and what you don't copy. Can you say what will be copied and what won't?

Thierry
 

Thanks,
Mark



--
View this message in context: http://forum.world.st/AST-copy-behavior-tp4789447.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: AST #copy behavior

Mark Rizun

The AST generated by SmaCC has a postCopy in the same way that you describe, so I'd say this is OK.

That's good
 
Just be precise about what you copy and what you don't copy. Can you say what will be copied and what won't?

For instance, in RBMethodNode I want to copy replacements inst var.
Another example: for RBReturnNode - return and value inst vars.