Refine optimizer.

This commit is contained in:
Stephen Chung
2020-03-10 11:22:41 +08:00
parent feaad4e0da
commit 2d80ee2f18
2 changed files with 41 additions and 10 deletions

View File

@@ -198,6 +198,21 @@ impl Expr {
| Expr::Or(e, _) => e.position(),
}
}
pub fn is_constant(&self) -> bool {
match self {
Expr::IntegerConstant(_, _)
| Expr::FloatConstant(_, _)
| Expr::Identifier(_, _)
| Expr::CharConstant(_, _)
| Expr::StringConstant(_, _)
| Expr::True(_)
| Expr::False(_)
| Expr::Unit(_) => true,
_ => false,
}
}
}
#[derive(Debug, PartialEq, Clone)]