Simplify using ..

This commit is contained in:
Stephen Chung
2022-02-08 09:02:15 +08:00
parent 187a20fd8b
commit f8cee0fe4e
54 changed files with 1184 additions and 1190 deletions

View File

@@ -99,7 +99,7 @@ impl Engine {
) {
ast.walk(&mut |path| match path.last().unwrap() {
// Collect all `import` statements with a string constant path
ASTNode::Stmt(Stmt::Import(Expr::StringConstant(s, _), _, _))
ASTNode::Stmt(Stmt::Import(Expr::StringConstant(s, ..), ..))
if !resolver.contains_path(s) && !imports.contains(s.as_str()) =>
{
imports.insert(s.clone().into());

View File

@@ -72,9 +72,9 @@ impl Expression<'_> {
pub fn get_string_value(&self) -> Option<&str> {
match self.0 {
#[cfg(not(feature = "no_module"))]
Expr::Variable(_, _, x) if x.1.is_some() => None,
Expr::Variable(_, _, x) => Some(x.2.as_str()),
Expr::StringConstant(x, _) => Some(x.as_str()),
Expr::Variable(.., _, x) if x.1.is_some() => None,
Expr::Variable(.., _, x) => Some(x.2.as_str()),
Expr::StringConstant(x, ..) => Some(x.as_str()),
_ => None,
}
}
@@ -94,18 +94,18 @@ impl Expression<'_> {
pub fn get_literal_value<T: Variant>(&self) -> Option<T> {
// Coded this way in order to maximally leverage potentials for dead-code removal.
match self.0 {
Expr::IntegerConstant(x, _) => reify!(*x, |x: T| Some(x), || None),
Expr::IntegerConstant(x, ..) => reify!(*x, |x: T| Some(x), || None),
#[cfg(not(feature = "no_float"))]
Expr::FloatConstant(x, _) => reify!(*x, |x: T| Some(x), || None),
Expr::FloatConstant(x, ..) => reify!(*x, |x: T| Some(x), || None),
Expr::CharConstant(x, _) => reify!(*x, |x: T| Some(x), || None),
Expr::StringConstant(x, _) => reify!(x.clone(), |x: T| Some(x), || None),
Expr::Variable(_, _, x) => {
Expr::CharConstant(x, ..) => reify!(*x, |x: T| Some(x), || None),
Expr::StringConstant(x, ..) => reify!(x.clone(), |x: T| Some(x), || None),
Expr::Variable(.., _, x) => {
let x: ImmutableString = x.2.clone().into();
reify!(x, |x: T| Some(x), || None)
}
Expr::BoolConstant(x, _) => reify!(*x, |x: T| Some(x), || None),
Expr::BoolConstant(x, ..) => reify!(*x, |x: T| Some(x), || None),
Expr::Unit(_) => reify!((), |x: T| Some(x), || None),
_ => None,