From 348065031421440313edeae70b5080d9c88e70d9 Mon Sep 17 00:00:00 2001 From: Jan Max Meyer Date: Thu, 15 Feb 2024 13:53:24 +0100 Subject: [PATCH] ImlValue::Instance doesn't require for Option-arguments By mistake, 0c0fc4417166764c49d491a94c6974f20cfb9483 introduced Option in the ImlValue::Instance itself, which totally is not necessary; When there is a value, it's never None. --- src/compiler/ast.rs | 4 ++-- src/compiler/iml/imlvalue.rs | 45 ++++++++++++------------------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/compiler/ast.rs b/src/compiler/ast.rs index 70a1d9f..fbf917b 100644 --- a/src/compiler/ast.rs +++ b/src/compiler/ast.rs @@ -333,7 +333,7 @@ fn traverse_node_value(scope: &Scope, node: &Dict, name: Option) -> ImlV let param = &genarg["children"].borrow(); let param = param.object::().unwrap(); - args.push((offset, Some(traverse_node_static(scope, None, param)))); + args.push((offset, traverse_node_static(scope, None, param))); } "genarg_named" => { @@ -358,7 +358,7 @@ fn traverse_node_value(scope: &Scope, node: &Dict, name: Option) -> ImlV nargs.insert( ident.to_string(), - (offset, Some(traverse_node_static(scope, None, param))), + (offset, traverse_node_static(scope, None, param)), ); } diff --git a/src/compiler/iml/imlvalue.rs b/src/compiler/iml/imlvalue.rs index d7ef75a..225b253 100644 --- a/src/compiler/iml/imlvalue.rs +++ b/src/compiler/iml/imlvalue.rs @@ -45,11 +45,11 @@ pub(in crate::compiler) enum ImlValue { }, Instance { // Unresolved parselet instance definition - offset: Option, // Source offset - target: Box, // Instance target - args: Vec<(Option, Option)>, // Sequential generic args - nargs: IndexMap, Option)>, // Named generic args - severity: Option, // optional desired severity + offset: Option, // Source offset + target: Box, // Instance target + args: Vec<(Option, ImlValue)>, // Sequential generic args + nargs: IndexMap, ImlValue)>, // Named generic args + severity: Option, // optional desired severity is_generated: bool, }, } @@ -69,7 +69,7 @@ impl ImlValue { offset: None, name: name.to_string(), }), - args: vec![(offset, Some(self))], + args: vec![(offset, self)], nargs: IndexMap::new(), severity, is_generated: true, @@ -120,19 +120,15 @@ impl ImlValue { // Resolve sequential generic args for arg in args.iter_mut() { - if let Some(arg) = arg.1.as_mut() { - if !arg.resolve(scope) { - is_resolved = false; - } + if !arg.1.resolve(scope) { + is_resolved = false; } } // Resolve named generic args for narg in nargs.values_mut() { - if let Some(narg) = narg.1.as_mut() { - if !narg.resolve(scope) { - is_resolved = false; - } + if !narg.1.resolve(scope) { + is_resolved = false; } } @@ -146,11 +142,12 @@ impl ImlValue { for (name, default) in parselet.generics.iter() { // Take arguments by sequence first let arg = if !args.is_empty() { - args.remove(0) + let arg = args.remove(0); + (arg.0, Some(arg.1)) } // Otherwise, take named arguments by sequence else if let Some(narg) = nargs.shift_remove(name) { - narg + (narg.0, Some(narg.1)) } // Otherwise, use default else { @@ -441,15 +438,7 @@ impl std::fmt::Display for ImlValue { let mut first = true; for arg in args { - write!( - f, - "{}{}", - if !first { ", " } else { "" }, - arg.1 - .as_ref() - .map(|v| v.to_string()) - .unwrap_or("None".to_string()) - )?; + write!(f, "{}{}", if !first { ", " } else { "" }, arg.1)?; first = false; } @@ -459,11 +448,7 @@ impl std::fmt::Display for ImlValue { "{}{}:{}", if !first { ", " } else { "" }, narg, - nargs[narg] - .1 - .as_ref() - .map(|v| v.to_string()) - .unwrap_or("None".to_string()) + nargs[narg].1 )?; first = false; }