Use vec of duplicate errors
This commit is contained in:
parent
d3378c3210
commit
9640a5b05b
@ -134,7 +134,10 @@ impl SymbolTable {
|
|||||||
/// compilation process.
|
/// compilation process.
|
||||||
pub fn process_ast(&mut self, ast: &ast::AST) -> Result<(), String> {
|
pub fn process_ast(&mut self, ast: &ast::AST) -> Result<(), String> {
|
||||||
|
|
||||||
self.populate_name_tables(ast)?;
|
let errs = self.populate_name_tables(ast);
|
||||||
|
if !errs.is_empty() {
|
||||||
|
return Err(format!("{:?}", errs));
|
||||||
|
}
|
||||||
self.resolve_symbol_ids(ast)?;
|
self.resolve_symbol_ids(ast)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -211,14 +214,12 @@ impl SymbolTable {
|
|||||||
/// constants, functions, types, and modules defined within. This simultaneously
|
/// constants, functions, types, and modules defined within. This simultaneously
|
||||||
/// checks for dupicate definitions (and returns errors if discovered), and sets
|
/// checks for dupicate definitions (and returns errors if discovered), and sets
|
||||||
/// up name tables that will be used by further parts of the compiler
|
/// up name tables that will be used by further parts of the compiler
|
||||||
fn populate_name_tables(&mut self, ast: &ast::AST) -> Result<(), String> {
|
fn populate_name_tables(&mut self, ast: &ast::AST) -> Vec<DuplicateName> {
|
||||||
let mut scope_stack = vec![];
|
let mut scope_stack = vec![];
|
||||||
self.add_from_scope(ast.statements.as_ref(), &mut scope_stack)
|
self.add_from_scope(ast.statements.as_ref(), &mut scope_stack)
|
||||||
.map_err(|err| format!("{:?}", err))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec<Scope>) -> Result<(), Vec<DuplicateName>> {
|
fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec<Scope>) -> Vec<DuplicateName> {
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
|
|
||||||
for statement in statements {
|
for statement in statements {
|
||||||
@ -245,19 +246,12 @@ impl SymbolTable {
|
|||||||
StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => {
|
StatementKind::Declaration(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)
|
||||||
}
|
}
|
||||||
_ => Ok(())
|
_ => vec![]
|
||||||
};
|
};
|
||||||
|
errors.extend(recursive_errs.into_iter());
|
||||||
if let Err(errs) = recursive_errs {
|
|
||||||
errors.extend(errs.into_iter());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.is_empty() {
|
errors
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(errors)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_single_statement(&mut self, kind: &StatementKind, location: Location, scope_stack: &Vec<Scope>) -> Result<(), DuplicateName> {
|
fn add_single_statement(&mut self, kind: &StatementKind, location: Location, scope_stack: &Vec<Scope>) -> Result<(), DuplicateName> {
|
||||||
@ -304,7 +298,7 @@ impl SymbolTable {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec<Scope>) -> Result<(), Vec<DuplicateName>> {
|
fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec<Scope>) -> Vec<DuplicateName> {
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
|
|
||||||
let mut register = |fqsn: FQSN, spec: SymbolSpec| {
|
let mut register = |fqsn: FQSN, spec: SymbolSpec| {
|
||||||
@ -378,11 +372,6 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scope_stack.pop();
|
scope_stack.pop();
|
||||||
|
errors
|
||||||
if errors.is_empty() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(errors)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user