Skip to main content

tldr_core/dataflow/
mod.rs

1//! Dataflow Analysis Module
2//!
3//! This module provides two forward dataflow analyses:
4//!
5//! 1. **Available Expressions Analysis** (CAP-AE-01 through CAP-AE-12)
6//!    - Forward MUST (intersection) dataflow analysis
7//!    - Common Subexpression Elimination (CSE) detection
8//!    - Commutative expression normalization
9//!
10//! 2. **Abstract Interpretation** (CAP-AI-01 through CAP-AI-22)
11//!    - Forward dataflow with widening for loop termination
12//!    - Range tracking for integer variables
13//!    - Nullability tracking (NEVER/MAYBE/ALWAYS)
14//!    - Division-by-zero detection
15//!    - Null dereference detection
16//!    - Multi-language support (Python, TypeScript, Go, Rust)
17//!
18//! ## Module Structure
19//!
20//! ```text
21//! dataflow/
22//! ├── mod.rs              # This file - module entry point
23//! ├── types.rs            # Shared types (BlockId, predecessors)
24//! ├── available.rs        # Available expressions analysis
25//! ├── abstract_interp.rs  # Abstract interpretation
26//! └── dataflow_tests.rs   # Comprehensive test suite
27//! ```
28//!
29//! ## Usage
30//!
31//! ```rust,ignore
32//! use tldr_core::dataflow::{
33//!     compute_available_exprs, AvailableExprsInfo, Expression,
34//!     compute_abstract_interp, AbstractInterpInfo, AbstractValue, Nullability,
35//! };
36//!
37//! // Available Expressions Analysis
38//! let cfg = get_cfg_context(path, func, None, None)?;
39//! let dfg = get_dfg_context(path, func, None, None)?;
40//! let avail = compute_available_exprs(&cfg, &dfg)?;
41//! let redundant = avail.redundant_computations();
42//!
43//! // Abstract Interpretation
44//! let interp = compute_abstract_interp(&cfg, &refs, Some(&source), "python")?;
45//! for (line, var) in &interp.potential_div_zero {
46//!     println!("Warning: potential division by zero at line {} ({})", line, var);
47//! }
48//! ```
49//!
50//! ## Specification Reference
51//!
52//! See `spec.md` in this directory for:
53//! - Full capability definitions (34 capabilities)
54//! - Algorithm descriptions
55//! - Behavioral contracts
56//! - JSON output formats
57//! - Edge case handling
58
59// =============================================================================
60// Submodules
61// =============================================================================
62
63// Types submodule (shared types and helpers)
64pub mod types;
65
66// Available Expressions Analysis
67pub mod available;
68
69// Abstract Interpretation
70pub mod abstract_interp;
71
72// Tests
73#[cfg(test)]
74mod dataflow_tests;
75
76// =============================================================================
77// Re-exports (Phase 12: Integration & Public API)
78// =============================================================================
79
80// Available Expressions types and functions
81pub use available::{
82    // Phase 12: Main algorithm
83    compute_available_exprs,
84    compute_available_exprs_with_source,
85    compute_available_exprs_with_source_and_lang,
86    extract_binary_exprs_from_ast,
87    extract_expressions_full,
88    normalize_expression,
89    AvailableExprsInfo,
90    BlockExpressions,
91    Confidence,
92    ExprInstance,
93    Expression,
94    ExtractionResult,
95    UncertainFinding,
96    COMMUTATIVE_OPS,
97};
98
99// Abstract Interpretation types and functions
100pub use abstract_interp::{
101    // Phase 10: Main algorithm
102    compute_abstract_interp,
103    init_params,
104    transfer_block,
105    AbstractInterpInfo,
106    AbstractState,
107    AbstractValue,
108    ConstantValue,
109    Nullability,
110};
111
112// Shared types and helpers
113pub use types::{
114    build_predecessors, build_successors, find_back_edges, reachable_blocks, reverse_postorder,
115    validate_cfg, BlockId, DataflowError, MAX_BLOCKS, MAX_ITERATIONS,
116};