Start to use table lookups instead of Meta
For fqsn
This commit is contained in:
parent
8b1dd561f2
commit
e1a83b5de3
@ -14,8 +14,8 @@ fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
|
||||
let mut ast = crate::util::quick_ast(input);
|
||||
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
||||
{
|
||||
let t = &state.symbol_table_handle.borrow();
|
||||
let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&t);
|
||||
let mut t = &mut state.symbol_table_handle.borrow_mut();
|
||||
let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&mut t);
|
||||
let _ = scope_resolver.resolve(&mut ast);
|
||||
}
|
||||
|
||||
|
@ -158,8 +158,9 @@ impl<'a> Reducer<'a> {
|
||||
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
||||
PrefixExp(op, arg) => self.prefix(op, arg),
|
||||
Value(qualified_name) => {
|
||||
let ref sym_name = match expr.fqsn {
|
||||
Some(ref fqsn) => fqsn,
|
||||
let ref id = qualified_name.node().id;
|
||||
let ref sym_name = match symbol_table.get_fqsn_from_id(id) {
|
||||
Some(fqsn) => fqsn,
|
||||
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
|
||||
};
|
||||
//TODO this probably needs to change
|
||||
|
@ -145,8 +145,8 @@ fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut PassDebu
|
||||
}
|
||||
|
||||
fn scope_resolution(mut input: ast::AST, handle: &mut Schala, _com: Option<&mut PassDebugArtifact>) -> Result<ast::AST, String> {
|
||||
let symbol_table = handle.symbol_table.borrow();
|
||||
let mut resolver = crate::scope_resolution::ScopeResolver::new(&symbol_table);
|
||||
let mut symbol_table = handle.symbol_table.borrow_mut();
|
||||
let mut resolver = crate::scope_resolution::ScopeResolver::new(&mut symbol_table);
|
||||
let () = resolver.resolve(&mut input)?;
|
||||
Ok(input)
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ use crate::symbol_table::{SymbolTable, ScopeSegment, ScopeSegmentKind, FullyQual
|
||||
use crate::ast::*;
|
||||
|
||||
pub struct ScopeResolver<'a> {
|
||||
symbol_table: &'a SymbolTable
|
||||
symbol_table: &'a mut SymbolTable
|
||||
}
|
||||
|
||||
impl<'a> ScopeResolver<'a> {
|
||||
pub fn new(symbol_table: &'a SymbolTable) -> ScopeResolver {
|
||||
pub fn new(symbol_table: &'a mut SymbolTable) -> ScopeResolver {
|
||||
ScopeResolver { symbol_table }
|
||||
}
|
||||
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
||||
@ -43,7 +43,9 @@ impl<'a> ScopeResolver<'a> {
|
||||
match &mut inner_expr.kind {
|
||||
ExpressionKind::Value(qualified_name) => {
|
||||
let fqsn = lookup_name_in_scope(&qualified_name.node());
|
||||
expr.fqsn = Some(fqsn);
|
||||
let ref id = qualified_name.node().id;
|
||||
self.symbol_table.map_id_to_fqsn(id, fqsn);
|
||||
//expr.fqsn = Some(fqsn);
|
||||
},
|
||||
NamedStruct { name, .. } => {
|
||||
let fqsn = lookup_name_in_scope(&name.node());
|
||||
|
@ -97,7 +97,7 @@ impl SymbolTable {
|
||||
self.id_to_fqsn.insert(id.clone(), fqsn);
|
||||
}
|
||||
|
||||
pub fn get_fqsn_from_id(&mut self, id: &ItemId) -> Option<FullyQualifiedSymbolName> {
|
||||
pub fn get_fqsn_from_id(&self, id: &ItemId) -> Option<FullyQualifiedSymbolName> {
|
||||
self.id_to_fqsn.get(&id).cloned()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user