1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum BinOp {
7 Add,
8 Sub,
9 Mul,
10 Div,
11 Mod,
12 Pow,
13 Lt,
14 Gt,
15 Le,
16 Ge,
17 Eq,
18 Ne,
19 StrictEq,
20 StrictNe,
21 BitAnd,
22 BitOr,
23 BitXor,
24 Shl,
25 Shr,
26 UrShr,
27 In,
28 InstanceOf,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33pub enum UnaOp {
34 Neg, Not, BitNot, TypeOf, Void, Delete, }
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44pub enum LogicalOp {
45 And, Or, Nullish, }
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52pub enum UpdateOp {
53 Increment,
54 Decrement,
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
59pub enum AssignOp {
60 Assign, Add, Sub, Mul, Div, Mod, Shl, Shr, BitAnd, BitOr, BitXor, LogicAnd, LogicOr, Nullish, }
75
76impl AssignOp {
77 pub fn to_zig_str(self) -> &'static str {
79 match self {
80 AssignOp::Assign => "=",
81 AssignOp::Add => "+=",
82 AssignOp::Sub => "-=",
83 AssignOp::Mul => "*=",
84 AssignOp::Div => "/=",
85 AssignOp::Mod => "%=",
86 AssignOp::Shl => "<<=",
87 AssignOp::Shr => ">>=",
88 AssignOp::BitAnd => "&=",
89 AssignOp::BitOr => "|=",
90 AssignOp::BitXor => "^=",
91 AssignOp::LogicAnd => "and=",
92 AssignOp::LogicOr => "or=",
93 AssignOp::Nullish => "orelse=",
94 }
95 }
96
97 pub fn to_bin_op(&self) -> Option<BinOp> {
100 match self {
101 Self::Add => Some(BinOp::Add),
102 Self::Sub => Some(BinOp::Sub),
103 Self::Mul => Some(BinOp::Mul),
104 Self::Div => Some(BinOp::Div),
105 Self::Mod => Some(BinOp::Mod),
106 Self::Shl => Some(BinOp::Shl),
107 Self::Shr => Some(BinOp::Shr),
108 Self::BitAnd => Some(BinOp::BitAnd),
109 Self::BitOr => Some(BinOp::BitOr),
110 Self::BitXor => Some(BinOp::BitXor),
111 _ => None,
112 }
113 }
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[test]
121 fn test_assign_op_zig_str() {
122 assert_eq!(AssignOp::Assign.to_zig_str(), "=");
123 assert_eq!(AssignOp::LogicAnd.to_zig_str(), "and=");
124 assert_eq!(AssignOp::Nullish.to_zig_str(), "orelse=");
125 }
126
127 #[test]
128 fn test_bin_op_coverage() {
129 let ops = [
131 BinOp::Add,
132 BinOp::Sub,
133 BinOp::Mul,
134 BinOp::Div,
135 BinOp::Mod,
136 BinOp::Lt,
137 BinOp::Gt,
138 BinOp::Le,
139 BinOp::Ge,
140 BinOp::Eq,
141 BinOp::Ne,
142 BinOp::StrictEq,
143 BinOp::StrictNe,
144 BinOp::BitAnd,
145 BinOp::BitOr,
146 BinOp::BitXor,
147 BinOp::Shl,
148 BinOp::Shr,
149 BinOp::UrShr,
150 BinOp::In,
151 BinOp::InstanceOf,
152 BinOp::Pow,
153 ];
154 assert_eq!(ops.len(), 22);
155 }
156}