diff options
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 5dbf9b221..8fb6b6408 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -394,3 +394,42 @@ impl<'a> EnumVariant<'a> { | |||
394 | StructFlavor::from_node(self) | 394 | StructFlavor::from_node(self) |
395 | } | 395 | } |
396 | } | 396 | } |
397 | |||
398 | impl<'a> PointerType<'a> { | ||
399 | pub fn is_mut(&self) -> bool { | ||
400 | self.syntax().children().any(|n| n.kind() == MUT_KW) | ||
401 | } | ||
402 | } | ||
403 | |||
404 | impl<'a> ReferenceType<'a> { | ||
405 | pub fn is_mut(&self) -> bool { | ||
406 | self.syntax().children().any(|n| n.kind() == MUT_KW) | ||
407 | } | ||
408 | } | ||
409 | |||
410 | impl<'a> RefExpr<'a> { | ||
411 | pub fn is_mut(&self) -> bool { | ||
412 | self.syntax().children().any(|n| n.kind() == MUT_KW) | ||
413 | } | ||
414 | } | ||
415 | |||
416 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
417 | pub enum PrefixOp { | ||
418 | /// The `*` operator for dereferencing | ||
419 | Deref, | ||
420 | /// The `!` operator for logical inversion | ||
421 | Not, | ||
422 | /// The `-` operator for negation | ||
423 | Neg, | ||
424 | } | ||
425 | |||
426 | impl<'a> PrefixExpr<'a> { | ||
427 | pub fn op(&self) -> Option<PrefixOp> { | ||
428 | match self.syntax().first_child()?.kind() { | ||
429 | STAR => Some(PrefixOp::Deref), | ||
430 | EXCL => Some(PrefixOp::Not), | ||
431 | MINUS => Some(PrefixOp::Neg), | ||
432 | _ => None, | ||
433 | } | ||
434 | } | ||
435 | } | ||