Skip to content

Commit ecc37c0

Browse files
committed
codex: serialize symbolic parameter values
1 parent a10b399 commit ecc37c0

2,533 files changed

Lines changed: 72841 additions & 1587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ python -m x2py tests/data/fortran/general/basic_subroutine.f90 --parse --wrap-re
200200
```
201201

202202
This prints the wrappability status and blocker list for each input file.
203+
The JSON readiness payload keeps `wrappable` at file level and includes
204+
`unit_blockers` only for procedure/type/file units that own a blocker.
203205

204206
### Example 4: semantic IR JSON output
205207

@@ -463,12 +465,18 @@ helpers parse variables, procedure arguments/results, and type fields, then
463465
push them into the active scope. Procedure execution bodies and internal
464466
subprograms are ignored for wrapper metadata; procedure-local interfaces are
465467
retained for callback typing.
466-
Parameter variables keep both `value` (best resolved value) and runtime
467-
`symbolic_value` (the original expression) when the parser has that information.
468+
Parameter variables keep both `value` and serialized `symbolic_value` when the
469+
parser has that information. `value` is literal/evaluated only; if an
470+
initializer cannot be evaluated safely, `value` is `None` and
471+
`symbolic_value` keeps the original expression.
468472
Module-level parameters used in procedure argument shapes remain symbolic in
469473
the signature while still being valid scoped references for readiness checks.
470474

471475
The semantics layer consumes `FortranFile`/`FortranModule` objects and projects them into language-independent semantic IR (`SemanticModule`, `SemanticFunction`, `SemanticClass`, `SemanticType`). This keeps the semantic API model independent from parser internals, matching the project goal that parser output is a helper and the semantic interface/IR is the source of truth.
476+
For compiler-specific constants, use
477+
`collect_semantic_compile_time_requirements(parsed)` to extract unresolved
478+
values and pass a dictionary to semantic conversion via
479+
`compile_time_values`.
472480

473481
For Fortran `use` imports, the parser stores each explicit imported symbol as a
474482
source/target mapping. A non-renamed `use iso_c_binding, only: c_int` maps

fortran_parser.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ and practical usage from terminal and Python.
6767
- Unsupported-pattern checks
6868
- Unknown argument declaration reporting
6969
- Final boolean readiness (`wrappable`)
70+
- Unit-scoped blocker records (`unit_blockers`) for wrapper-relevant
71+
procedures and derived types, plus file-level blockers when diagnostics are
72+
not owned by a single unit. The ready-to-wrap flag remains file-level only.
7073

7174
## 2) Public API surface
7275

@@ -173,11 +176,12 @@ actual declarations.
173176
Most parser organization changes are structural, but behavior, model-schema,
174177
coverage, or fixture changes should be reflected in this reference.
175178

176-
Parameter constants expose both `value` and runtime `symbolic_value` when
177-
available. `value` is the parser's best resolved expression after compile-time
178-
folding; `symbolic_value` preserves the original parameter initializer for
179-
validation, debugging, and downstream diagnostics without changing the legacy
180-
JSON fixture shape.
179+
Parameter constants expose both `value` and serialized `symbolic_value` when
180+
available. `value` is reserved for a literal/evaluated result after
181+
compile-time folding. If an initializer cannot be evaluated safely, such as
182+
`selected_real_kind(...)`, `value` is `None` and `symbolic_value` preserves the
183+
original initializer for validation, debugging, downstream diagnostics, and
184+
JSON consumers.
181185

182186
Procedure-local parameters may be folded into argument shapes during procedure
183187
finalization. Module-level and `use`-associated parameters used in procedure
@@ -471,7 +475,8 @@ Expected behavior:
471475

472476
- `parsed` is a `FortranFile` aggregate model with parsed units and symbols.
473477
- `readiness` includes counts, unsupported hits, unknown args, unresolved
474-
imported derived-type/kind dependencies, and `wrappable`.
478+
imported derived-type/kind dependencies, unit-scoped blockers, and the
479+
file-level `wrappable` flag.
475480

476481
### 4.3 Structured argument specifications
477482

@@ -955,3 +960,13 @@ Lower-level unit parsers are internal `FortranParser` methods.
955960
Semantic conversion lives in `semantics/fortran2ir.py`. It accepts parsed `FortranFile`
956961
(or selected `FortranModule`) structures and converts metadata into semantic IR
957962
consumed by the `.pyi` printer and later wrapper/runtime stages.
963+
964+
The semantic converter also supports compile-time specialization for values the
965+
parser intentionally leaves symbolic. Use
966+
`collect_semantic_compile_time_requirements(parsed)` to list missing parameter
967+
or kind values, then pass a dictionary such as
968+
`{"selected_real_kind(12)": 8}` to
969+
`fortran_module_to_semantic_module(..., compile_time_values=...)` or
970+
`fortran_file_to_semantic_modules(..., compile_time_values=...)`. Existing
971+
semantic IR can be copied and specialized with
972+
`resolve_semantic_compile_time_values(module, {"n": 64})`.

fortran_parser/models.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class FortranVariable:
208208
lbound: list[str | None] = field(default_factory=list)
209209
ubound: list[str | None] = field(default_factory=list)
210210
value: str | None = None
211+
symbolic_value: str | None = None
211212
value_type: str = "unknown"
212213
is_parameter: bool = False
213214
dimensions: list[int] = field(default_factory=list)
@@ -217,14 +218,6 @@ def __post_init__(self) -> None:
217218
if self.kind is None:
218219
self.kind = ""
219220

220-
@property
221-
def symbolic_value(self) -> str | None:
222-
return getattr(self, "_symbolic_value", None)
223-
224-
@symbolic_value.setter
225-
def symbolic_value(self, value: str | None) -> None:
226-
self._symbolic_value = value
227-
228221
@property
229222
def shape_info(self) -> list[dict[str, str | None]]:
230223
"""Structured per-dimension shape metadata derived from `shape` tokens."""

0 commit comments

Comments
 (0)