Symbol local_name

This commit is contained in:
Greg Shuflin 2021-11-27 03:39:10 -08:00
parent 89a93d59c7
commit 88dfa87e85

View File

@ -153,7 +153,8 @@ impl SymbolTable {
/// to a Symbol, a descriptor of what that name refers to. /// to a Symbol, a descriptor of what that name refers to.
fn add_symbol(&mut self, id: &ItemId, fqsn: Fqsn, spec: SymbolSpec) { fn add_symbol(&mut self, id: &ItemId, fqsn: Fqsn, spec: SymbolSpec) {
let def_id = self.def_id_store.fresh(); 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.symbol_trie.insert(&fqsn, def_id);
self.id_to_def.insert(*id, def_id); self.id_to_def.insert(*id, def_id);
self.def_to_symbol.insert(def_id, symbol); self.def_to_symbol.insert(def_id, symbol);
@ -162,7 +163,8 @@ impl SymbolTable {
fn populate_single_builtin(&mut self, fqsn: Fqsn, builtin: Builtin) { fn populate_single_builtin(&mut self, fqsn: Fqsn, builtin: Builtin) {
let def_id = self.def_id_store.fresh(); let def_id = self.def_id_store.fresh();
let spec = SymbolSpec::Builtin(builtin); 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.symbol_trie.insert(&fqsn, def_id);
self.def_to_symbol.insert(def_id, symbol); self.def_to_symbol.insert(def_id, symbol);
@ -173,13 +175,14 @@ impl SymbolTable {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Symbol { pub struct Symbol {
fully_qualified_name: Fqsn, fully_qualified_name: Fqsn,
local_name: Rc<String>,
spec: SymbolSpec, spec: SymbolSpec,
def_id: DefId, def_id: DefId,
} }
impl Symbol { impl Symbol {
pub fn local_name(&self) -> Rc<String> { pub fn local_name(&self) -> &str {
self.fully_qualified_name.last_elem() self.local_name.as_ref()
} }
pub fn def_id(&self) -> Option<DefId> { pub fn def_id(&self) -> Option<DefId> {