#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::Result;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
pub struct UnifiedAstEngine;
impl Default for UnifiedAstEngine {
fn default() -> Self {
Self::new()
}
}
impl UnifiedAstEngine {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_project(&self, _path: &Path) -> Result<AstForest> {
Ok(AstForest::default())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn parse_project(&self, _path: &Path) -> Result<AstForest> {
Ok(AstForest::default())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "score_range")]
pub fn compute_metrics(&self, _forest: &AstForest) -> Result<ProjectMetrics> {
Ok(ProjectMetrics::default())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn extract_dependencies(
&self,
_forest: &AstForest,
) -> Result<crate::models::dag::DependencyGraph> {
Ok(crate::models::dag::DependencyGraph::new())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn generate_artifacts(&self, _path: &Path) -> Result<ArtifactTree> {
Ok(ArtifactTree::default())
}
}
#[derive(Default, Debug, Clone)]
pub struct AstForest {
pub modules: Vec<ModuleNode>,
pub metrics: ProjectMetrics,
}
impl AstForest {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn files(&self) -> impl Iterator<Item = (&PathBuf, &ModuleNode)> {
self.modules.iter().map(|module| (&module.path, module))
}
}
#[derive(Default, Debug, Clone)]
pub struct ModuleNode {
pub path: std::path::PathBuf,
pub name: String,
pub visibility: String,
pub metrics: ModuleMetrics,
}
#[derive(Default, Debug, Clone)]
pub struct ModuleMetrics {
pub complexity: u32,
pub lines: usize,
pub functions: usize,
pub classes: usize,
}
#[derive(Default, Debug, Clone)]
pub struct ProjectMetrics {
pub total_complexity: u32,
pub total_lines: usize,
pub file_count: usize,
pub function_count: usize,
pub avg_complexity: f32,
pub max_complexity: u32,
}
#[derive(Default, Debug, Clone)]
pub struct ArtifactTree {
pub dogfooding: BTreeMap<String, String>,
pub mermaid: MermaidArtifacts,
pub templates: Vec<Template>,
}
#[derive(Default, Debug, Clone)]
pub struct MermaidArtifacts {
pub ast_generated: BTreeMap<String, String>,
pub non_code: BTreeMap<String, String>,
}
#[derive(Debug, Clone)]
pub struct Template {
pub name: String,
pub content: String,
pub hash: blake3::Hash,
pub source_location: PathBuf,
}
impl Default for Template {
fn default() -> Self {
Self {
name: String::new(),
content: String::new(),
hash: blake3::hash(b""),
source_location: PathBuf::new(),
}
}
}
pub enum FileAst {
Rust(syn::File),
TypeScript(String),
Python(String),
C(String),
Cpp(String),
Cython(String),
Kotlin(String),
Makefile(String),
Markdown(String),
Toml(String),
Yaml(String),
Json(String),
Shell(String),
}
include!("unified_ast_engine_tests.rs");