pub struct GraphBuilder {
pub cpg: CodePropertyGraph,
symbol_index: HashMap<String, NodeIndex>,
function_defs: HashMap<String, Vec<NodeIndex>>,
call_sites: HashMap<String, Vec<NodeIndex>>,
}Expand description
Incrementally builds a CodePropertyGraph from parser facts.
Supports ingesting facts from multiple files and merging local graphs
(e.g., from parallel parsing) into a single global graph with symbol
deduplication. Call Self::resolve_calls after all facts are ingested
to wire up call sites to their definitions.
§Example
use icb_graph::builder::GraphBuilder;
use icb_parser::facts::RawNode;
use icb_common::{Language, NodeKind};
let mut builder = GraphBuilder::new();
let facts = vec![RawNode {
language: Language::Python,
kind: NodeKind::Function,
name: Some("main".into()),
usr: None,
start_line: 1,
start_col: 0,
end_line: 1,
end_col: 5,
children: vec![],
source_file: None,
}];
builder.ingest_file_facts(&facts);
builder.resolve_calls();
assert_eq!(builder.cpg.node_count(), 1);Fields§
§cpg: CodePropertyGraph§symbol_index: HashMap<String, NodeIndex>§function_defs: HashMap<String, Vec<NodeIndex>>§call_sites: HashMap<String, Vec<NodeIndex>>Implementations§
Source§impl GraphBuilder
impl GraphBuilder
pub fn new() -> Self
Sourcepub fn ingest_file_facts(&mut self, facts: &[RawNode])
pub fn ingest_file_facts(&mut self, facts: &[RawNode])
Ingest facts from a single file.
This method may be called multiple times (even from different threads after merging). Each call enriches the same graph.
Sourcepub fn resolve_calls(&mut self)
pub fn resolve_calls(&mut self)
Resolve calls: for every call site with a matching function/class
definition, add a Edge::Call edge from the call site to the definition.
Sourcepub fn merge(&mut self, other: GraphBuilder)
pub fn merge(&mut self, other: GraphBuilder)
Merge another GraphBuilder into this one.
All nodes from other are transferred to self. Nodes with the
same symbolic key (USR or name) that already exist in self are
reused, and edges are rewired accordingly. The temporary call/def
maps are also merged.