Skip to content

Commit

Permalink
Remove standalone finalize statement from the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Nov 12, 2022
1 parent 232cbfb commit 060f57d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 79 deletions.
3 changes: 0 additions & 3 deletions compiler/ast/src/passes/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub trait StatementConsumer {
Statement::Decrement(stmt) => self.consume_decrement(stmt),
Statement::Definition(stmt) => self.consume_definition(stmt),
Statement::Expression(stmt) => self.consume_expression_statement(stmt),
Statement::Finalize(stmt) => self.consume_finalize(stmt),
Statement::Increment(stmt) => self.consume_increment(stmt),
Statement::Iteration(stmt) => self.consume_iteration(*stmt),
Statement::Return(stmt) => self.consume_return(stmt),
Expand All @@ -98,8 +97,6 @@ pub trait StatementConsumer {

fn consume_expression_statement(&mut self, input: ExpressionStatement) -> Self::Output;

fn consume_finalize(&mut self, input: FinalizeStatement) -> Self::Output;

fn consume_increment(&mut self, input: IncrementStatement) -> Self::Output;

fn consume_iteration(&mut self, input: IterationStatement) -> Self::Output;
Expand Down
21 changes: 6 additions & 15 deletions compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub trait StatementReconstructor: ExpressionReconstructor {
Statement::Decrement(stmt) => self.reconstruct_decrement(stmt),
Statement::Definition(stmt) => self.reconstruct_definition(stmt),
Statement::Expression(stmt) => self.reconstruct_expression_statement(stmt),
Statement::Finalize(stmt) => self.reconstruct_finalize(stmt),
Statement::Increment(stmt) => self.reconstruct_increment(stmt),
Statement::Iteration(stmt) => self.reconstruct_iteration(*stmt),
Statement::Return(stmt) => self.reconstruct_return(stmt),
Expand Down Expand Up @@ -270,20 +269,6 @@ pub trait StatementReconstructor: ExpressionReconstructor {
)
}

fn reconstruct_finalize(&mut self, input: FinalizeStatement) -> (Statement, Self::AdditionalOutput) {
(
Statement::Finalize(FinalizeStatement {
arguments: input
.arguments
.into_iter()
.map(|arg| self.reconstruct_expression(arg).0)
.collect(),
span: input.span,
}),
Default::default(),
)
}

fn reconstruct_increment(&mut self, input: IncrementStatement) -> (Statement, Self::AdditionalOutput) {
(
Statement::Increment(IncrementStatement {
Expand Down Expand Up @@ -317,6 +302,12 @@ pub trait StatementReconstructor: ExpressionReconstructor {
(
Statement::Return(ReturnStatement {
expression: self.reconstruct_expression(input.expression).0,
finalize_args: input.finalize_args.map(|arguments| {
arguments
.into_iter()
.map(|argument| self.reconstruct_expression(argument).0)
.collect()
}),
span: input.span,
}),
Default::default(),
Expand Down
12 changes: 5 additions & 7 deletions compiler/ast/src/passes/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {
Statement::Decrement(stmt) => self.visit_decrement(stmt),
Statement::Definition(stmt) => self.visit_definition(stmt),
Statement::Expression(stmt) => self.visit_expression_statement(stmt),
Statement::Finalize(stmt) => self.visit_finalize(stmt),
Statement::Increment(stmt) => self.visit_increment(stmt),
Statement::Iteration(stmt) => self.visit_iteration(stmt),
Statement::Return(stmt) => self.visit_return(stmt),
Expand Down Expand Up @@ -177,12 +176,6 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {
self.visit_expression(&input.expression, &Default::default());
}

fn visit_finalize(&mut self, input: &'a FinalizeStatement) {
input.arguments.iter().for_each(|expr| {
self.visit_expression(expr, &Default::default());
});
}

fn visit_increment(&mut self, input: &'a IncrementStatement) {
self.visit_expression(&input.amount, &Default::default());
self.visit_expression(&input.index, &Default::default());
Expand All @@ -197,6 +190,11 @@ pub trait StatementVisitor<'a>: ExpressionVisitor<'a> {

fn visit_return(&mut self, input: &'a ReturnStatement) {
self.visit_expression(&input.expression, &Default::default());
if let Some(arguments) = &input.finalize_args {
arguments.iter().for_each(|argument| {
self.visit_expression(argument, &Default::default());
})
}
}
}

Expand Down
46 changes: 0 additions & 46 deletions compiler/ast/src/statement/finalize.rs

This file was deleted.

8 changes: 0 additions & 8 deletions compiler/ast/src/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub use definition::*;
pub mod expression;
pub use expression::*;

pub mod finalize;
pub use finalize::*;

pub mod increment;
pub use increment::*;

Expand Down Expand Up @@ -71,8 +68,6 @@ pub enum Statement {
Definition(DefinitionStatement),
/// An expression statement
Expression(ExpressionStatement),
/// A finalize statement.
Finalize(FinalizeStatement),
/// An increment statement.
Increment(IncrementStatement),
/// A `for` statement.
Expand Down Expand Up @@ -101,7 +96,6 @@ impl fmt::Display for Statement {
Statement::Decrement(x) => x.fmt(f),
Statement::Definition(x) => x.fmt(f),
Statement::Expression(x) => x.fmt(f),
Statement::Finalize(x) => x.fmt(f),
Statement::Increment(x) => x.fmt(f),
Statement::Iteration(x) => x.fmt(f),
Statement::Return(x) => x.fmt(f),
Expand All @@ -120,7 +114,6 @@ impl Node for Statement {
Decrement(n) => n.span(),
Definition(n) => n.span(),
Expression(n) => n.span(),
Finalize(n) => n.span(),
Increment(n) => n.span(),
Iteration(n) => n.span(),
Return(n) => n.span(),
Expand All @@ -137,7 +130,6 @@ impl Node for Statement {
Decrement(n) => n.set_span(span),
Definition(n) => n.set_span(span),
Expression(n) => n.set_span(span),
Finalize(n) => n.set_span(span),
Increment(n) => n.set_span(span),
Iteration(n) => n.set_span(span),
Return(n) => n.set_span(span),
Expand Down
2 changes: 2 additions & 0 deletions compiler/ast/src/statement/return_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use std::fmt;
pub struct ReturnStatement {
/// The expression to return to the function caller.
pub expression: Expression,
/// Arguments to the finalize block.
pub finalize_args: Option<Vec<Expression>>,
/// The span of `return expression` excluding the semicolon.
pub span: Span,
}
Expand Down

0 comments on commit 060f57d

Please sign in to comment.