Box parts of Statement::Switch and ForLoop

Statement: 112 to 104
This commit is contained in:
Tad Hardesty 2020-11-23 20:11:44 -08:00
parent 2dcd579fa8
commit 13fd304f04
2 changed files with 9 additions and 5 deletions

View file

@ -1029,7 +1029,7 @@ pub enum Statement {
},
ForLoop {
init: Option<Box<Statement>>,
test: Option<Expression>,
test: Option<Box<Expression>>,
inc: Option<Box<Statement>>,
block: Block,
},
@ -1062,8 +1062,8 @@ pub enum Statement {
block: Block,
},
Switch {
input: Expression,
cases: Vec<(Spanned<Vec<Case>>, Block)>,
input: Box<Expression>,
cases: Box<[(Spanned<Vec<Case>>, Block)]>,
default: Option<Block>,
},
TryCatch {

View file

@ -1254,7 +1254,7 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
require!(self.exact(Token::Punct(Punctuation::RParen)));
spanned(Statement::ForLoop {
init: init.map(Box::new),
test,
test: test.map(Box::new),
inc: inc.map(Box::new),
block: require!(self.block(&LoopContext::ForLoop)),
})
@ -1385,7 +1385,11 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
None
};
require!(self.exact(Token::Punct(Punctuation::RBrace)));
spanned(Statement::Switch { input: expr, cases, default })
spanned(Statement::Switch {
input: Box::new(expr),
cases: cases.into_boxed_slice(),
default,
})
} else if let Some(()) = self.exact_ident("try")? {
let try_block = require!(self.block(loop_ctx));
self.skip_phantom_semicolons()?;