diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index bb78424..50febf3 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -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; pub struct ScopeResolver<'a> { - symbol_table: &'a mut SymbolTable + symbol_table: &'a mut SymbolTable, + name_scope_stack: ScopeStack<'a, Rc, 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(())