1use std::fmt;
10
11#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
12pub enum NodeKind {
13 Block,
16 Empty,
18 Yield,
20 ExprStmt,
22 VarDecl,
25 Assign,
27 If,
29 While,
31 DoWhile,
33 For,
35 ForEach,
37 Return,
39 Break,
41 Continue,
42 Throw,
44 Try,
46 Catch,
48 Synchronized,
50 Switch,
52 Case,
54 Label,
56 Assert,
58
59 Binary,
62 Unary,
64 Call,
66 Literal,
68 VarRef,
70 Ternary,
72 Cast,
74 Paren,
76 Member,
78 Index,
80 New,
82 NewArray,
84 ArrayLit,
86 This,
88 InstanceOf,
90 Lambda,
92 MethodRef,
94 Raw,
96 Custom(u16),
98}
99
100impl NodeKind {
101 #[inline]
104 pub fn slot(self) -> usize {
105 match self {
106 NodeKind::Block => 0,
107 NodeKind::Empty => 1,
108 NodeKind::Yield => 2,
109 NodeKind::ExprStmt => 2,
110 NodeKind::VarDecl => 3,
111 NodeKind::Assign => 4,
112 NodeKind::If => 5,
113 NodeKind::While => 6,
114 NodeKind::DoWhile => 7,
115 NodeKind::For => 8,
116 NodeKind::ForEach => 9,
117 NodeKind::Return => 10,
118 NodeKind::Break => 11,
119 NodeKind::Continue => 12,
120 NodeKind::Throw => 13,
121 NodeKind::Try => 14,
122 NodeKind::Catch => 15,
123 NodeKind::Synchronized => 16,
124 NodeKind::Switch => 17,
125 NodeKind::Case => 18,
126 NodeKind::Label => 19,
127 NodeKind::Assert => 20,
128 NodeKind::Binary => 21,
129 NodeKind::Unary => 22,
130 NodeKind::Call => 23,
131 NodeKind::Literal => 24,
132 NodeKind::VarRef => 25,
133 NodeKind::Ternary => 26,
134 NodeKind::Cast => 27,
135 NodeKind::Paren => 28,
136 NodeKind::Member => 29,
137 NodeKind::Index => 30,
138 NodeKind::New => 31,
139 NodeKind::NewArray => 32,
140 NodeKind::ArrayLit => 33,
141 NodeKind::This => 34,
142 NodeKind::InstanceOf => 35,
143 NodeKind::Lambda => 36,
144 NodeKind::MethodRef => 37,
145 NodeKind::Raw => 38,
146 NodeKind::Custom(_) => 39,
147 }
148 }
149
150 pub const SLOT_COUNT: usize = 42;
152}
153
154impl NodeKind {
155 pub fn is_stmt(self) -> bool {
156 use NodeKind::*;
157 matches!(
158 self,
159 Block | Empty | ExprStmt | VarDecl | Assign | If | While | DoWhile | For | ForEach
160 | Return | Break | Continue | Throw | Switch | Case | Try | Catch
161 | Synchronized | Label | Assert | Raw
162 )
163 }
164}
165
166impl fmt::Display for NodeKind {
167 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168 write!(f, "{:?}", self)
169 }
170}
171
172#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
174pub enum BinOp {
175 Add,
176 Sub,
177 Mul,
178 Div,
179 Rem,
180 Shl,
181 Shr,
182 UShr,
183 Lt,
184 Le,
185 Gt,
186 Ge,
187 Eq,
188 Ne,
189 BitAnd,
190 BitXor,
191 BitOr,
192 And,
193 Or,
194}
195
196impl BinOp {
197 pub fn is_comparison(self) -> bool {
198 matches!(self, BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge | BinOp::Eq | BinOp::Ne)
199 }
200 pub fn is_short_circuit(self) -> bool {
201 matches!(self, BinOp::And | BinOp::Or)
202 }
203 pub fn may_div_zero(self) -> bool {
205 matches!(self, BinOp::Div | BinOp::Rem)
206 }
207 pub fn is_arith(self) -> bool {
209 matches!(
210 self,
211 BinOp::Add
212 | BinOp::Sub
213 | BinOp::Mul
214 | BinOp::Div
215 | BinOp::Rem
216 | BinOp::Shl
217 | BinOp::Shr
218 | BinOp::UShr
219 | BinOp::BitAnd
220 | BinOp::BitXor
221 | BinOp::BitOr
222 )
223 }
224}
225
226#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
228pub enum UnOp {
229 Not,
230 Neg,
231 BitNot,
232 Plus,
236 PreInc,
238 PreDec,
239 PostInc,
241 PostDec,
242}
243
244impl UnOp {
245 pub fn is_incdec(self) -> bool {
246 matches!(
247 self,
248 UnOp::PreInc | UnOp::PreDec | UnOp::PostInc | UnOp::PostDec
249 )
250 }
251}
252
253#[derive(Clone, Copy, PartialEq, Debug)]
255pub enum LitRef<'a> {
256 Bool(bool),
257 Int(i64),
258 Long(i64),
259 Float(f64),
260 Double(f64),
261 Char(char),
262 Str(&'a str),
263 Null,
264}
265
266impl<'a> LitRef<'a> {
267 pub fn is_bool(self) -> bool {
268 matches!(self, LitRef::Bool(_))
269 }
270 pub fn as_int(self) -> Option<i64> {
272 match self {
273 LitRef::Int(v) | LitRef::Long(v) => Some(v),
274 _ => None,
275 }
276 }
277}
278
279#[derive(Clone, Copy, Debug)]
284pub struct RegionEvent<Id, Key> {
285 pub kind: EventKind,
286 pub node: Id,
287 pub key: Key,
290}
291
292#[derive(Clone, Copy, PartialEq, Eq, Debug)]
293pub enum EventKind {
294 Use,
296 Write,
298 Shadow,
300 Opaque,
304}