-
Notifications
You must be signed in to change notification settings - Fork 21
Source processing flow
An overview of the operations fortran-src does on Fortran source.
fortran-src's default "parse Fortran source code" operation does the following:
- Lex & parse (simultaneous)
- Post-parse transform
Post-parse transformation alters the AST, but not annotations. Internally, it performs a temporary renaming pass, then a temporary type analysis pass, then runs the transformations in sequence with annotations available, and finally discards the analysis and renamings.
Type checking depends on some post-parse transformations for correctness (the subscript disambiguation, and intrinsics disambiguation)
With type checking (--typecheck
CLI, analyseTypes
library), after parsing:
- Type analysis
- Gathers type information on 4 separate traversals through the entire
ProgramFile
- Uses gathered information to "annotate"
Expression
s andProgramUnit
s: involves evaluating expression types e.g.real + int = real
- Types are a mix of
BaseType
+ other syntax tags, and fortran-varsSemanticType
s which include kind
- Gathers type information on 4 separate traversals through the entire
Basic block analysis must run after transformations, but is separate from type analysis.
- Basic block analysis
Dataflow analyses may run after the basic block analysis.
- Dataflow analysis
- Live variable analysis
- Constant expression analysis
- Gathers explicit constants (PARAMETER variables)
- Evaluates a handful of literals and binops
- The implicit type analysis isn't ideal. We should be able to identify the exact set of syntax analysis required to perform these post-parse transformations, and do only that.
- Or perhaps these transformations could take place in-line, inside the main syntax analysis?
- It gets even worse as we do more work during type analysis - perhaps we could make these analyses a bit configurable to work around that.
- Parts of the constant expression analysis should be done earlier. Explicit constant variables (PARAMETERs) may be used in types as kind parameters, so we should gather that info during type analysis.