mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 02:31:44 +03:00
Refactor SymbolTable creation pass to be compatible with new Visitor pattern
This commit is contained in:
parent
a60439eb8a
commit
7b5632be90
@ -36,22 +36,23 @@ impl<'a> CreateSymbolTable<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExpressionVisitor<'a> for CreateSymbolTable<'a> {}
|
||||
impl<'a> ExpressionVisitor<'a> for CreateSymbolTable<'a> {
|
||||
type AdditionalInput = ();
|
||||
type Output = ();
|
||||
}
|
||||
|
||||
impl<'a> StatementVisitor<'a> for CreateSymbolTable<'a> {}
|
||||
|
||||
impl<'a> ProgramVisitor<'a> for CreateSymbolTable<'a> {
|
||||
fn visit_function(&mut self, input: &'a Function) -> VisitResult {
|
||||
fn visit_function(&mut self, input: &'a Function) {
|
||||
if let Err(err) = self.symbol_table.insert_fn(input.name(), input) {
|
||||
self.handler.emit_err(err);
|
||||
}
|
||||
VisitResult::SkipChildren
|
||||
}
|
||||
|
||||
fn visit_circuit(&mut self, input: &'a Circuit) -> VisitResult {
|
||||
fn visit_circuit(&mut self, input: &'a Circuit) {
|
||||
if let Err(err) = self.symbol_table.insert_circuit(input.name(), input) {
|
||||
self.handler.emit_err(err);
|
||||
}
|
||||
VisitResult::SkipChildren
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +0,0 @@
|
||||
// Copyright (C) 2019-2022 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::{ExpressionVisitorDirector, ProgramVisitorDirector, StatementVisitorDirector, VisitorDirector};
|
||||
use leo_errors::emitter::Handler;
|
||||
|
||||
use crate::CreateSymbolTable;
|
||||
|
||||
pub(crate) struct Director<'a> {
|
||||
visitor: CreateSymbolTable<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Director<'a> {
|
||||
pub(crate) fn new(handler: &'a Handler) -> Self {
|
||||
Self {
|
||||
visitor: CreateSymbolTable::new(handler),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VisitorDirector<'a> for Director<'a> {
|
||||
type Visitor = CreateSymbolTable<'a>;
|
||||
|
||||
fn visitor(self) -> Self::Visitor {
|
||||
self.visitor
|
||||
}
|
||||
|
||||
fn visitor_ref(&mut self) -> &mut Self::Visitor {
|
||||
&mut self.visitor
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExpressionVisitorDirector<'a> for Director<'a> {
|
||||
type AdditionalInput = ();
|
||||
type Output = ();
|
||||
}
|
||||
|
||||
impl<'a> StatementVisitorDirector<'a> for Director<'a> {}
|
||||
|
||||
impl<'a> ProgramVisitorDirector<'a> for Director<'a> {}
|
@ -17,9 +17,6 @@
|
||||
pub mod create;
|
||||
pub use create::*;
|
||||
|
||||
pub mod director;
|
||||
use director::*;
|
||||
|
||||
pub mod table;
|
||||
pub use table::*;
|
||||
|
||||
@ -31,7 +28,7 @@ pub use variable_symbol::*;
|
||||
|
||||
use crate::Pass;
|
||||
|
||||
use leo_ast::{Ast, ProgramVisitorDirector, VisitorDirector};
|
||||
use leo_ast::{Ast, ProgramVisitor};
|
||||
use leo_errors::{emitter::Handler, Result};
|
||||
|
||||
impl<'a> Pass for CreateSymbolTable<'a> {
|
||||
@ -39,7 +36,7 @@ impl<'a> Pass for CreateSymbolTable<'a> {
|
||||
type Output = Result<SymbolTable<'a>>;
|
||||
|
||||
fn do_pass((ast, handler): Self::Input) -> Self::Output {
|
||||
let mut visitor = Director::new(handler);
|
||||
let mut visitor = CreateSymbolTable::new(handler);
|
||||
visitor.visit_program(ast.as_repr());
|
||||
handler.last_err()?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user