use super::database::{CodeSymbol, FunctionFact, ImportFact, TypeFact};
use super::types::CallGraphEntry;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ConstantFact {
pub file: String,
pub name: String,
pub value: Option<String>,
pub const_type: String, pub scope: String, pub line: usize,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MemberFact {
pub file: String,
pub container: String, pub name: String,
pub member_type: String, pub visibility: String, pub modifiers: Vec<String>, pub line: usize,
}
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct ExtractedData {
pub symbols: Vec<CodeSymbol>,
pub functions: Vec<FunctionFact>,
pub types: Vec<TypeFact>,
pub imports: Vec<ImportFact>,
pub call_edges: Vec<CallGraphEntry>,
pub constants: Vec<ConstantFact>,
pub members: Vec<MemberFact>,
}
impl ExtractedData {
pub fn new() -> Self {
Self::default()
}
pub fn add_symbol(&mut self, symbol: CodeSymbol) {
let already_exists = self
.symbols
.iter()
.any(|s| s.path == symbol.path && s.name == symbol.name && s.line == symbol.line);
if !already_exists {
self.symbols.push(symbol);
}
}
pub fn add_function(&mut self, function: FunctionFact) {
let already_exists = self
.functions
.iter()
.any(|f| f.file == function.file && f.name == function.name);
if !already_exists {
self.functions.push(function);
}
}
pub fn add_type(&mut self, type_fact: TypeFact) {
let already_exists = self
.types
.iter()
.any(|t| t.file == type_fact.file && t.name == type_fact.name);
if !already_exists {
self.types.push(type_fact);
}
}
pub fn add_import(&mut self, import: ImportFact) {
let already_exists = self
.imports
.iter()
.any(|i| i.file == import.file && i.import_path == import.import_path);
if !already_exists {
self.imports.push(import);
}
}
pub fn add_call_edge(&mut self, edge: CallGraphEntry) {
let already_exists = self.call_edges.iter().any(|e| {
e.caller == edge.caller
&& e.callee == edge.callee
&& e.file == edge.file
&& e.line_number == edge.line_number
});
if !already_exists {
self.call_edges.push(edge);
}
}
}