#![cfg_attr(coverage_nightly, coverage(off))]
use super::symbol_table::{SymbolEntry, SymbolTable};
use super::*;
use anyhow::Result;
use rustc_hash::FxHashMap;
use std::fs;
use std::path::{Path, PathBuf};
pub struct DependencyGraphBuilder {
graph: DependencyGraph,
symbol_table: SymbolTable,
node_map: FxHashMap<PathBuf, NodeId>,
processed_hashes: FxHashMap<PathBuf, u64>,
}
impl Default for DependencyGraphBuilder {
fn default() -> Self {
Self::new()
}
}
impl DependencyGraphBuilder {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
DependencyGraphBuilder {
graph: DependencyGraph::new(),
symbol_table: SymbolTable::new(),
node_map: FxHashMap::default(),
processed_hashes: FxHashMap::default(),
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub fn from_workspace(path: &Path) -> Result<Self> {
let mut builder = Self::new();
let files = builder.collect_source_files(path)?;
for file_path in &files {
builder.build_file_symbols(file_path)?;
}
for file_path in &files {
let node_id = builder.analyze_file(file_path)?;
builder.resolve_file_dependencies(node_id, file_path)?;
}
Ok(builder)
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn build(self) -> Result<DependencyGraph> {
Ok(self.graph)
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn symbol_table(&self) -> &SymbolTable {
&self.symbol_table
}
}
include!("builder_file_collection.rs");
include!("builder_symbol_parsing.rs");
include!("builder_import_parsing.rs");
include!("builder_analysis.rs");
include!("builder_tests.rs");