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, declared_name_source_range: SourceRange, fqn_parts: Vec>, is_extern: bool, scope_id: usize, generic_parameters: Vec>, constructor_symbol: Rc, fields: HashMap, Rc>, functions: HashMap, Rc>, } impl ClassSymbol { pub fn new( declared_name: &Rc, declared_name_source_range: &SourceRange, fqn_parts: Vec>, is_extern: bool, scope_id: usize, generic_parameters: Vec>, constructor_symbol: Rc, fields: Vec>, functions: Vec>, ) -> 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 { self.declared_name.clone() } pub fn declared_name_source_range(&self) -> &SourceRange { &self.declared_name_source_range } pub fn fqn_parts(&self) -> &[Rc] { &self.fqn_parts } pub fn scope_id(&self) -> usize { self.scope_id } pub fn generic_parameters(&self) -> &[Rc] { &self.generic_parameters } pub fn constructor_symbol(&self) -> &ConstructorSymbol { &self.constructor_symbol } pub fn fields(&self) -> &HashMap, Rc> { &self.fields } pub fn functions(&self) -> &HashMap, Rc> { &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(&self, state: &mut H) { self.declared_name.hash(state); self.scope_id.hash(state); } }