From f5328fac9d6069ccd04aec5c31a5c59f573f56bd Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 19 Oct 2021 00:07:02 -0700 Subject: [PATCH] More work in symbol_table, reduced_ast --- schala-lang/language/src/reduced_ast.rs | 3 +- schala-lang/language/src/symbol_table/mod.rs | 44 -------------------- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 0b47ce9..2192d94 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -189,6 +189,7 @@ impl<'a> Reducer<'a> { let Symbol { local_name, spec, .. } = match self.symbol_table.lookup_by_fqsn(&sym_name) { Some(s) => s, + //TODO investigate why this fails //None => return Expr::ReductionError(format!("Symbol {:?} not found", sym_name)), None => return Expr::Sym(name) }; @@ -197,7 +198,7 @@ impl<'a> Reducer<'a> { SymbolSpec::RecordConstructor { .. } => Expr::ReductionError(format!("AST reducer doesn't expect a RecordConstructor here")), SymbolSpec::DataConstructor { index, type_args, type_name } => Expr::Constructor { type_name: type_name.clone(), - name, + name: local_name.clone(), tag: index.clone(), arity: type_args.len(), }, diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 614b031..2c07818 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -107,37 +107,6 @@ impl NameTable { } } - -/// Keeps track of what names were used in a given namespace. Call try_register to add a name to -/// the table, or report an error if a name already exists. -struct DuplicateNameTrackTable { - table: HashMap, LineNumber>, -} - -impl DuplicateNameTrackTable { - fn new() -> DuplicateNameTrackTable { - DuplicateNameTrackTable { table: HashMap::new() } - } - - fn try_register(&mut self, name: &Rc, id: &ItemId, decl_locations: &DeclLocations) -> Result<(), LineNumber> { - match self.table.entry(name.clone()) { - Entry::Occupied(o) => { - let line_number = o.get(); - Err(*line_number) - }, - Entry::Vacant(v) => { - let line_number = if let Some(loc) = decl_locations.lookup(id) { - loc.line_num - } else { - 0 - }; - v.insert(line_number); - Ok(()) - } - } - } -} - #[derive(PartialEq, Eq, Hash, Debug, Clone, PartialOrd, Ord)] pub struct FullyQualifiedSymbolName(pub Vec); @@ -395,9 +364,6 @@ impl SymbolTable { fn add_symbols_from_scope<'a>(&'a mut self, statements: &Vec, scope_name_stack: &mut Vec) -> Result<(), String> { use self::ast::Declaration::*; - let mut seen_identifiers = DuplicateNameTrackTable::new(); - let mut seen_modules = DuplicateNameTrackTable::new(); - for statement in statements.iter() { match statement { Statement { kind: StatementKind::Declaration(decl), id, location, } => { @@ -405,13 +371,9 @@ impl SymbolTable { match decl { FuncSig(ref signature) => { - seen_identifiers.try_register(&signature.name, id, &self.decl_locations) - .map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?; self.add_function_signature(signature, scope_name_stack)? } FuncDecl(ref signature, ref body) => { - seen_identifiers.try_register(&signature.name, id, &self.decl_locations) - .map_err(|line| format!("Duplicate function definition: {}. It's already defined at {}", signature.name, line))?; self.add_function_signature(signature, scope_name_stack)?; scope_name_stack.push(ScopeSegment{ name: signature.name.clone(), @@ -421,13 +383,9 @@ impl SymbolTable { output? }, TypeDecl { name, body, mutable } => { - seen_identifiers.try_register(&name.name, &id, &self.decl_locations) - .map_err(|line| format!("Duplicate type definition: {}. It's already defined at {}", name.name, line))?; self.add_type_decl(name, body, mutable, scope_name_stack)? }, Binding { name, .. } => { - seen_identifiers.try_register(&name, &id, &self.decl_locations) - .map_err(|line| format!("Duplicate variable definition: {}. It's already defined at {}", name, line))?; self.add_new_symbol(name, scope_name_stack, SymbolSpec::Binding); } _ => () @@ -435,8 +393,6 @@ impl SymbolTable { }, Statement { kind: StatementKind::Module(ModuleSpecifier { name, contents}), id, location } => { self.decl_locations.add_location(id, *location); - seen_modules.try_register(name, id, &self.decl_locations) - .map_err(|line| format!("Duplicate module definition: {}. It's already defined at {}", name, line))?; scope_name_stack.push(ScopeSegment { name: name.clone() }); let output = self.add_symbols_from_scope(contents, scope_name_stack); scope_name_stack.pop();