use serde::Deserialize;
use serde::Serialize;
use mago_atom::Atom;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DefSignatureNode {
pub name: Atom,
pub is_function: bool,
pub is_constant: bool,
pub start_offset: u32,
pub end_offset: u32,
pub start_line: u32,
pub end_line: u32,
pub start_column: u16,
pub end_column: u16,
pub children: Vec<DefSignatureNode>,
pub hash: u64,
pub signature_hash: u64,
}
impl DefSignatureNode {
#[inline]
#[allow(clippy::too_many_arguments)]
#[must_use]
pub fn new(
name: Atom,
is_function: bool,
is_constant: bool,
start_offset: u32,
end_offset: u32,
start_line: u32,
end_line: u32,
start_column: u16,
end_column: u16,
hash: u64,
signature_hash: u64,
) -> Self {
Self {
name,
is_function,
is_constant,
start_offset,
end_offset,
start_line,
end_line,
start_column,
end_column,
children: Vec::new(),
hash,
signature_hash,
}
}
#[inline]
pub fn add_child(&mut self, child: DefSignatureNode) {
self.children.push(child);
}
#[inline]
#[must_use]
pub fn children(&self) -> &[DefSignatureNode] {
&self.children
}
#[inline]
pub fn children_mut(&mut self) -> &mut Vec<DefSignatureNode> {
&mut self.children
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct FileSignature {
pub hash: u64,
pub ast_nodes: Vec<DefSignatureNode>,
}
impl FileSignature {
#[inline]
#[must_use]
pub fn new(hash: u64) -> Self {
Self { hash, ast_nodes: Vec::new() }
}
#[inline]
pub fn add_node(&mut self, node: DefSignatureNode) {
self.ast_nodes.push(node);
}
#[inline]
#[must_use]
pub fn nodes(&self) -> &[DefSignatureNode] {
&self.ast_nodes
}
#[inline]
pub fn nodes_mut(&mut self) -> &mut Vec<DefSignatureNode> {
&mut self.ast_nodes
}
#[inline]
#[must_use]
pub fn is_empty(&self) -> bool {
self.ast_nodes.is_empty()
}
#[inline]
#[must_use]
pub fn len(&self) -> usize {
self.ast_nodes.len()
}
}