-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
317668a
commit 241b2ad
Showing
5 changed files
with
89 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod expr; | |
pub mod parse; | ||
pub mod parser_context; | ||
pub mod scope; | ||
pub mod stmt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use crate::tokenize::debug_infos::DebugInfo; | ||
|
||
use super::{ | ||
declaration::Declaration, | ||
expr::Expr, | ||
parse::{ForInitKind, LabelKind, StmtKind}, | ||
}; | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq, Clone, Debug)] | ||
pub struct Stmt { | ||
pub kind: StmtKind, | ||
pub debug_info: DebugInfo, | ||
} | ||
|
||
impl Stmt { | ||
pub const fn expr(expr: Expr, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Expr(expr), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub const fn ret(expr: Option<Expr>, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Return(expr), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_block(stmts: Vec<Stmt>, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Block(stmts), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_if(cond: Expr, then: Stmt, els: Option<Stmt>, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::If(cond, Box::new(then), els.map(Box::new)), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_while(cond: Expr, then: Stmt, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::While(cond, Box::new(then)), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_for( | ||
init: Option<ForInitKind>, | ||
cond: Option<Expr>, | ||
inc: Option<Expr>, | ||
then: Stmt, | ||
debug_info: DebugInfo, | ||
) -> Self { | ||
Self { | ||
kind: StmtKind::For(init, cond, inc, Box::new(then)), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_switch(expr: Expr, stmt: Stmt, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Switch(expr, Box::new(stmt)), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub fn new_labeled_stmt(label_kind: LabelKind, stmt: Stmt, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Labeled(label_kind, Box::new(stmt)), | ||
debug_info, | ||
} | ||
} | ||
|
||
pub const fn new_declare(declaration: Declaration, debug_info: DebugInfo) -> Self { | ||
Self { | ||
kind: StmtKind::Declare(declaration), | ||
debug_info, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters