66 lines
1.7 KiB
Rust
66 lines
1.7 KiB
Rust
use crate::name_analysis::symbol::module_level_symbol::ModuleLevelSymbol;
|
|
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
|
use crate::name_analysis::symbol::Symbol;
|
|
use crate::name_analysis::util::join_fqn_parts;
|
|
use std::fmt::{Debug, Formatter};
|
|
use std::rc::Rc;
|
|
|
|
pub struct ModuleSymbol {
|
|
fqn_parts: Vec<Rc<str>>,
|
|
is_public: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
inner_symbols: Vec<ModuleLevelSymbol>,
|
|
}
|
|
|
|
impl ModuleSymbol {
|
|
pub fn new(
|
|
fqn_parts: Vec<Rc<str>>,
|
|
is_public: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
) -> Self {
|
|
Self {
|
|
fqn_parts,
|
|
is_public,
|
|
source_definition,
|
|
inner_symbols: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn fqn_parts(&self) -> &[Rc<str>] {
|
|
&self.fqn_parts
|
|
}
|
|
|
|
pub fn declared_name(&self) -> &str {
|
|
self.fqn_parts.last().unwrap()
|
|
}
|
|
|
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
|
self.fqn_parts.last().unwrap().clone()
|
|
}
|
|
|
|
pub fn is_public(&self) -> bool {
|
|
self.is_public
|
|
}
|
|
|
|
pub fn add_inner_symbol(&mut self, module_level_symbol: ModuleLevelSymbol) {
|
|
self.inner_symbols.push(module_level_symbol);
|
|
}
|
|
}
|
|
|
|
impl Symbol for ModuleSymbol {
|
|
fn source_definition(&self) -> Option<&SourceDefinition> {
|
|
self.source_definition.as_ref()
|
|
}
|
|
}
|
|
|
|
impl Debug for ModuleSymbol {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_struct("ModuleSymbol")
|
|
.field("fqn", &join_fqn_parts(&self.fqn_parts))
|
|
.field("is_public", &self.is_public)
|
|
.field("source_definition", &self.source_definition)
|
|
.field("inner_symbols", &self.inner_symbols)
|
|
.finish()
|
|
}
|
|
}
|