[code-reflection] RFR: Regularize parsing of refs/types in op attributes
Paul Sandoz
psandoz at openjdk.org
Tue May 27 17:45:04 UTC 2025
On Mon, 26 May 2025 11:41:15 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This PR builds on https://git.openjdk.org/babylon/pull/432 and simplifies the way in which the various op factories handle attributes that are either `JavaRef` or `JavaType`.
> Previously, such attribute values were written as strings -- and then the op factory would need to parse them back using one of the `JavaType::ofString`, or `XYZRef::ofString` parsing factories.
>
> In this PR, type elements are serialized into strings using `TypeElement::externalize` (as usual, we also apply flattening, to turn the external forms into something more readable).
> When parsing back, we then check whether we're staring at an externalized form or not. If so, we parse it back, we inflate it and turn it back into a `TypeElement` using the selected type factory.
>
> As a result op factories can just work on type elements directly, all the parsing will already have occurred at that point. This simplfies the op factory code, and, crucially, allows us to drop the various `ofString` factories. This means that the code model API no longer relies on the textual form of Java types/refs.
>
> #### Next steps
> * enhance attribute parsing to special case all Java literals (so that we can drop even more parsing in the common cases)
> * unify grammar between attributes and types
Looks good.
-------------
PR Review: https://git.openjdk.org/babylon/pull/433#pullrequestreview-2871992553
More information about the babylon-dev
mailing list