groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ed Clark <eacl...@ameritech.net>
Subject more help with an AST
Date Tue, 11 Jul 2017 20:07:31 GMT
Hello All,

Let me go to the well one more time for help with my AST....

First, let me ask ---
    is there any reason the AST browser would lie and show you what you want to
    see and not what the compiler really does??

Sorry, that's harsh.  But, I've been staring that the AST browser for hours trying
to spot the difference between two lines of code - one that runs and one the blows
up - and I can't see any thing other than lineNumber/columnNumber differences.


Some background.  I want to replace some binary methods (like multiply and plus)
so I can play around and do them the way I want.  So, my AST goes through and
replaces binary method calls like "le * re" with "myCtx.multiply( le, re)".

Looking at the massaged code through the AST browser, it looks like my xform is
doing what it should - but the code won't execute.

Trying to get to a simple example, if I have two lines of code before xforming:

     sum = myCtx.multiply( le, re)          <------- the xform leaves this alone
     sum = le * re                                   <------- the xform changes this

the browser shows a post-xform output of:

     sum = myCtx.multiply( le, re)          <------- this executes
     sum = myCtx.multiply( le, re)          <------- this doesn't

But, when run, the first line works while the second one results in a
MissingMethodException stating there is no "multiply" method for the type
Complex - which is the type of "le".

It's as if the compiler tried to execute "le * re" (which would give exactly this MME)
and not "myCtx.multiply( le, re)".

Drilling down in the AST itself, I'm not seeing any difference - other than line
numbers and column numbers - between the various *Expressions
(e.g. VariableExpression) making up the subtrees for the two lines.


Obviously I'm doing something wrong.  But I can't see what it is.


Any suggestions?

Regards,

Ed Clark







Mime
View raw message