feat: execute source control flow and exact real arithmetic
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
use super::{
|
||||
Assignment, AstDocument, AstRoot, BinaryOp, Binding, Block, Class, Decl, DeclKind, Expr,
|
||||
ExprKind, Function, InteractiveInput, MemberAssignment, Name, Parameter, Program,
|
||||
ReturnStatement, Spanned, Stmt, StmtKind, UnaryOp,
|
||||
ExprKind, Function, IfStatement, InteractiveInput, MemberAssignment, Name, Parameter, Program,
|
||||
ReturnStatement, Spanned, Stmt, StmtKind, UnaryOp, WhileStatement,
|
||||
};
|
||||
use crate::Span;
|
||||
pub trait Visitor {
|
||||
@@ -102,6 +102,18 @@ pub trait Visitor {
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_if_statement(&mut self, node: &IfStatement) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_if_statement(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_while_statement(&mut self, node: &WhileStatement) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_while_statement(self, node);
|
||||
self.leave_node();
|
||||
result
|
||||
}
|
||||
fn visit_return_statement(&mut self, node: &ReturnStatement) -> Result<(), Self::Error> {
|
||||
self.enter_node(node.span())?;
|
||||
let result = walk_return_statement(self, node);
|
||||
@@ -243,6 +255,12 @@ pub fn walk_stmt_kind<V: Visitor + ?Sized>(
|
||||
StmtKind::MemberAssignment(value) => {
|
||||
visitor.visit_member_assignment(value)?;
|
||||
}
|
||||
StmtKind::If(value) => {
|
||||
visitor.visit_if_statement(value)?;
|
||||
}
|
||||
StmtKind::While(value) => {
|
||||
visitor.visit_while_statement(value)?;
|
||||
}
|
||||
StmtKind::Return(value) => {
|
||||
visitor.visit_return_statement(value)?;
|
||||
}
|
||||
@@ -280,6 +298,27 @@ pub fn walk_member_assignment<V: Visitor + ?Sized>(
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_if_statement<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &IfStatement,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_expr(&node.condition)?;
|
||||
visitor.visit_block(&node.body)?;
|
||||
if let Some(value) = &node.otherwise {
|
||||
visitor.visit_block(value)?;
|
||||
}
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_while_statement<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &WhileStatement,
|
||||
) -> Result<(), V::Error> {
|
||||
visitor.visit_expr(&node.condition)?;
|
||||
visitor.visit_block(&node.body)?;
|
||||
visitor.visit_span(&node.span)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn walk_return_statement<V: Visitor + ?Sized>(
|
||||
visitor: &mut V,
|
||||
node: &ReturnStatement,
|
||||
|
||||
Reference in New Issue
Block a user