gbf_core/decompiler/ast/
range.rs

1#![deny(missing_docs)]
2
3use gbf_macros::AstNodeTransform;
4use serde::{Deserialize, Serialize};
5
6use super::{AstKind, AstVisitable, expr::ExprKind, ptr::P, visitors::AstVisitor};
7
8/// Represents a range node in the AST, such as <1, 5>.
9#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
10#[convert_to(ExprKind::Range, AstKind::Expression)]
11pub struct RangeNode {
12    /// The start of the range
13    pub start: ExprKind,
14    /// The end of the range
15    pub end: ExprKind,
16}
17
18impl RangeNode {
19    /// Creates a new `RangeNode` with the provided start and end expressions.
20    ///
21    /// # Arguments
22    /// - `start`: The start of the range
23    /// - `end`: The end of the range
24    ///
25    /// # Returns
26    /// - A `RangeNode` instance containing the provided start and end expressions.
27    pub fn new(start: ExprKind, end: ExprKind) -> Self {
28        Self { start, end }
29    }
30}
31
32impl AstVisitable for P<RangeNode> {
33    fn accept<V: AstVisitor>(&self, visitor: &mut V) -> V::Output {
34        visitor.visit_range(self)
35    }
36}
37
38// == Other implementations for range operations ==
39impl PartialEq for RangeNode {
40    fn eq(&self, other: &Self) -> bool {
41        self.start == other.start && self.end == other.end
42    }
43}