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();
|
let mut symbol_table = SymbolTable::new();
|
||||||
add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols.");
|
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() {
|
if diagnostics.is_empty() {
|
||||||
println!("Name analysis complete.");
|
println!("Name analysis complete.");
|
||||||
println!("{}", symbol_table);
|
println!("{}", symbol_table);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/// The gather phase must exclusively gather all named items that can be used elsewhere.
|
/// 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::{
|
use crate::ast::node::{
|
||||||
Class, Closure, ClosureParameter, CompilationUnit, ForStatement, Function, FunctionBody,
|
Class, Closure, ClosureParameter, CompilationUnit, ForStatement, Function, FunctionBody,
|
||||||
GenericParameters, Identifier, IfClause, Interface, InterfaceDefaultFunction,
|
GenericParameters, Identifier, IfClause, Interface, InterfaceDefaultFunction,
|
||||||
@ -87,7 +87,7 @@ fn gather_node_children<'a>(
|
|||||||
diagnostics: &mut Vec<DmDiagnostic>,
|
diagnostics: &mut Vec<DmDiagnostic>,
|
||||||
) {
|
) {
|
||||||
node.for_each_child_mut(&mut |child| {
|
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) => {
|
AstNodeRefMut::ClosureParameter(closure_parameter) => {
|
||||||
gather_closure_parameter(closure_parameter, symbol_table, fqn_context, diagnostics);
|
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()));
|
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(
|
gather_node(
|
||||||
function.parameters_mut(),
|
function.parameters_mut(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
@ -912,7 +917,12 @@ fn gather_member<'a>(
|
|||||||
diagnostics,
|
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>(
|
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 crate::name_analysis::symbol_table::SymbolTable;
|
||||||
use codespan_reporting::files::Files;
|
use codespan_reporting::files::Files;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use crate::name_analysis::second_pass::nap2_compilation_unit;
|
||||||
|
|
||||||
pub(self) mod fqn_context;
|
pub(self) mod fqn_context;
|
||||||
mod gather;
|
mod gather;
|
||||||
@ -53,7 +54,7 @@ pub fn analyze_names<'a, F: Files<'a, FileId = usize, Name = String>>(
|
|||||||
|
|
||||||
// resolve symbols
|
// resolve symbols
|
||||||
for compilation_unit in compilation_units {
|
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()
|
diagnostics.into()
|
||||||
|
|||||||
@ -377,14 +377,14 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
Err(NoDefinition)
|
Err(NoDefinition)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_usable_by_fqn(
|
pub fn resolve_usable_by_fqn(
|
||||||
&self,
|
&self,
|
||||||
fqn: &str
|
fqn: &str
|
||||||
) -> Result<Symbol, SymbolLookupError> {
|
) -> Result<Symbol, SymbolLookupError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_usable_star(
|
pub fn resolve_usable_star(
|
||||||
&self,
|
&self,
|
||||||
base_fqn: &str,
|
base_fqn: &str,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user