Some refactoring

This commit is contained in:
Greg Shuflin 2021-11-26 03:41:12 -08:00
parent 0eccceabd9
commit 89a93d59c7

View File

@ -51,24 +51,34 @@ impl<'a> SymbolTablePopulator<'a> {
if let Err(err) = self.add_single_statement(id, kind, location, scope_stack, function_scope) { if let Err(err) = self.add_single_statement(id, kind, location, scope_stack, function_scope) {
errors.push(err); errors.push(err);
} else { } else {
let decl = match kind {
StatementKind::Declaration(decl) => decl,
_ => continue,
};
// If there's an error with a name, don't recurse into subscopes of that name // If there's an error with a name, don't recurse into subscopes of that name
let recursive_errs = match kind { let recursive_errs = match decl {
StatementKind::Declaration(Declaration::FuncDecl(signature, body)) => { Declaration::FuncDecl(signature, body) => {
let new_scope = ScopeSegment::Name(signature.name.clone()); let new_scope = ScopeSegment::Name(signature.name.clone());
scope_stack.push(new_scope); scope_stack.push(new_scope);
let output = self.add_from_scope(body.as_ref(), scope_stack, true); let output = self.add_from_scope(body.as_ref(), scope_stack, true);
scope_stack.pop(); scope_stack.pop();
output output
} }
StatementKind::Declaration(Declaration::Module { name, items }) => { Declaration::Module { name, items } => {
let new_scope = ScopeSegment::Name(name.clone()); let new_scope = ScopeSegment::Name(name.clone());
scope_stack.push(new_scope); scope_stack.push(new_scope);
let output = self.add_from_scope(items.as_ref(), scope_stack, false); let output = self.add_from_scope(items.as_ref(), scope_stack, false);
scope_stack.pop(); scope_stack.pop();
output output
} }
StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => Declaration::TypeDecl { name, body, mutable } =>
self.add_type_members(name, body, mutable, location, scope_stack), self.add_type_members(name, body, mutable, location, scope_stack),
/*
Declaration::Impl { type_name, body, .. } => {
},
*/
_ => vec![], _ => vec![],
}; };
errors.extend(recursive_errs.into_iter()); errors.extend(recursive_errs.into_iter());