From 88dfa87e85786d16599befcef0d333e0053540a3 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 27 Nov 2021 03:39:10 -0800 Subject: [PATCH] Symbol local_name --- schala-lang/src/symbol_table/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/schala-lang/src/symbol_table/mod.rs b/schala-lang/src/symbol_table/mod.rs index 66ea937..2f07049 100644 --- a/schala-lang/src/symbol_table/mod.rs +++ b/schala-lang/src/symbol_table/mod.rs @@ -153,7 +153,8 @@ impl SymbolTable { /// to a Symbol, a descriptor of what that name refers to. fn add_symbol(&mut self, id: &ItemId, fqsn: Fqsn, spec: SymbolSpec) { let def_id = self.def_id_store.fresh(); - let symbol = Rc::new(Symbol { fully_qualified_name: fqsn.clone(), spec, def_id }); + let local_name = fqsn.last_elem(); + let symbol = Rc::new( Symbol { fully_qualified_name: fqsn.clone(), local_name, spec, def_id }); self.symbol_trie.insert(&fqsn, def_id); self.id_to_def.insert(*id, def_id); self.def_to_symbol.insert(def_id, symbol); @@ -162,7 +163,8 @@ impl SymbolTable { fn populate_single_builtin(&mut self, fqsn: Fqsn, builtin: Builtin) { let def_id = self.def_id_store.fresh(); let spec = SymbolSpec::Builtin(builtin); - let symbol = Rc::new(Symbol { fully_qualified_name: fqsn.clone(), spec, def_id }); + let local_name = fqsn.last_elem(); + let symbol = Rc::new(Symbol { fully_qualified_name: fqsn.clone(), local_name, spec, def_id }); self.symbol_trie.insert(&fqsn, def_id); self.def_to_symbol.insert(def_id, symbol); @@ -173,13 +175,14 @@ impl SymbolTable { #[derive(Debug, Clone)] pub struct Symbol { fully_qualified_name: Fqsn, + local_name: Rc, spec: SymbolSpec, def_id: DefId, } impl Symbol { - pub fn local_name(&self) -> Rc { - self.fully_qualified_name.last_elem() + pub fn local_name(&self) -> &str { + self.local_name.as_ref() } pub fn def_id(&self) -> Option {