#![allow(unused)]
use std::path::Path;
#[cfg(feature = "go-ast")]
use crate::services::unified_go_analyzer::UnifiedGoAnalyzer;
#[cfg(feature = "wasm-ast")]
use crate::services::unified_wasm_analyzer::UnifiedWasmAnalyzer;
#[cfg(feature = "go-ast")]
use super::metrics::GO_UNIFIED_CACHE;
#[cfg(feature = "wasm-ast")]
use super::metrics::WASM_UNIFIED_CACHE;
#[allow(unused_variables)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_go_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "go-ast")]
{
let analyzer = UnifiedGoAnalyzer::new(file_path.to_path_buf());
match analyzer.analyze().await {
Ok(analysis) => {
GO_UNIFIED_CACHE.insert(file_path.to_path_buf(), analysis.file_metrics.clone());
Ok(analysis.ast_items)
}
Err(_) => {
analyze_go_file(file_path).await
}
}
}
#[cfg(not(feature = "go-ast"))]
Ok(Vec::new())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_c_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "c-ast")]
{
use crate::services::ast::languages::c;
let file_context = c::analyze_c_file(file_path)
.await
.map_err(|e| anyhow::anyhow!("C analysis error: {}", e))?;
Ok(file_context.items)
}
#[cfg(not(feature = "c-ast"))]
analyze_c_file(file_path).await
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_cpp_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "cpp-ast")]
{
use crate::services::ast::languages::cpp;
let file_context = cpp::analyze_cpp_file(file_path)
.await
.map_err(|e| anyhow::anyhow!("C++ analysis error: {}", e))?;
Ok(file_context.items)
}
#[cfg(not(feature = "cpp-ast"))]
analyze_c_file(file_path).await }
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_kotlin_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
tracing::debug!("Analyzing Kotlin file: {}", file_path.display());
let items = analyze_kotlin_file(file_path).await?;
tracing::debug!("Kotlin analysis returned {} items", items.len());
Ok(items)
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_java_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
analyze_java_file(file_path).await
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_csharp_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
analyze_csharp_file(file_path).await
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_swift_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
analyze_swift_file(file_path).await
}
#[allow(unused_variables)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_wasm_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "wasm-ast")]
{
let analyzer = UnifiedWasmAnalyzer::new(file_path.to_path_buf());
match analyzer.analyze().await {
Ok(analysis) => {
WASM_UNIFIED_CACHE.insert(file_path.to_path_buf(), analysis.file_metrics.clone());
Ok(analysis.ast_items)
}
Err(_) => {
analyze_wasm_file(file_path).await
}
}
}
#[cfg(not(feature = "wasm-ast"))]
Ok(Vec::new())
}
#[allow(unused_variables)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_lean_language(
file_path: &std::path::Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "lean-ast")]
{
use crate::services::languages::lean;
match lean::analyze_lean_file(file_path).await {
Ok(file_context) => Ok(file_context.items),
Err(_) => Ok(Vec::new()),
}
}
#[cfg(not(feature = "lean-ast"))]
Ok(Vec::new())
}
async fn analyze_go_file(
_file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "go-ast")]
{
use crate::services::languages::go;
match go::analyze_go_file(_file_path).await {
Ok(file_context) => Ok(file_context.items),
Err(_) => Ok(Vec::new()), }
}
#[cfg(not(feature = "go-ast"))]
Ok(Vec::new())
}
async fn analyze_c_file(
#[allow(unused_variables)] file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "c-ast")]
{
use crate::services::ast::languages::c;
let file_context = c::analyze_c_file(file_path)
.await
.map_err(|e| anyhow::anyhow!("C analysis error: {}", e))?;
Ok(file_context.items)
}
#[cfg(not(feature = "c-ast"))]
Ok(Vec::new())
}
async fn analyze_kotlin_file(
#[allow(unused_variables)] file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
Ok(Vec::new())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_java_file(
_file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "java-ast")]
{
use crate::services::languages::java::JavaAstVisitor;
use tokio::fs;
match fs::read_to_string(_file_path).await {
Ok(source) => {
let visitor = JavaAstVisitor::new(_file_path);
match visitor.analyze_java_source(&source) {
Ok(items) => Ok(items),
Err(_) => Ok(Vec::new()),
}
}
Err(_) => Ok(Vec::new()),
}
}
#[cfg(not(feature = "java-ast"))]
Ok(Vec::new())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_csharp_file(
_file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "csharp-ast")]
{
use crate::services::languages::csharp::CSharpAstVisitor;
use tokio::fs;
match fs::read_to_string(_file_path).await {
Ok(source) => {
let visitor = CSharpAstVisitor::new(_file_path);
match visitor.analyze_csharp_source(&source) {
Ok(items) => Ok(items),
Err(_) => Ok(Vec::new()),
}
}
Err(_) => Ok(Vec::new()),
}
}
#[cfg(not(feature = "csharp-ast"))]
Ok(Vec::new())
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn analyze_swift_file(
_file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "swift-ast")]
{
Ok(Vec::new())
}
#[cfg(not(feature = "swift-ast"))]
Ok(Vec::new())
}
async fn analyze_wasm_file(
_file_path: &Path,
) -> anyhow::Result<Vec<crate::services::context::AstItem>> {
#[cfg(feature = "wasm-ast")]
{
use crate::services::languages::wasm::WasmModuleAnalyzer;
match tokio::fs::read_to_string(_file_path).await {
Ok(source) => {
let analyzer = WasmModuleAnalyzer::new(_file_path);
match analyzer.analyze_wat_text(&source) {
Ok(items) => Ok(items),
Err(_) => Ok(Vec::new()),
}
}
Err(_) => Ok(Vec::new()),
}
}
#[cfg(not(feature = "wasm-ast"))]
Ok(Vec::new())
}