use crate::{
AstPath, Box, BoxSlice, CallArgs, DocComments, Expr, ParameterList, StrLit, VariableDefinition,
yul,
};
use solar_interface::{Ident, Span, SpannedOption};
#[derive(Debug)]
pub struct Block<'ast> {
pub span: Span,
pub stmts: BoxSlice<'ast, Stmt<'ast>>,
}
impl<'ast> std::ops::Deref for Block<'ast> {
type Target = [Stmt<'ast>];
fn deref(&self) -> &Self::Target {
self.stmts
}
}
impl<'ast> std::ops::DerefMut for Block<'ast> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.stmts
}
}
#[derive(Debug)]
pub struct Stmt<'ast> {
pub docs: DocComments<'ast>,
pub span: Span,
pub kind: StmtKind<'ast>,
}
#[derive(Debug)]
pub enum StmtKind<'ast> {
Assembly(StmtAssembly<'ast>),
DeclSingle(Box<'ast, VariableDefinition<'ast>>),
DeclMulti(BoxSlice<'ast, SpannedOption<VariableDefinition<'ast>>>, Box<'ast, Expr<'ast>>),
Block(Block<'ast>),
Break,
Continue,
DoWhile(Box<'ast, Stmt<'ast>>, Box<'ast, Expr<'ast>>),
Emit(AstPath<'ast>, CallArgs<'ast>),
Expr(Box<'ast, Expr<'ast>>),
For {
init: Option<Box<'ast, Stmt<'ast>>>,
cond: Option<Box<'ast, Expr<'ast>>>,
next: Option<Box<'ast, Expr<'ast>>>,
body: Box<'ast, Stmt<'ast>>,
},
If(Box<'ast, Expr<'ast>>, Box<'ast, Stmt<'ast>>, Option<Box<'ast, Stmt<'ast>>>),
Return(Option<Box<'ast, Expr<'ast>>>),
Revert(AstPath<'ast>, CallArgs<'ast>),
Try(Box<'ast, StmtTry<'ast>>),
UncheckedBlock(Block<'ast>),
While(Box<'ast, Expr<'ast>>, Box<'ast, Stmt<'ast>>),
Placeholder,
}
#[derive(Debug)]
pub struct StmtAssembly<'ast> {
pub dialect: Option<StrLit>,
pub flags: BoxSlice<'ast, StrLit>,
pub block: yul::Block<'ast>,
}
#[derive(Debug)]
pub struct StmtTry<'ast> {
pub expr: Box<'ast, Expr<'ast>>,
pub clauses: BoxSlice<'ast, TryCatchClause<'ast>>,
}
#[derive(Debug)]
pub struct TryCatchClause<'ast> {
pub span: Span,
pub name: Option<Ident>,
pub args: ParameterList<'ast>,
pub block: Block<'ast>,
}