tldr_core/lib.rs
1//! TLDR-Core: Core analysis engine for code analysis
2//!
3//! This crate provides the core analysis functionality for the TLDR tool,
4//! organized into analysis layers:
5//!
6//! - **Layer 1 (AST)**: tree, structure, extract, imports
7//! - **Layer 2 (Call Graph)**: calls, impact, dead, importers, arch
8//! - **Layer 3 (CFG)**: cfg, complexity
9//! - **Layer 4 (DFG)**: dfg
10//! - **Layer 5 (PDG)**: pdg, slice, thin_slice
11//! - **Layer 6 (SSA)**: ssa, reaching-defs (Session 10)
12//! - **Layer 7 (Alias)**: alias analysis (Session 11+)
13//! - **Layer 8 (Dataflow)**: available expressions, abstract interpretation (Session 13)
14//!
15//! Plus search, context, quality, security, and diagnostics modules.
16//!
17//! # Example
18//!
19//! ```rust,ignore
20//! use tldr_core::{Language, TldrResult};
21//! use tldr_core::fs::tree::get_file_tree;
22//! use tldr_core::ast::{get_code_structure, extract_file, get_imports};
23//!
24//! // Detect language from file extension
25//! let lang = Language::from_extension(".py");
26//! assert_eq!(lang, Some(Language::Python));
27//!
28//! // Get file tree
29//! let tree = get_file_tree(Path::new("src"), None, true, None)?;
30//!
31//! // Extract code structure
32//! let structure = get_code_structure(Path::new("src"), Language::Python, 0, None)?;
33//! ```
34
35#![warn(missing_docs)]
36#![warn(rustdoc::missing_crate_level_docs)]
37
38pub mod error;
39pub mod git;
40pub mod types;
41pub mod validation;
42
43// Phase 10: Robustness (A32, A33, A34)
44pub mod encoding;
45pub mod limits;
46
47// Phase 2: AST Layer (L1) - implemented
48pub mod ast;
49pub mod fs;
50
51// Phase 3: Call Graph Layer (L2) - implemented
52pub mod analysis;
53pub mod callgraph;
54
55// Phase 4: CFG Layer (L3) - implemented
56pub mod cfg;
57pub mod metrics;
58
59// Phase 6: Search Layer - implemented
60pub mod search;
61
62// Phase 5: DFG Layer (L4) - implemented
63pub mod dfg;
64
65// Phase 5: PDG Layer (L5) - implemented
66pub mod pdg;
67
68// Session 10: SSA Layer (L6) - in progress
69pub mod ssa;
70
71// Session 11+: Alias Analysis Layer (L7) - in progress
72pub mod alias;
73
74// Session 13: Dataflow Analysis Layer (L8) - in progress
75// Available expressions (CSE detection) and Abstract interpretation (range/nullability)
76pub mod dataflow;
77
78// Session 16: Semantic Search Layer - in progress
79// Dense embeddings for code search using Snowflake Arctic models
80#[cfg(feature = "semantic")]
81pub mod semantic;
82
83// API surface extraction for libraries/packages
84pub mod surface;
85
86// Error diagnosis and auto-fix system (Phase 2)
87pub mod fix;
88
89// GVN Migration: Phase P0 - Base infrastructure for orchestrated analysis
90pub mod wrappers;
91
92// Re-export main types for convenience
93pub use error::TldrError;
94pub use types::*;
95
96// Re-export Layer 1 functions for convenience
97pub use ast::{extract_file, get_code_structure, get_imports};
98pub use fs::get_file_tree;
99
100// Re-export Layer 2 functions for convenience
101pub use analysis::{
102 architecture_analysis, change_impact, change_impact_extended, collect_all_functions,
103 dead_code_analysis, find_importers, impact_analysis, impact_analysis_with_ast_fallback,
104 ChangeImpactMetadata, ChangeImpactReport, DetectionMethod, TestFunction,
105};
106pub use callgraph::build_project_call_graph;
107
108// Re-export Layer 3 functions for convenience
109pub use cfg::get_cfg_context;
110pub use metrics::calculate_complexity;
111
112// Re-export Layer 4 (DFG) functions for convenience
113pub use dfg::get_dfg_context;
114
115// Re-export Layer 5 (PDG) functions for convenience
116pub use pdg::{get_pdg_context, get_slice, get_slice_rich, RichSlice, SliceEdge, SliceNode};
117
118// Re-export Layer 6 (Search) functions for convenience
119pub use search::{
120 enriched_search, enriched_search_with_callgraph_cache, enriched_search_with_index,
121 enriched_search_with_structure_cache, hybrid_search, read_callgraph_cache,
122 read_structure_cache, search, search_with_inner, write_structure_cache, Bm25Index, Bm25Result,
123 CallGraphLookup, EmbeddingClient, EnrichedResult, EnrichedSearchOptions, EnrichedSearchReport,
124 HybridResult, HybridSearchReport, SearchMatch, SearchMode, StructureLookup, Tokenizer,
125};
126
127/// Result type alias for all TLDR operations
128pub type TldrResult<T> = Result<T, TldrError>;
129
130// Re-export validation functions (P4: DRY validators)
131pub use validation::{detect_or_parse_language, validate_file_path};
132
133// Phase 7: Context & Analysis
134pub mod context;
135
136// Re-export context module functions
137pub use context::{get_relevant_context, FunctionContext, RelevantContext};
138
139// Phase 8: Quality & Security - implemented
140pub mod quality;
141pub mod security;
142
143// Phase 4-6: Pattern Detection - implemented
144pub mod patterns;
145
146// Re-export Quality module functions
147pub use quality::{
148 analyze_smells_aggregated, detect_smells, SmellFinding, SmellType, SmellsReport,
149 ThresholdPreset,
150};
151pub use quality::{
152 maintainability_index, FileMI, HalsteadMetrics, MISummary, MaintainabilityReport,
153};
154
155// Re-export Security module functions
156pub use security::{
157 compute_taint, compute_taint_with_tree, TaintFlow, TaintInfo, TaintSink, TaintSinkType,
158 TaintSource, TaintSourceType,
159};
160pub use security::{scan_secrets, SecretFinding, SecretsReport, Severity};
161pub use security::{scan_vulnerabilities, VulnFinding, VulnReport, VulnType};
162
163// Re-export Pattern detection functions
164pub use patterns::{detect_patterns, detect_patterns_with_config, PatternConfig, PatternMiner};
165
166// Phase 7-9: Inheritance Analysis - implemented
167pub mod inheritance;
168
169// Re-export Inheritance module functions
170pub use inheritance::format::{format_dot, format_text};
171pub use inheritance::{extract_inheritance, InheritanceOptions};
172
173// Session 6: Diagnostics module - unified type checking and linting
174pub mod diagnostics;
175
176// Re-export Diagnostics module types (implementations pending)
177pub use diagnostics::{
178 Diagnostic, DiagnosticsReport, DiagnosticsSummary, Severity as DiagnosticSeverity,
179};
180
181// Alias analysis re-exports will be added when implemented:
182// pub use alias::{compute_alias, compute_alias_from_ssa, AliasInfo, AliasError, AbstractLocation};
183
184// Dataflow analysis re-exports (Phase 12: Integration & Public API)
185pub use dataflow::{
186 // Abstract Interpretation (CAP-AI-01 through CAP-AI-22)
187 compute_abstract_interp,
188 // Available Expressions (CAP-AE-01 through CAP-AE-12)
189 compute_available_exprs,
190 compute_available_exprs_with_source_and_lang,
191 normalize_expression,
192 AbstractInterpInfo,
193 AbstractState,
194 AbstractValue,
195 AvailableExprsInfo,
196 ConstantValue,
197 Expression,
198 Nullability,
199};