New phases for name analysis.
This commit is contained in:
parent
af8f0b5dac
commit
273d197841
@ -31,7 +31,7 @@ pub fn name_analysis(paths: &Vec<PathBuf>) -> Result<(), Box<dyn std::error::Err
|
||||
let mut symbol_table = SymbolTable::new();
|
||||
add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols.");
|
||||
|
||||
let diagnostics = analyze_names(&compilation_units, &files, &mut symbol_table);
|
||||
let diagnostics = analyze_names(&mut compilation_units, &files, &mut symbol_table);
|
||||
if diagnostics.is_empty() {
|
||||
println!("Name analysis complete.");
|
||||
println!("{}", symbol_table);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/// The gather phase must exclusively gather all named items that can be used elsewhere.
|
||||
use crate::ast::ast_node::{AstNode, AstNodeRef, AstNodeRefMut};
|
||||
use crate::ast::ast_node::{AstNode, AstNodeRefMut};
|
||||
use crate::ast::node::{
|
||||
Class, Closure, ClosureParameter, CompilationUnit, ForStatement, Function, FunctionBody,
|
||||
GenericParameters, Identifier, IfClause, Interface, InterfaceDefaultFunction,
|
||||
@ -87,7 +87,7 @@ fn gather_node_children<'a>(
|
||||
diagnostics: &mut Vec<DmDiagnostic>,
|
||||
) {
|
||||
node.for_each_child_mut(&mut |child| {
|
||||
gather_node(child, symbol_table, fqn_context, diagnostics);
|
||||
gather_node(child, symbol_table, fqn_context, diagnostics);
|
||||
});
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ fn gather_node<'a>(
|
||||
AstNodeRefMut::ClosureParameter(closure_parameter) => {
|
||||
gather_closure_parameter(closure_parameter, symbol_table, fqn_context, diagnostics);
|
||||
}
|
||||
_ => todo!()
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -475,7 +475,12 @@ fn gather_function<'a>(
|
||||
);
|
||||
}
|
||||
symbol_table.push_scope(&format!("FunctionScope {}", function.identifier().name()));
|
||||
gather_node(function.generics_mut(), symbol_table, fqn_context, diagnostics);
|
||||
gather_node(
|
||||
function.generics_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
gather_node(
|
||||
function.parameters_mut(),
|
||||
symbol_table,
|
||||
@ -912,7 +917,12 @@ fn gather_member<'a>(
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
gather_node(member.type_use_mut(), symbol_table, fqn_context, diagnostics);
|
||||
gather_node(
|
||||
member.type_use_mut(),
|
||||
symbol_table,
|
||||
fqn_context,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
|
||||
fn gather_variable_declaration<'a>(
|
||||
|
||||
@ -27,6 +27,7 @@ use crate::name_analysis::first_pass::np1_compilation_unit;
|
||||
use crate::name_analysis::symbol_table::SymbolTable;
|
||||
use codespan_reporting::files::Files;
|
||||
use std::hash::Hash;
|
||||
use crate::name_analysis::second_pass::nap2_compilation_unit;
|
||||
|
||||
pub(self) mod fqn_context;
|
||||
mod gather;
|
||||
@ -53,7 +54,7 @@ pub fn analyze_names<'a, F: Files<'a, FileId = usize, Name = String>>(
|
||||
|
||||
// resolve symbols
|
||||
for compilation_unit in compilation_units {
|
||||
// resolve_compilation_unit(compilation_unit, symbol_table, &mut diagnostics);
|
||||
nap2_compilation_unit(compilation_unit, symbol_table, &mut diagnostics);
|
||||
}
|
||||
|
||||
diagnostics.into()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user