Start work on name resolution
This commit is contained in:
parent
a054de56a2
commit
41cad61e34
@ -1,20 +1,42 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::symbol_table::{SymbolTable, ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName};
|
||||
use crate::ast::*;
|
||||
use crate::util::ScopeStack;
|
||||
|
||||
type FQSNPrefix = Vec<ScopeSegment>;
|
||||
|
||||
pub struct ScopeResolver<'a> {
|
||||
symbol_table: &'a mut SymbolTable
|
||||
symbol_table: &'a mut SymbolTable,
|
||||
name_scope_stack: ScopeStack<'a, Rc<String>, FQSNPrefix>,
|
||||
}
|
||||
|
||||
impl<'a> ScopeResolver<'a> {
|
||||
pub fn new(symbol_table: &'a mut SymbolTable) -> ScopeResolver {
|
||||
ScopeResolver { symbol_table }
|
||||
let name_scope_stack = ScopeStack::new(None);
|
||||
ScopeResolver { symbol_table, name_scope_stack }
|
||||
}
|
||||
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
||||
for statement in ast.statements.iter() {
|
||||
match statement.kind {
|
||||
StatementKind::Declaration(ref decl) => self.decl(decl),
|
||||
StatementKind::Expression(ref expr) => self.expr(expr),
|
||||
StatementKind::Import(_) => Ok(())
|
||||
StatementKind::Import(ImportSpecifier { ref path_components, ref imported_names, .. }) => {
|
||||
match imported_names {
|
||||
ImportedNames::All => unimplemented!(),
|
||||
ImportedNames::LastOfPath => {
|
||||
let name = path_components.last().unwrap(); //TODO handle better
|
||||
let fqsn_prefix = path_components.iter().map(|c| ScopeSegment {
|
||||
name: c.clone(), kind: ScopeSegmentKind::Type
|
||||
}).collect();
|
||||
self.name_scope_stack.insert(name.clone(), fqsn_prefix);
|
||||
()
|
||||
}
|
||||
ImportedNames::List(ref names) => unimplemented!()
|
||||
};
|
||||
//self.name_scope_stack.insert()
|
||||
Ok(())
|
||||
}
|
||||
}?;
|
||||
}
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user