[code-reflection] RFR: Regularize parsing of refs/types in op attributes

Maurizio Cimadamore mcimadamore at openjdk.org
Mon May 26 11:46:48 UTC 2025


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

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

Commit messages:
 - Drop unused imports
 - Fix examples
 - Drop ofString factories and fix up tests
 - Merge branch 'code-reflection' into remove_of_string_type_factories
 - All tests pass
 - Fix examples
 - Simplify JavaTypeUtils to use ExternalizedTypeElement factories
 - Enhance type factory to create refs
 - Merge branch 'code-reflection' into externalized_Java_type_cleanup
 - Simplify parser code to use `Lexer::is`
 - ... and 16 more: https://git.openjdk.org/babylon/compare/4278b5b4...6cd1e041

Changes: https://git.openjdk.org/babylon/pull/433/files
  Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=433&range=00
  Stats: 729 lines in 49 files changed: 48 ins; 37 del; 644 mod
  Patch: https://git.openjdk.org/babylon/pull/433.diff
  Fetch: git fetch https://git.openjdk.org/babylon.git pull/433/head:pull/433

PR: https://git.openjdk.org/babylon/pull/433


More information about the babylon-dev mailing list