gbf_core/decompiler/ast/
new_array.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 return node in the AST, such as `return 5`.
9#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
10#[convert_to(ExprKind::NewArray, AstKind::Expression)]
11pub struct NewArrayNode {
12    /// The number of elements in the array
13    pub arg: ExprKind,
14}
15
16impl NewArrayNode {
17    /// Creates a new `NewNode` with the provided type and arguments.
18    ///
19    /// # Arguments
20    /// - `arg`: The number of elements in the array
21    ///
22    /// # Returns
23    /// - A `NewNode` instance containing the provided type and arguments.
24    pub fn new(arg: ExprKind) -> Self {
25        Self { arg }
26    }
27}
28
29impl AstVisitable for P<NewArrayNode> {
30    fn accept<V: AstVisitor>(&self, visitor: &mut V) -> V::Output {
31        visitor.visit_new_array(self)
32    }
33}
34
35// == Other implementations for return ==
36impl PartialEq for NewArrayNode {
37    fn eq(&self, other: &Self) -> bool {
38        self.arg == other.arg
39    }
40}