Box the body of Statement::ForList

This commit is contained in:
Tad Hardesty 2021-11-20 17:26:15 -08:00
parent 3caa439608
commit 40fef0ecb3
4 changed files with 22 additions and 17 deletions

View file

@ -254,7 +254,8 @@ impl<'o> WalkProc<'o> {
}
self.visit_block(block);
},
Statement::ForList { in_list, block, var_type, name, .. } => {
Statement::ForList(for_list) => {
let ForListStatement { var_type, name, in_list, block, .. } = &**for_list;
if let Some(in_list) = in_list {
self.visit_expression(location, in_list, None);
}

View file

@ -1392,7 +1392,8 @@ impl<'o, 's> AnalyzeProc<'o, 's> {
state.end_loop();
return state
},
Statement::ForList { in_list, block, var_type, name, .. } => {
Statement::ForList(for_list) => {
let ForListStatement { var_type, name, input_type, in_list, block } = &**for_list;
let mut scoped_locals = local_vars.clone();
if let Some(in_list) = in_list {
let list = self.visit_expression(location, in_list, None, &mut scoped_locals);

View file

@ -1157,15 +1157,7 @@ pub enum Statement {
inc: Option<Box<Statement>>,
block: Block,
},
ForList {
var_type: Option<VarType>,
name: Ident2,
/// If zero, uses the declared type of the variable.
input_type: Option<InputType>,
/// Defaults to 'world'.
in_list: Option<Box<Expression>>,
block: Block,
},
ForList(Box<ForListStatement>),
ForRange(Box<ForRangeStatement>),
Var(Box<VarStatement>),
Vars(Vec<VarStatement>),
@ -1212,6 +1204,17 @@ pub enum Case {
Range(Expression, Expression),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ForListStatement {
pub var_type: Option<VarType>,
pub name: Ident2,
/// If zero, uses the declared type of the variable.
pub input_type: Option<InputType>,
/// Defaults to 'world'.
pub in_list: Option<Expression>,
pub block: Block,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ForRangeStatement {
pub var_type: Option<VarType>,

View file

@ -1308,13 +1308,13 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
rhs => {
// I love code duplication, don't you?
require!(self.exact(Token::Punct(Punctuation::RParen)));
return spanned(Statement::ForList {
return spanned(Statement::ForList(Box::new(ForListStatement {
var_type: None,
name: name.into(),
input_type: None,
in_list: Some(Box::new(rhs)),
in_list: Some(rhs),
block: require!(self.block(&LoopContext::ForList)),
});
})));
}
}
},
@ -1344,13 +1344,13 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
};
require!(self.exact(Token::Punct(Punctuation::RParen)));
spanned(Statement::ForList {
spanned(Statement::ForList(Box::new(ForListStatement {
var_type,
name: name.into(),
input_type,
in_list: in_list.map(Box::new),
in_list,
block: require!(self.block(&LoopContext::ForList)),
})
})))
} else {
require!(self.exact(Token::Punct(Punctuation::RParen)));
spanned(Statement::ForInfinite {