gbf_core/decompiler/ast/
assignable.rs#![deny(missing_docs)]
use gbf_macros::AstNodeTransform;
use serde::{Deserialize, Serialize};
use super::{
emit, expr::ExprKind, identifier::IdentifierNode, member_access::MemberAccessNode,
ssa::SsaVersion, visitors::AstVisitor, AstKind, AstVisitable,
};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, AstNodeTransform)]
#[convert_to(ExprKind::Assignable, AstKind::Expression)]
pub enum AssignableKind {
MemberAccess(MemberAccessNode),
Identifier(IdentifierNode),
}
impl AssignableKind {
pub fn set_ssa_version(&mut self, ssa_version: SsaVersion) {
match self {
AssignableKind::MemberAccess(m) => m.ssa_version = Some(ssa_version),
AssignableKind::Identifier(i) => i.ssa_version = Some(ssa_version),
}
}
pub fn id_string(&self) -> String {
match self {
AssignableKind::MemberAccess(m) => emit(m.clone()),
AssignableKind::Identifier(i) => emit(i.clone()),
}
}
pub fn ssa_version(&self) -> Option<SsaVersion> {
match self {
AssignableKind::MemberAccess(m) => m.ssa_version,
AssignableKind::Identifier(i) => i.ssa_version,
}
}
pub fn remove_ssa_version(&mut self) {
match self {
AssignableKind::MemberAccess(m) => m.ssa_version = None,
AssignableKind::Identifier(i) => i.ssa_version = None,
}
}
}
impl AstVisitable for AssignableKind {
fn accept(&self, visitor: &mut dyn AstVisitor) {
visitor.visit_assignable_expr(self);
}
}
impl PartialEq for AssignableKind {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(AssignableKind::MemberAccess(m1), AssignableKind::MemberAccess(m2)) => m1 == m2,
(AssignableKind::Identifier(i1), AssignableKind::Identifier(i2)) => i1 == i2,
_ => false,
}
}
}