gbf_core/decompiler/ast/
function.rs#![deny(missing_docs)]
use gbf_macros::AstNodeTransform;
use serde::{Deserialize, Serialize};
use super::{ast_vec::AstVec, expr::ExprKind, AstKind, AstVisitable};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
#[convert_to(AstKind::Function)]
pub struct FunctionNode {
name: Option<String>,
params: AstVec<ExprKind>,
body: AstVec<AstKind>,
}
impl FunctionNode {
pub fn new<N>(name: N, params: AstVec<ExprKind>, body: AstVec<AstKind>) -> Self
where
N: Into<Option<String>>,
{
Self {
name: name.into(),
params,
body,
}
}
pub fn params(&self) -> &Vec<ExprKind> {
&self.params
}
pub fn body(&self) -> &Vec<AstKind> {
&self.body
}
pub fn name(&self) -> &Option<String> {
&self.name
}
}
impl AstVisitable for FunctionNode {
fn accept(&self, visitor: &mut dyn super::visitors::AstVisitor) {
visitor.visit_function(self);
}
}
impl PartialEq for FunctionNode {
fn eq(&self, other: &Self) -> bool {
self.params == other.params && self.body == other.body
}
}