The Fortran syntax representation we use is highly mutually recursive. To summarise the core types:
a ProgramFile contains many
ProgramUnits, which contain
Blocks, which contain
Statements, which contain
Expressions.
However, as of 2022-05-11, Expressions are mutually recursive with ProgramUnits. This can introduce surprises, and makes instance derivation awkward. In particular, generic derivation likely won't work unless every type up to ProgramUnit also has an instance derived.
It would be more sensible to limit the two-way recursion where possible. Note there might be some unexpected behaviour by doing so. For example, Expressions are only connected to Statements through one constructor -- altering a data type stored in there removes the mutual recursion, but caused issues with block/flow analysis https://github.com/camfort/fortran-src/pull/221 .
The Fortran syntax representation we use is highly mutually recursive. To summarise the core types:
ProgramFile
contains manyProgramUnit
s, which containBlock
s, which containStatement
s, which containExpression
s.However, as of 2022-05-11,
Expression
s are mutually recursive withProgramUnit
s. This can introduce surprises, and makes instance derivation awkward. In particular, generic derivation likely won't work unless every type up toProgramUnit
also has an instance derived.It would be more sensible to limit the two-way recursion where possible. Note there might be some unexpected behaviour by doing so. For example,
Expression
s are only connected toStatement
s through one constructor -- altering a data type stored in there removes the mutual recursion, but caused issues with block/flow analysis https://github.com/camfort/fortran-src/pull/221 .