|
26 | 26 | file/project models. |
27 | 27 |
|
28 | 28 | Recommended reading order for maintainers: |
29 | | -- Start from `FortranParser.visit_file` / `visit_project` |
| 29 | +- Start from the module-level public wrappers (`parse_fortran_file`, |
| 30 | + `parse_fortran_project`, `assess_wrap_readiness`) |
| 31 | +- Then read `FortranParser.visit_file` / `visit_project` |
30 | 32 | - Then read the high-level unit visitor methods at the top of the class |
31 | 33 | - Then drill into `_helper_*` implementations and low-level helpers |
32 | 34 |
|
33 | 35 | `FortranParser` class layout (top -> bottom): |
34 | | -- Visitor API: `visit_file`, `visit_project`, `visit_wrap_readiness`, plus |
35 | | - small `visit_*_unit` methods for each already-sliced source unit. |
| 36 | +- Internal visitor entrypoints: `visit_file`, `visit_project`, |
| 37 | + `visit_wrap_readiness`, plus small `visit_*_unit` methods for each |
| 38 | + already-sliced source unit. The stable public API is the module-level wrapper |
| 39 | + layer at the bottom of the file. |
36 | 40 | - Core `_helper_*` methods for source slicing, grammar-region splitting, |
37 | 41 | scoped specification-part visits, declaration parsing, symbol pushing, |
38 | 42 | preprocessor branch selection, and same-level duplicate checks. |
@@ -1629,33 +1633,48 @@ class FortranParser: |
1629 | 1633 |
|
1630 | 1634 | State carried on the instance: |
1631 | 1635 | - `macro_defines`: optional macro-selection configuration used while |
1632 | | - collecting procedures when conditional branches are present. |
| 1636 | + selecting preprocessor branches before source-unit slicing. |
1633 | 1637 |
|
1634 | 1638 | Parsing pipeline used by `visit_file`: |
1635 | 1639 | 1. Preprocess source into normalized lines (`_preprocessed_lines`). |
1636 | | - 2. Parse signatures/types/interfaces/program units. |
1637 | | - 3. Attach parsed members to owning module/submodule scopes. |
1638 | | - 4. Build `FortranFile` symbol table and standalone entity lists. |
| 1640 | + 2. Slice direct file-level source units (`module`, `submodule`, |
| 1641 | + `program`, standalone `procedure`, `block data`, file-level |
| 1642 | + `interface`, and file-level derived type). |
| 1643 | + 3. Dispatch each `_SourceUnit` to a small `visit_*_unit` method. |
| 1644 | + 4. Each unit visitor parses only that unit's own substring, builds its own |
| 1645 | + `_ParserScope`, splits the unit into grammar regions, visits the |
| 1646 | + specification part, and recursively slices direct children where the |
| 1647 | + grammar allows them. |
| 1648 | + 5. Shared declaration helpers push variables, procedure symbols, and type |
| 1649 | + fields into the active scope model. |
| 1650 | + 6. Build `FortranFile` symbol table and standalone entity lists. |
1639 | 1651 |
|
1640 | 1652 | Class section map: |
1641 | | - - Public API methods first (developer discovery). |
1642 | | - - High-level unit parsing methods next (top-down by Fortran block size). |
1643 | | - - Internal `_helper_*` methods after that (full scoped parsing logic). |
| 1653 | + - Internal visitor entrypoints first (developer discovery). |
| 1654 | + - Unit visitors next (one visitor per grammar-level source unit). |
| 1655 | + - Internal `_helper_*` methods after that (reusable scoped parsing logic). |
1644 | 1656 | - Lower-level declaration/header helpers and assembly utilities last. |
1645 | 1657 |
|
1646 | 1658 | Scope behavior summary: |
1647 | | - - `current_module` tracks ownership for procedures/types/interfaces. |
1648 | | - - `interface_depth`/stacks track when declarations belong to interface blocks. |
1649 | | - - Per-procedure state tracks declaration-part vs executable-part boundaries. |
1650 | | - - Type parsing tracks `contains` sub-region for bindings/generics vs fields. |
1651 | | - - Program/module/submodule parsers collect specification-part declarations |
1652 | | - and stop collecting variable declarations after `contains`. |
| 1659 | + - `_ParserScope` is passed explicitly into shared helpers; there is no |
| 1660 | + ambient `current_module` or interface stack. |
| 1661 | + - Module/submodule scopes own contained procedures, interfaces, and derived |
| 1662 | + types; program and block-data scopes collect their specification |
| 1663 | + variables only. |
| 1664 | + - Procedure scopes parse only wrapper-relevant specification declarations; |
| 1665 | + execution statements and internal procedures after `contains` are |
| 1666 | + ignored, except procedure-local interfaces are revisited to type callback |
| 1667 | + dummy arguments. |
| 1668 | + - Derived-type scopes parse fields in the specification region and |
| 1669 | + type-bound procedure/generic bindings in the `contains` region. |
| 1670 | + - Same-level unit names are validated by the slicer with preprocessor |
| 1671 | + branch-awareness, while identical names in different scopes remain valid. |
1653 | 1672 |
|
1654 | 1673 | `visit_project` composes multiple `FortranFile` objects into one |
1655 | 1674 | `FortranProject` registry and validates duplicate symbols by scope. |
1656 | 1675 | """ |
1657 | 1676 | # ------------------------------------------------------------------ |
1658 | | - # Public API (kept first for discoverability) |
| 1677 | + # Internal visitor entrypoints (kept first for developer discovery) |
1659 | 1678 | # ------------------------------------------------------------------ |
1660 | 1679 |
|
1661 | 1680 | def __init__(self, macro_defines: set[str] | dict[str, int | bool | str] | None = None): |
|
0 commit comments