gbf_core/decompiler/ast/
vbranch.rs

1#![deny(missing_docs)]
2
3use gbf_macros::AstNodeTransform;
4use serde::{Deserialize, Serialize};
5
6use crate::decompiler::structure_analysis::region::RegionId;
7
8use super::{AstKind, AstVisitable, ptr::P, statement::StatementKind, visitors::AstVisitor};
9
10/// Represents a unary operation node in the AST, such as `-a` or `!b`.
11#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
12#[convert_to(StatementKind::VirtualBranch, AstKind::Statement)]
13pub struct VirtualBranchNode {
14    /// The branch to jump to.
15    pub branch: RegionId,
16}
17
18impl VirtualBranchNode {
19    /// Creates a new `VirtualBranchNode` with the provided branch.
20    pub fn new(branch: RegionId) -> Self {
21        Self { branch }
22    }
23
24    /// Returns the branch to jump to.
25    pub fn branch(&self) -> RegionId {
26        self.branch
27    }
28}
29
30impl AstVisitable for P<VirtualBranchNode> {
31    fn accept<V: AstVisitor>(&self, visitor: &mut V) -> V::Output {
32        visitor.visit_virtual_branch(self)
33    }
34}
35
36// == Other implementations for unary operations ==
37impl PartialEq for VirtualBranchNode {
38    fn eq(&self, other: &Self) -> bool {
39        self.branch == other.branch
40    }
41}