Clean up some symbol table code

This commit is contained in:
Greg Shuflin 2021-11-01 21:34:45 -07:00
parent acc99fa0ef
commit 0bf0b3e2e8
2 changed files with 10 additions and 11 deletions

View File

@ -337,7 +337,7 @@ impl<'a> SymbolTableRunner<'a> {
let mut errors = vec![];
for statement in statements {
let Statement { id, kind, location } = statement; //TODO I'm not sure if I need to do anything with this ID
let Statement { id, kind, location } = statement;
let location = *location;
if let Err(err) = self.add_single_statement(id, kind, location, scope_stack, function_scope) {
errors.push(err);

View File

@ -43,13 +43,18 @@ impl<'a> ScopeResolver<'a> {
/// mappings.
fn lookup_name_in_scope(&mut self, name: &QualifiedName) {
let QualifiedName { id, components } = name;
let local_name = components.first().unwrap().clone();
let name_type = self.lexical_scopes.lookup(&local_name);
let fqsn = Fqsn { scopes: components.iter().map(|name| Scope::Name(name.clone())).collect() };
let symbol = self.symbol_table.fqsn_to_symbol.get(&fqsn);
//println!("\tFound lexical_scope entry: {:?} and {} symbol: {:?}", name_type, fqsn, symbol);
//TODO handle a "partial" qualified name, and also handle it down in the pattern-matching
//section
//TODO some of these if lets that look into the fqsn_to_symbol table should probaby fail
//with an error
if components.len() == 1 {
let local_name: Rc<String> = components[0].clone();
let name_type = self.lexical_scopes.lookup(&local_name);
match name_type {
Some(NameType::Import(fqsn)) => {
let symbol = self.symbol_table.fqsn_to_symbol.get(fqsn);
@ -70,18 +75,12 @@ impl<'a> ScopeResolver<'a> {
self.symbol_table.id_to_symbol.insert(*id, symbol);
}
}
None => {
//TODO see if I can reduce this duplicate code
let fqsn = Fqsn { scopes: vec![Scope::Name(local_name.clone())] };
let symbol = self.symbol_table.fqsn_to_symbol.get(&fqsn);
None =>
if let Some(symbol) = symbol {
self.symbol_table.id_to_symbol.insert(*id, symbol.clone());
}
}
},
}
} else {
let fqsn = Fqsn { scopes: components.iter().map(|name| Scope::Name(name.clone())).collect() };
let symbol = self.symbol_table.fqsn_to_symbol.get(&fqsn);
if let Some(symbol) = symbol {
self.symbol_table.id_to_symbol.insert(*id, symbol.clone());
}