pub const MAX_STATEMENT_DEPTH: usize = 500;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ControlFlowFrameType {
StatementList,
IfStatement,
ForStatement,
SelectCase,
WhileStatement,
DoStatement,
WithStatement,
}
#[derive(Debug, Clone)]
pub enum ControlFlowFrame {
StatementList {
depth: usize,
context: StatementListContext,
started: bool,
},
IfStatement {
phase: IfPhase,
depth: usize,
},
ForStatement {
phase: ForPhase,
is_for_each: bool,
depth: usize,
},
SelectCase {
phase: SelectPhase,
depth: usize,
},
WhileStatement {
phase: WhilePhase,
depth: usize,
},
DoStatement {
phase: DoPhase,
depth: usize,
},
WithStatement {
phase: WithPhase,
depth: usize,
},
}
#[derive(Debug, Copy, Clone)]
pub enum StatementListContext {
TopLevel,
IfThenBody,
ElseIfBody,
ElseBody,
ForBody,
SelectCaseBody,
WhileBody,
DoBody,
WithBody,
}
#[derive(Debug, Copy, Clone)]
pub enum IfPhase {
Start,
ThenBody,
CheckElseIf,
ElseIfBody,
CheckElse,
ElseBody,
Finish,
}
#[derive(Debug, Copy, Clone)]
pub enum ForPhase {
Start,
Body,
Finish,
}
#[derive(Debug, Copy, Clone)]
pub enum SelectPhase {
Start,
CaseClause,
CaseBody,
CheckNextCase,
CaseElseBody,
Finish,
}
#[derive(Debug, Copy, Clone)]
pub enum WhilePhase {
Start,
Body,
Finish,
}
#[derive(Debug, Copy, Clone)]
pub enum DoPhase {
Start,
Body,
Finish,
}
#[derive(Debug, Copy, Clone)]
pub enum WithPhase {
Start,
Body,
Finish,
}
impl ControlFlowFrame {
pub(crate) fn frame_type(&self) -> ControlFlowFrameType {
match self {
ControlFlowFrame::StatementList { .. } => ControlFlowFrameType::StatementList,
ControlFlowFrame::IfStatement { .. } => ControlFlowFrameType::IfStatement,
ControlFlowFrame::ForStatement { .. } => ControlFlowFrameType::ForStatement,
ControlFlowFrame::SelectCase { .. } => ControlFlowFrameType::SelectCase,
ControlFlowFrame::WhileStatement { .. } => ControlFlowFrameType::WhileStatement,
ControlFlowFrame::DoStatement { .. } => ControlFlowFrameType::DoStatement,
ControlFlowFrame::WithStatement { .. } => ControlFlowFrameType::WithStatement,
}
}
}