From 75356d2972f8b2b5acbfc833421340f4dd2850b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 5 Feb 2020 02:27:00 +0100 Subject: [PATCH] Remove variable declaration stack --- src/ast.rs | 65 ------------------------------------------------------ 1 file changed, 65 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 3e9026b..95f632b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -128,71 +128,6 @@ impl VariableDeclaration pub type VariableDeclarations = Vec>; -pub struct VariableDeclarationStack -{ - pub free_variable_declarations: VariableDeclarations, - bound_variable_declaration_stack: Vec>, -} - -impl VariableDeclarationStack -{ - pub fn new() -> Self - { - Self - { - free_variable_declarations: VariableDeclarations::new(), - bound_variable_declaration_stack: vec![], - } - } - - pub fn find(&self, variable_name: &str) -> Option> - { - for variable_declarations in self.bound_variable_declaration_stack.iter().rev() - { - if let Some(variable_declaration) = variable_declarations.iter().find(|x| x.name == variable_name) - { - return Some(std::rc::Rc::clone(&variable_declaration)); - } - } - - if let Some(variable_declaration) = self.free_variable_declarations.iter().find(|x| x.name == variable_name) - { - return Some(std::rc::Rc::clone(&variable_declaration)); - } - - None - } - - pub fn find_or_create(&mut self, variable_name: &str) -> std::rc::Rc - { - if let Some(variable_declaration) = self.find(variable_name) - { - return variable_declaration; - } - - let variable_declaration = VariableDeclaration - { - name: variable_name.to_owned(), - }; - let variable_declaration = std::rc::Rc::new(variable_declaration); - - self.free_variable_declarations.push(std::rc::Rc::clone(&variable_declaration)); - - variable_declaration - } - - pub fn push(&mut self, bound_variable_declarations: std::rc::Rc) - { - self.bound_variable_declaration_stack.push(bound_variable_declarations); - } - - pub fn pop(&mut self) - { - // TODO: return error instead - self.bound_variable_declaration_stack.pop().expect("bound variable is empty, cannot pop last element"); - } -} - // Terms pub struct BinaryOperation