[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] ParseTreeRewriter refactoring

From: Stephen Compall
Subject: Re: [Help-smalltalk] ParseTreeRewriter refactoring
Date: Fri, 12 Jan 2007 03:48:05 -0600

On Fri, 2007-01-12 at 09:13 +0100, Paolo Bonzini wrote:
> > Might visitNodeList:visitor:onMatch: also be included and used where
> > relevant?  This gives just enough dynamism that my rewriter subclass
> > works without overriding accept*:.
> Ok, so here's my take.
> As far as I understood, what you want is to not use the new instance if 
> nothing changed in the parse tree.  Which seems good.

It also allows visitNode*:*: et al to customize the context in which
replacements are delivered to their final containing slots.

>  lookForMoreMatchesInContext: oldContext 
> -    oldContext keysAndValuesDo: 
> -         [:key :value | 
> -         (key isString not and: [key recurseInto]) 
> -             ifTrue: 
> -                 [oldContext at: key put: (value collect: [:each | self 
> visitNode: each])]]! !
> +    oldContext keysAndValuesDo: [:key :value || newValue |
> +     (key isString not and: [key recurseInto]) ifTrue: [
> +         "Of course, the following statement does nothing without the 
> `deepCopy'
> +          which fixes the bug."
> +         newValue := oldContext at: key put: value "deepCopy <<<".

Please don't use deepCopy here; it copies too much data from the
original tree.  collect: [:node | node copy] does exactly the right
thing in both the single-node and node-collection cases.

> +visitNodes: aNodeList
> +    ^self visitNodes: aNodeList searches: searches onMatch: [:newNodes |]!

Why does this inline visitNodes:onMatch:?  (As with visitArguments:.)

Stephen Compall

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

[Prev in Thread] Current Thread [Next in Thread]