use std::sync::{Arc, OnceLock};
use backhopper_xref_graph::{Built, CallGraph, Functions, Mode, Relation};
use backhopper_xref_reader::ReadWarning;
#[derive(Debug, Clone)]
pub struct Xref<M: Mode> {
pub(crate) graph: Arc<CallGraph<M, Built>>,
pub(crate) warnings: Arc<Vec<ReadWarning>>,
pub(crate) closure_memo: OnceLock<Arc<Relation>>,
}
impl<M: Mode> Xref<M> {
pub(crate) fn from_graph(graph: CallGraph<M, Built>, warnings: Vec<ReadWarning>) -> Self {
Self {
graph: Arc::new(graph),
warnings: Arc::new(warnings),
closure_memo: OnceLock::new(),
}
}
pub fn graph(&self) -> &CallGraph<M, Built> {
&self.graph
}
pub fn warnings(&self) -> &[ReadWarning] {
&self.warnings
}
}
impl Xref<Functions> {
pub(crate) fn all_calls_closure(&self) -> &Relation {
self.closure_memo
.get_or_init(|| Arc::new(self.graph.all_calls().transitive_closure()))
}
}