groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ed Clark <>
Subject Re: help with an AST
Date Tue, 14 Feb 2017 17:58:58 GMT
On 02/14/2017 12:16 PM, Jochen Theodorou wrote:
> On 14.02.2017 12:41, Ed Clark wrote:
>> Hi Jochen,
>> Well, I've been slowly making progress on this; kind of feels like
>> bashing my
>> head against a wall at times, but I have made a small hole in the wall
>> through
>> which I can see my goal. ;-)
> making holes my lead to brain damage.. then things get really hard to solve ;)
Maybe I'm too late, and that's why things aren't coming together ;)

> [...]
>> Specifically, I haven't figured out how to inject a variable into the
>> scope of an outer
>> with's closure that can be used by code in an interior with's closure.
>> For example,
>> consider
>>   myCtx1.with {
>>       __outerCtx1 = null            // injected statement
>>       __currCtx1 = myCtx1       // injected statement
>>       .... some code ...
>>       myCtx2.with {
>>           __outerCtx2 = __currCtx1   // injected statement <---  doesn't
>> work
>>           __currCtx2 = myCtx2          // injected statement
> where is __currCtx1 and __outerCtx1 coming from? Are they supposed to be new local variables?
> that case you will have to add a DeclarationStatement, not just an assignment to a 
> VariableExpression. Otherwise the compiler will thnk they are dynamic properties and
tries to 
> resolve them against the context.
> as for the logic behind __outerCtxN... with number wouldn't have to be null I would have
said you 
> should think of using getOwner on Closure
Hmmm, I'm close to that, but not quite the same.  I was trying

    ExpressionStatement currCtx = new ExpressionStatement(
        new DeclarationExpression (
            new VariableExpression( "__currCtx$levelcnt"),
            new Token( Types.ASSIGNMENT_OPERATOR, "=", -1, -1),
            new MethodCallExpression( new VariableExpression( 'this'), 'getDelegate', new


Would a DeclarationStatment act differently from an ExpressionStatement with an embedded
DeclarationExpression?  If my foggy memory is correct, I wrote my code after looking at the
AST displayed for a short test script in groovyConsole.

Plus, if foggy memory serves, I tried using getOwner and it came back with the closure being
owned by the test script, not the object doing the with.  Calling getDelegate gave me the
If foggy memory serves.

I also tried playing around with setClosureSharedVariable( true) and putReferencedLocalVariable()
without success.  But, those were somewhat blind stabs in the dark, so I might not have been
using them correctly.

Looking at the AST generated by groovyConsole, my transform looks like it is working, but
the compiler complains about things not being in scope (in the inner closure).  So, I'm doing
something wrong with setting up the scoping.

>  bye Jochen



View raw message