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);
|
let mut ast = crate::util::quick_ast(input);
|
||||||
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
|
||||||
{
|
{
|
||||||
let t = &state.symbol_table_handle.borrow();
|
let mut t = &mut state.symbol_table_handle.borrow_mut();
|
||||||
let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&t);
|
let mut scope_resolver = crate::scope_resolution::ScopeResolver::new(&mut t);
|
||||||
let _ = scope_resolver.resolve(&mut ast);
|
let _ = scope_resolver.resolve(&mut ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,8 +158,9 @@ impl<'a> Reducer<'a> {
|
|||||||
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
||||||
PrefixExp(op, arg) => self.prefix(op, arg),
|
PrefixExp(op, arg) => self.prefix(op, arg),
|
||||||
Value(qualified_name) => {
|
Value(qualified_name) => {
|
||||||
let ref sym_name = match expr.fqsn {
|
let ref id = qualified_name.node().id;
|
||||||
Some(ref fqsn) => fqsn,
|
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)),
|
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
|
||||||
};
|
};
|
||||||
//TODO this probably needs to change
|
//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> {
|
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 symbol_table = handle.symbol_table.borrow_mut();
|
||||||
let mut resolver = crate::scope_resolution::ScopeResolver::new(&symbol_table);
|
let mut resolver = crate::scope_resolution::ScopeResolver::new(&mut symbol_table);
|
||||||
let () = resolver.resolve(&mut input)?;
|
let () = resolver.resolve(&mut input)?;
|
||||||
Ok(input)
|
Ok(input)
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ use crate::symbol_table::{SymbolTable, ScopeSegment, ScopeSegmentKind, FullyQual
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
|
|
||||||
pub struct ScopeResolver<'a> {
|
pub struct ScopeResolver<'a> {
|
||||||
symbol_table: &'a SymbolTable
|
symbol_table: &'a mut SymbolTable
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ScopeResolver<'a> {
|
impl<'a> ScopeResolver<'a> {
|
||||||
pub fn new(symbol_table: &'a SymbolTable) -> ScopeResolver {
|
pub fn new(symbol_table: &'a mut SymbolTable) -> ScopeResolver {
|
||||||
ScopeResolver { symbol_table }
|
ScopeResolver { symbol_table }
|
||||||
}
|
}
|
||||||
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
||||||
@ -43,7 +43,9 @@ impl<'a> ScopeResolver<'a> {
|
|||||||
match &mut inner_expr.kind {
|
match &mut inner_expr.kind {
|
||||||
ExpressionKind::Value(qualified_name) => {
|
ExpressionKind::Value(qualified_name) => {
|
||||||
let fqsn = lookup_name_in_scope(&qualified_name.node());
|
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, .. } => {
|
NamedStruct { name, .. } => {
|
||||||
let fqsn = lookup_name_in_scope(&name.node());
|
let fqsn = lookup_name_in_scope(&name.node());
|
||||||
|
@ -97,7 +97,7 @@ impl SymbolTable {
|
|||||||
self.id_to_fqsn.insert(id.clone(), fqsn);
|
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()
|
self.id_to_fqsn.get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user