Create a Type from a Constant.
(constant: &Constant)
| 950 | } |
| 951 | } |
| 952 | |
| 953 | pub fn is_zero(&self) -> bool { |
| 954 | match self { |
| 955 | Constant::I8(i) => *i == 0, |
| 956 | Constant::I16(i) => *i == 0, |
| 957 | Constant::I32(i) => *i == 0, |
| 958 | Constant::I64(i) => *i == 0, |
| 959 | Constant::F32(f) => *f == 0.0, |
| 960 | Constant::F64(f) => *f == 0.0, |
| 961 | Constant::Char(c) => *c == '\0', |
| 962 | Constant::Boolean(b) => !*b, |
| 963 | _ => false, // Null, String, Array, etc. are not zero |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | pub fn is_one(&self) -> bool { |
| 968 | match self { |
| 969 | Constant::I8(i) => *i == 1, |
| 970 | Constant::I16(i) => *i == 1, |
| 971 | Constant::I32(i) => *i == 1, |