use alloc::boxed::Box;
use core::cell::{Cell, RefCell};
use miden_assembly_syntax::{
ast::{self, GlobalItemIndex, Ident, Visibility},
library::ItemInfo,
};
use super::LinkStatus;
#[derive(Debug, Clone)]
pub struct Symbol {
name: Ident,
visibility: Visibility,
status: Cell<LinkStatus>,
item: SymbolItem,
}
#[derive(Debug, Clone)]
pub enum SymbolItem {
Alias {
alias: ast::Alias,
resolved: Cell<Option<GlobalItemIndex>>,
},
Constant(ast::Constant),
Type(ast::TypeDecl),
Procedure(RefCell<Box<ast::Procedure>>),
Compiled(ItemInfo),
}
impl Symbol {
#[inline]
pub fn new(name: Ident, visibility: Visibility, status: LinkStatus, item: SymbolItem) -> Self {
Self {
name,
visibility,
status: Cell::new(status),
item,
}
}
#[inline(always)]
pub fn name(&self) -> &Ident {
&self.name
}
#[inline(always)]
pub fn visibility(&self) -> Visibility {
self.visibility
}
#[inline(always)]
pub fn item(&self) -> &SymbolItem {
&self.item
}
#[inline(always)]
pub fn status(&self) -> LinkStatus {
self.status.get()
}
#[inline]
pub fn set_status(&self, status: LinkStatus) {
self.status.set(status);
}
#[inline]
pub fn is_unlinked(&self) -> bool {
matches!(self.status.get(), LinkStatus::Unlinked)
}
#[inline]
pub fn is_linked(&self) -> bool {
matches!(self.status.get(), LinkStatus::Linked)
}
pub fn is_procedure(&self) -> bool {
matches!(
&self.item,
SymbolItem::Compiled(ItemInfo::Procedure(_)) | SymbolItem::Procedure(_)
)
}
}