use crate::CompilerState;
use leo_ast::{AstVisitor, Expression, Node as _, Path, ProgramVisitor, TupleAccess, Type};
use indexmap::IndexSet;
pub struct SymbolAccessCollector<'a> {
state: &'a CompilerState,
pub symbol_accesses: IndexSet<(Path, Option<usize>)>,
}
impl<'a> SymbolAccessCollector<'a> {
pub fn new(state: &'a mut CompilerState) -> Self {
Self { state, symbol_accesses: IndexSet::new() }
}
}
impl AstVisitor for SymbolAccessCollector<'_> {
type AdditionalInput = ();
type Output = ();
fn visit_path(&mut self, input: &Path, _: &Self::AdditionalInput) -> Self::Output {
self.symbol_accesses.insert((input.clone(), None));
}
fn visit_tuple_access(&mut self, input: &TupleAccess, _: &Self::AdditionalInput) -> Self::Output {
if let Expression::Path(path) = &input.tuple {
if let Some(Type::Future(_)) = self.state.type_table.get(&input.tuple.id()) {
self.symbol_accesses.insert((path.clone(), None));
} else {
self.symbol_accesses.insert((path.clone(), Some(input.index.value())));
}
} else {
self.visit_expression(&input.tuple, &());
}
}
}
impl ProgramVisitor for SymbolAccessCollector<'_> {}