Fix a number of TODOs

Add def -> symbol lookup table
Minor syntax changes
This commit is contained in:
Greg Shuflin 2021-10-30 17:37:02 -07:00
parent 53112c9f9d
commit ea494bb328
2 changed files with 7 additions and 5 deletions

View File

@ -92,8 +92,8 @@ pub fn walk_expression<V: ASTVisitor>(v: &mut V, expr: &Expression) {
walk_expression(v, f);
for arg in arguments.iter() {
match arg {
InvocationArgument::Positional(expr) => walk_expression(v, expr),
InvocationArgument::Keyword { expr, .. } => walk_expression(v, expr), //TODO maybe I can combine this pattern
InvocationArgument::Positional(expr) | InvocationArgument::Keyword { expr, .. } =>
walk_expression(v, expr),
_ => (),
}
}

View File

@ -147,6 +147,7 @@ pub struct SymbolTable {
fqsn_to_symbol: HashMap<Fqsn, Rc<Symbol>>,
id_to_symbol: HashMap<ItemId, Rc<Symbol>>,
def_to_symbol: HashMap<DefId, Rc<Symbol>>,
}
impl SymbolTable {
@ -159,6 +160,7 @@ impl SymbolTable {
fqsn_to_symbol: HashMap::new(),
id_to_symbol: HashMap::new(),
def_to_symbol: HashMap::new(),
}
}
@ -184,9 +186,8 @@ impl SymbolTable {
self.id_to_symbol.get(id).map(|s| s.as_ref())
}
//TODO optimize this
pub fn lookup_symbol_by_def(&self, def: &DefId) -> Option<&Symbol> {
self.id_to_symbol.iter().find(|(_, sym)| sym.def_id == *def).map(|(_, sym)| sym.as_ref())
self.def_to_symbol.get(def).map(|s| s.as_ref())
}
#[allow(dead_code)]
@ -205,7 +206,8 @@ impl SymbolTable {
let symbol = Rc::new(Symbol { fully_qualified_name: fqsn.clone(), spec, def_id });
self.symbol_trie.insert(&fqsn);
self.fqsn_to_symbol.insert(fqsn, symbol.clone());
self.id_to_symbol.insert(*id, symbol);
self.id_to_symbol.insert(*id, symbol.clone());
self.def_to_symbol.insert(def_id, symbol);
}
}