How acdeveloper-sci/forti4d works
Purpose and Entry Points
Forti4D is a Python static-analysis toolkit for mixed F77/F90/F95 source trees, designed around regex and logical-line processing rather than a full Fortran parser. The CLI/package orchestration entry point is forti4d/pipeline.py; runtime paths and environment overrides are centralized in forti4d/config.py.
Pipeline Orchestration
forti4d/pipeline.py runs a dependency-ordered 19-stage batch pipeline, supports selecting/resuming stages, and materializes reports under the configured output directory. Stages communicate primarily through CSV/text artifacts rather than an in-memory shared model. Logging is initialized through forti4d/lib/logging_setup.py; parallel execution support is in forti4d/lib/parallel.py.
Source Normalization and Parsing Boundary
The core parsing boundary is the custom logical-line reader in forti4d/lib/reader_logical.py, which normalizes F77 fixed-form and F90 free-form continuation behavior. Regex grammars in forti4d/lib/patterns_v1.py and forti4d/lib/patterns_v2.py, plus statement classification in forti4d/lib/kinds.py, replace external parser dependencies. This scope intentionally supports F77–F95 but not Fortran 2003+ or C-preprocessor expansion.
Corpus Inventory and Dependency Graph
Inventory establishes program-unit identities, types, and line ranges in forti4d/analyzers/inventory.py. Dependency extraction then resolves CALL/USE/function relationships, ambiguities, external references, includes, and file-level relationships in forti4d/analyzers/dependencies.py. These outputs form the graph and unit identity foundation used by structural and reachability analyses.
Line-Level Audit and Scope Attribution
forti4d/analyzers/profiler.py produces per-file audit CSVs that classify logical lines and density metrics. Multiple analyzers consume this audit layer: forti4d/analyzers/complexity.py, forti4d/analyzers/common_blocks.py, and scope-management analyzers. Attribution relies on inventory line ranges, assigning statements to the innermost containing program unit.
Structural, Risk, and Modernization Analysis
Topology and migration interpretation are layered over inventory, dependency, and audit outputs: forti4d/analyzers/block_analysis.py models block topology; forti4d/analyzers/structure_analysis.py identifies graph roles such as hubs and entry points; forti4d/analyzers/cross_analysis.py derives migration strategy. Entry points include explicit PROGRAM units and implicit main programs.
Symbol and Legacy-Feature Scope Layer
The E4 ScopeManager layer extracts declarations and legacy semantics within unit boundaries: forti4d/analyzers/symbols.py, forti4d/analyzers/derived_types.py, and forti4d/analyzers/equivalences.py. It captures variables, signatures, IMPLICIT rules, derived types, and EQUIVALENCE alias groups; it complements graph-level analysis rather than resolving modern OOP or procedure-pointer semantics.
Consolidation and Deliverables
Late stages derive reachability/dead-code status, SLOC, clone relationships, graph render inputs, and ranked migration risk through forti4d/analyzers/reachability.py, forti4d/analyzers/consolidate.py, and forti4d/analyzers/prioritization.py. forti4d/analyzers/html_report.py creates a self-contained report, while forti4d/analyzers/visual_graph.py emits Graphviz DOT; Graphviz is optional and only needed to render those files. The only stated Python third-party runtime dependency is Loguru.
Main entry points: inventory.py Corpus Inventory · dependencies.py Dependency Extraction · consolidate.py Consolidated Analysis · reader_logical.py Logical-Line Reader
Components 20
Runtime & Pipeline
- Runtime Configuration · Centralizes paths and environment overrides.
forti4d/config.py - 19-Stage Pipeline · Runs selected or resumed batch stages through CSV/text artifacts.
forti4d/pipeline.py - Logging Setup
forti4d/lib/logging_setup.py - Parallel Execution
forti4d/lib/parallel.py
Normalization Boundary
- Logical-Line Reader · Normalizes fixed-form and free-form continuation rules.
forti4d/lib/reader_logical.py - Regex Grammar v1
forti4d/lib/patterns_v1.py - Regex Grammar v2
forti4d/lib/patterns_v2.py - Statement Classification
forti4d/lib/kinds.py
Core Analysis
- Corpus Inventory · Establishes program-unit identities, types, and line ranges.
forti4d/analyzers/inventory.py - Dependency Extraction · Resolves calls, uses, functions, includes, and external references.
forti4d/analyzers/dependencies.py - Line Audit & Metrics · Produces per-file logical-line audit CSVs and density metrics.
forti4d/analyzers/profiler.py - Structural Analysis · Derives block topology, graph roles, and entry points.
forti4d/analyzers/structure_analysis.py
Scope & Legacy Semantics
- Symbols & Declarations · Extracts variables, signatures, and IMPLICIT rules by unit.
forti4d/analyzers/symbols.py - Derived Types
forti4d/analyzers/derived_types.py - EQUIVALENCE Aliases
forti4d/analyzers/equivalences.py
Consolidation & Deliverables
- Reachability & Dead Code
forti4d/analyzers/reachability.py - Consolidated Analysis · Combines late-stage results including SLOC and clone relationships.
forti4d/analyzers/consolidate.py - Migration Prioritization · Ranks modernization risk and migration work.
forti4d/analyzers/prioritization.py - HTML Report · Creates a self-contained report.
forti4d/analyzers/html_report.py - Graphviz DOT Output · Emits DOT render inputs; Graphviz rendering is optional.
forti4d/analyzers/visual_graph.py
Connections 27
- Runtime Configuration → 19-Stage Pipeline: configures
- Logging Setup → 19-Stage Pipeline: logs pipeline
- Parallel Execution → 19-Stage Pipeline: parallel stages
- 19-Stage Pipeline → Logical-Line Reader: reads source
- Regex Grammar v1 → Statement Classification: grammar rules
- Regex Grammar v2 → Statement Classification: grammar rules
- Logical-Line Reader → Corpus Inventory: logical lines
- Logical-Line Reader → Line Audit & Metrics: logical lines
- Statement Classification → Line Audit & Metrics: classifies lines
- Corpus Inventory → Dependency Extraction: unit identities and ranges
- Logical-Line Reader → Dependency Extraction: normalized source
- Corpus Inventory → Structural Analysis: unit graph foundation
- Dependency Extraction → Structural Analysis: dependency graph
- Line Audit & Metrics → Symbols & Declarations: audit attribution
- Corpus Inventory → Symbols & Declarations: unit boundaries
- Corpus Inventory → Derived Types: unit boundaries
- Corpus Inventory → EQUIVALENCE Aliases: unit boundaries
- Dependency Extraction → Reachability & Dead Code: call/use graph
- Structural Analysis → Reachability & Dead Code: entry points
- Line Audit & Metrics → Consolidated Analysis: audit metrics
- Reachability & Dead Code → Consolidated Analysis: dead-code status
- Symbols & Declarations → Consolidated Analysis: scope results
- Consolidated Analysis → Migration Prioritization: combined findings
- Migration Prioritization → HTML Report: ranked results
- Consolidated Analysis → HTML Report: analysis artifacts
- Dependency Extraction → Graphviz DOT Output: graph data
- Structural Analysis → Graphviz DOT Output: topology roles