104 lines
2.8 KiB
Rust
104 lines
2.8 KiB
Rust
use crate::source_range::SourceRange;
|
|
use crate::symbol::constructor_symbol::ConstructorSymbol;
|
|
use crate::symbol::field_symbol::FieldSymbol;
|
|
use crate::symbol::function_symbol::FunctionSymbol;
|
|
use crate::symbol::generic_parameter_symbol::GenericParameterSymbol;
|
|
use std::collections::HashMap;
|
|
use std::hash::{Hash, Hasher};
|
|
use std::rc::Rc;
|
|
|
|
pub struct ClassSymbol {
|
|
declared_name: Rc<str>,
|
|
declared_name_source_range: SourceRange,
|
|
fqn_parts: Vec<Rc<str>>,
|
|
is_extern: bool,
|
|
scope_id: usize,
|
|
generic_parameters: Vec<Rc<GenericParameterSymbol>>,
|
|
constructor_symbol: Rc<ConstructorSymbol>,
|
|
fields: HashMap<Rc<str>, Rc<FieldSymbol>>,
|
|
functions: HashMap<Rc<str>, Rc<FunctionSymbol>>,
|
|
}
|
|
|
|
impl ClassSymbol {
|
|
pub fn new(
|
|
declared_name: &Rc<str>,
|
|
declared_name_source_range: &SourceRange,
|
|
fqn_parts: Vec<Rc<str>>,
|
|
is_extern: bool,
|
|
scope_id: usize,
|
|
generic_parameters: Vec<Rc<GenericParameterSymbol>>,
|
|
constructor_symbol: Rc<ConstructorSymbol>,
|
|
fields: Vec<Rc<FieldSymbol>>,
|
|
functions: Vec<Rc<FunctionSymbol>>,
|
|
) -> Self {
|
|
Self {
|
|
declared_name: declared_name.clone(),
|
|
declared_name_source_range: declared_name_source_range.clone(),
|
|
fqn_parts,
|
|
is_extern,
|
|
scope_id,
|
|
generic_parameters,
|
|
constructor_symbol,
|
|
fields: fields
|
|
.into_iter()
|
|
.map(|fs| (fs.declared_name_owned(), fs))
|
|
.collect(),
|
|
functions: functions
|
|
.into_iter()
|
|
.map(|fs| (fs.declared_name_owned(), fs))
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
pub fn declared_name(&self) -> &str {
|
|
&self.declared_name
|
|
}
|
|
|
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
|
self.declared_name.clone()
|
|
}
|
|
|
|
pub fn declared_name_source_range(&self) -> &SourceRange {
|
|
&self.declared_name_source_range
|
|
}
|
|
|
|
pub fn fqn_parts(&self) -> &[Rc<str>] {
|
|
&self.fqn_parts
|
|
}
|
|
|
|
pub fn scope_id(&self) -> usize {
|
|
self.scope_id
|
|
}
|
|
|
|
pub fn generic_parameters(&self) -> &[Rc<GenericParameterSymbol>] {
|
|
&self.generic_parameters
|
|
}
|
|
|
|
pub fn constructor_symbol(&self) -> &ConstructorSymbol {
|
|
&self.constructor_symbol
|
|
}
|
|
|
|
pub fn fields(&self) -> &HashMap<Rc<str>, Rc<FieldSymbol>> {
|
|
&self.fields
|
|
}
|
|
|
|
pub fn functions(&self) -> &HashMap<Rc<str>, Rc<FunctionSymbol>> {
|
|
&self.functions
|
|
}
|
|
}
|
|
|
|
impl Eq for ClassSymbol {}
|
|
|
|
impl PartialEq for ClassSymbol {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.declared_name == other.declared_name && self.scope_id == other.scope_id
|
|
}
|
|
}
|
|
|
|
impl Hash for ClassSymbol {
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
self.declared_name.hash(state);
|
|
self.scope_id.hash(state);
|
|
}
|
|
}
|