gbf_core/decompiler/ast/
phi_array.rs

1#![deny(missing_docs)]
2
3use gbf_macros::AstNodeTransform;
4use serde::{Deserialize, Serialize};
5
6use super::{
7    AstKind, AstVisitable, array_kind::ArrayKind, expr::ExprKind, phi::PhiNode, ptr::P,
8    visitors::AstVisitor,
9};
10
11/// Represents a function call
12#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
13#[convert_to(ArrayKind::PhiArray, ExprKind::Array, AstKind::Expression)]
14pub struct PhiArrayNode {
15    /// The phi node that merges the array.
16    pub phi: P<PhiNode>,
17    /// The elements in the array
18    pub elements: Vec<ExprKind>,
19}
20
21impl PhiArrayNode {
22    /// Creates a new array.
23    ///
24    /// # Arguments
25    /// - `elements`: The elements of the array.
26    pub fn new(phi: P<PhiNode>, elements: Vec<ExprKind>) -> Self {
27        Self { phi, elements }
28    }
29}
30
31impl AstVisitable for P<PhiArrayNode> {
32    fn accept<V: AstVisitor>(&self, visitor: &mut V) -> V::Output {
33        visitor.visit_phi_array(self)
34    }
35}
36
37// == Other implementations for unary operations ==
38impl PartialEq for PhiArrayNode {
39    fn eq(&self, other: &Self) -> bool {
40        self.elements == other.elements && self.phi == other.phi
41    }
42}