[code-reflection] RFR: Support storing the code that builds the code model [v18]

Mourad Abbay mabbay at openjdk.org
Sat Mar 15 02:53:03 UTC 2025


On Sat, 15 Mar 2025 02:48:49 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

>> src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/CodeModelToAST.java line 222:
>> 
>>> 220:         // TODO add VarOps in OpBuilder
>>> 221:         funcOp = addVarsWhenNecessary(funcOp);
>>> 222:         funcOp.writeTo(System.out);
>> 
>> This should be removed?
>
> `addVarsWhenNecessary` is used to add necessary VarOp in the code model before transformation to AST. For example if an op result is used more than once, we introduce a VarOp to hold the value, because that's what the equivalent Java code will have. This makes the transformation from code model to AST a bit easier.
> We also use it to in case we want an Op (e.g. InvokeOp) to be appended right away to the method we are building. As you now the block of a method is a list of statements, some operations maps to an expression, so they won't be appended until needed.

Normally, the OpBuilder should produces a model that contains the VarOp when they should be. But I decided to have a seperate transformation as a quick fix. Later I will change the OpBuilder.

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/305#discussion_r1996526723


More information about the babylon-dev mailing list