From 40fef0ecb3729f19eb4bb6c300b379c604f6d45c Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Sat, 20 Nov 2021 17:26:15 -0800 Subject: [PATCH] Box the body of Statement::ForList --- crates/dm-langserver/src/find_references.rs | 3 ++- crates/dreamchecker/src/lib.rs | 3 ++- crates/dreammaker/src/ast.rs | 21 ++++++++++++--------- crates/dreammaker/src/parser.rs | 12 ++++++------ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/dm-langserver/src/find_references.rs b/crates/dm-langserver/src/find_references.rs index f7f6fd22..35def452 100644 --- a/crates/dm-langserver/src/find_references.rs +++ b/crates/dm-langserver/src/find_references.rs @@ -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); } diff --git a/crates/dreamchecker/src/lib.rs b/crates/dreamchecker/src/lib.rs index 3774325e..2fe9c9bb 100644 --- a/crates/dreamchecker/src/lib.rs +++ b/crates/dreamchecker/src/lib.rs @@ -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); diff --git a/crates/dreammaker/src/ast.rs b/crates/dreammaker/src/ast.rs index ed0c2860..8c56347c 100644 --- a/crates/dreammaker/src/ast.rs +++ b/crates/dreammaker/src/ast.rs @@ -1157,15 +1157,7 @@ pub enum Statement { inc: Option>, block: Block, }, - ForList { - var_type: Option, - name: Ident2, - /// If zero, uses the declared type of the variable. - input_type: Option, - /// Defaults to 'world'. - in_list: Option>, - block: Block, - }, + ForList(Box), ForRange(Box), Var(Box), Vars(Vec), @@ -1212,6 +1204,17 @@ pub enum Case { Range(Expression, Expression), } +#[derive(Debug, Clone, PartialEq)] +pub struct ForListStatement { + pub var_type: Option, + pub name: Ident2, + /// If zero, uses the declared type of the variable. + pub input_type: Option, + /// Defaults to 'world'. + pub in_list: Option, + pub block: Block, +} + #[derive(Debug, Clone, PartialEq)] pub struct ForRangeStatement { pub var_type: Option, diff --git a/crates/dreammaker/src/parser.rs b/crates/dreammaker/src/parser.rs index e04c3d29..eb4e124d 100644 --- a/crates/dreammaker/src/parser.rs +++ b/crates/dreammaker/src/parser.rs @@ -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 {