#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::Result;
use std::path::{Path, PathBuf};
#[cfg(test)]
use std::sync::atomic::{AtomicUsize, Ordering};
use crate::services::complexity::{ComplexityMetrics, FileComplexityMetrics, FunctionComplexity};
use crate::services::context::AstItem;
#[cfg(feature = "python-ast")]
use tree_sitter::{Parser as TsParser, Tree};
pub struct UnifiedPythonAnalyzer {
file_path: PathBuf,
#[cfg(test)]
parse_count: AtomicUsize,
}
#[derive(Debug)]
pub struct UnifiedAnalysis {
pub ast_items: Vec<AstItem>,
pub file_metrics: FileComplexityMetrics,
pub parsed_at: std::time::Instant,
}
#[derive(Debug, thiserror::Error)]
pub enum AnalysisError {
#[error("Failed to read file: {0}")]
Io(#[from] std::io::Error),
#[error("Failed to parse Python syntax: {0}")]
Parse(String),
#[error("Analysis error: {0}")]
Analysis(String),
}
impl UnifiedPythonAnalyzer {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn new(file_path: PathBuf) -> Self {
Self {
file_path,
#[cfg(test)]
parse_count: AtomicUsize::new(0),
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn file_path(&self) -> &Path {
&self.file_path
}
#[cfg(test)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn parse_count(&self) -> usize {
self.parse_count.load(Ordering::SeqCst)
}
}
include!("unified_python_analyzer_analysis.rs");
include!("unified_python_analyzer_parser.rs");
include!("unified_python_analyzer_visitor.rs");
include!("unified_python_analyzer_tests.rs");