Resolver - Return the map of resolved variables

This commit is contained in:
Emmanuel BENOîT 2023-01-03 12:56:40 +01:00
parent 376f28044c
commit 1346e0ccf0

View file

@ -2,10 +2,12 @@ use std::collections::HashMap;
use crate::{ast, errors::ParserError, tokens::Token}; use crate::{ast, errors::ParserError, tokens::Token};
pub fn resolve_variables(program: &ast::ProgramNode) -> ResolverResult { pub type ResolvedVariables = HashMap<*const ast::ExprNode, usize>;
pub fn resolve_variables(program: &ast::ProgramNode) -> Result<ResolvedVariables, ParserError> {
let mut state = ResolverState::default(); let mut state = ResolverState::default();
program.resolve(&mut state)?; program.resolve(&mut state)?;
Ok(()) Ok(state.resolved)
} }
type ResolverResult = Result<(), ParserError>; type ResolverResult = Result<(), ParserError>;
@ -13,7 +15,7 @@ type ResolverResult = Result<(), ParserError>;
#[derive(Default)] #[derive(Default)]
struct ResolverState { struct ResolverState {
scopes: Vec<HashMap<String, bool>>, scopes: Vec<HashMap<String, bool>>,
resolved: HashMap<*const ast::ExprNode, usize>, resolved: ResolvedVariables,
} }
impl ResolverState { impl ResolverState {