WIP bringing back name analysis.
This commit is contained in:
parent
cfe24aa107
commit
6e37e3a5dd
@ -1,10 +1,10 @@
|
|||||||
// mod name_analysis;
|
mod name_analysis;
|
||||||
mod p3;
|
mod p3;
|
||||||
// mod unparse;
|
// mod unparse;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
// use crate::name_analysis::name_analysis;
|
use crate::name_analysis::name_analysis;
|
||||||
use crate::p3::pretty_print_parse;
|
use crate::p3::pretty_print_parse;
|
||||||
// use crate::unparse::unparse;
|
// use crate::unparse::unparse;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
@ -44,12 +44,12 @@ fn main() {
|
|||||||
pretty_print_parse(&path)
|
pretty_print_parse(&path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Commands::NameAnalysis { paths } => {
|
Commands::NameAnalysis { paths } => {
|
||||||
// let result = name_analysis(&paths);
|
let result = name_analysis(&paths);
|
||||||
// if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
// eprintln!("{}", e)
|
eprintln!("{}", e)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,7 @@ pub fn name_analysis(paths: &Vec<PathBuf>) -> Result<(), Box<dyn std::error::Err
|
|||||||
|
|
||||||
match parse_result {
|
match parse_result {
|
||||||
Ok(mut pairs) => {
|
Ok(mut pairs) => {
|
||||||
let compilation_unit_pair = pairs.next().unwrap();
|
let compilation_unit = build_ast(file_id, &mut pairs);
|
||||||
let compilation_unit = build_ast(&path.display().to_string(), file_id, compilation_unit_pair);
|
|
||||||
compilation_units.push(compilation_unit);
|
compilation_units.push(compilation_unit);
|
||||||
Ok::<(), Box<dyn std::error::Error>>(())
|
Ok::<(), Box<dyn std::error::Error>>(())
|
||||||
}
|
}
|
||||||
@ -32,7 +31,10 @@ 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(&mut compilation_units, &mut symbol_table);
|
let diagnostics = analyze_names(
|
||||||
|
&mut compilation_units.iter().map(Box::as_mut),
|
||||||
|
&mut symbol_table
|
||||||
|
);
|
||||||
if diagnostics.is_empty() {
|
if diagnostics.is_empty() {
|
||||||
println!("Name analysis complete.");
|
println!("Name analysis complete.");
|
||||||
println!("Symbol table\n-------\n{}", symbol_table);
|
println!("Symbol table\n-------\n{}", symbol_table);
|
||||||
@ -5,7 +5,7 @@ extern crate core;
|
|||||||
pub mod ast;
|
pub mod ast;
|
||||||
pub mod diagnostic;
|
pub mod diagnostic;
|
||||||
pub mod module;
|
pub mod module;
|
||||||
// pub mod name_analysis;
|
pub mod name_analysis;
|
||||||
pub mod object_file;
|
pub mod object_file;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
pub mod std_core;
|
pub mod std_core;
|
||||||
|
|||||||
1320
src/name_analysis/gather.rs
Normal file
1320
src/name_analysis/gather.rs
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -32,7 +32,7 @@ pub mod symbol;
|
|||||||
pub mod symbol_table;
|
pub mod symbol_table;
|
||||||
|
|
||||||
pub fn analyze_names(
|
pub fn analyze_names(
|
||||||
compilation_units: &mut Vec<CompilationUnit>,
|
compilation_units: &mut [CompilationUnit],
|
||||||
symbol_table: &mut SymbolTable,
|
symbol_table: &mut SymbolTable,
|
||||||
) -> Vec<DmDiagnostic> {
|
) -> Vec<DmDiagnostic> {
|
||||||
let mut diagnostics = vec![];
|
let mut diagnostics = vec![];
|
||||||
@ -1,11 +1,9 @@
|
|||||||
use crate::ast::node::named::Named;
|
|
||||||
use crate::ast::node::*;
|
use crate::ast::node::*;
|
||||||
use crate::diagnostic::DmDiagnostic;
|
use crate::diagnostic::DmDiagnostic;
|
||||||
use crate::name_analysis::symbol::Symbol;
|
use crate::name_analysis::symbol::Symbol;
|
||||||
use crate::name_analysis::symbol_table::{SymbolLookupError, SymbolTable};
|
use crate::name_analysis::symbol_table::{SymbolLookupError, SymbolTable};
|
||||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||||
use std::range::Range;
|
use std::range::Range;
|
||||||
/* Type Use */
|
|
||||||
|
|
||||||
fn resolve_type_use(
|
fn resolve_type_use(
|
||||||
type_use: &mut TypeUse,
|
type_use: &mut TypeUse,
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
use crate::ast::node::Identifier;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@ -1,14 +1,14 @@
|
|||||||
// use crate::name_analysis::symbol::{FunctionSymbol, ParameterSymbol};
|
use crate::name_analysis::symbol::{FunctionSymbol, ParameterSymbol};
|
||||||
// use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
|
||||||
//
|
|
||||||
// pub fn add_std_core_symbols(symbol_table: &mut SymbolTable) -> Result<(), SymbolInsertError> {
|
pub fn add_std_core_symbols(symbol_table: &mut SymbolTable) -> Result<(), SymbolInsertError> {
|
||||||
// symbol_table.insert_function_symbol(
|
symbol_table.insert_function_symbol(
|
||||||
// FunctionSymbol::new("std::core::println", "println", true, true, None)
|
FunctionSymbol::new("std::core::println", "println", true, true, None)
|
||||||
// .with_parameters(vec![ParameterSymbol::new("msg", None)]),
|
.with_parameters(vec![ParameterSymbol::new("msg", None)]),
|
||||||
// )?;
|
)?;
|
||||||
// symbol_table.insert_function_symbol(
|
symbol_table.insert_function_symbol(
|
||||||
// FunctionSymbol::new("std::core::print", "print", true, true, None)
|
FunctionSymbol::new("std::core::print", "print", true, true, None)
|
||||||
// .with_parameters(vec![ParameterSymbol::new("msg", None)]),
|
.with_parameters(vec![ParameterSymbol::new("msg", None)]),
|
||||||
// )?;
|
)?;
|
||||||
// Ok(())
|
Ok(())
|
||||||
// }
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user