#![allow(non_upper_case_globals)]
mod builder;
mod id;
mod mangler;
mod reference;
mod table;
use bitflags::bitflags;
use oxc_ast::{Atom, Span};
use self::reference::ResolvedReferenceId;
pub use self::{
builder::SymbolTableBuilder,
id::SymbolId,
mangler::{Mangler, Slot},
reference::{Reference, ReferenceFlag, ResolvedReference},
table::SymbolTable,
};
use crate::node::AstNodeId;
#[derive(Debug)]
pub struct Symbol {
id: SymbolId,
declaration: AstNodeId,
name: Atom,
span: Span,
flags: SymbolFlags,
slot: Slot,
references: Vec<ResolvedReferenceId>,
}
#[cfg(target_pointer_width = "64")]
#[test]
fn symbol_size() {
use std::mem::size_of;
assert_eq!(size_of::<Symbol>(), 96);
}
bitflags! {
pub struct SymbolFlags: u16 {
const None = 0;
const FunctionScopedVariable = 1 << 0;
const BlockScopedVariable = 1 << 1;
const ConstVariable = 1 << 2;
const Import = 1 << 3;
const Export = 1 << 4;
const Class = 1 << 5;
const CatchVariable = 1 << 6; const Variable = Self::FunctionScopedVariable.bits | Self::BlockScopedVariable.bits;
const Value = Self::Variable.bits | Self::Class.bits;
const FunctionScopedVariableExcludes = Self::Value.bits - Self::FunctionScopedVariable.bits;
const BlockScopedVariableExcludes = Self::Value.bits;
const ClassExcludes = Self::Value.bits;
}
}
impl SymbolFlags {
#[must_use]
pub fn is_variable(&self) -> bool {
self.intersects(Self::Variable)
}
}
impl Symbol {
#[must_use]
pub fn new(
id: SymbolId,
declaration: AstNodeId,
name: Atom,
span: Span,
flags: SymbolFlags,
) -> Self {
Self { id, declaration, name, span, flags, slot: Slot::default(), references: vec![] }
}
#[must_use]
pub fn id(&self) -> SymbolId {
self.id
}
#[must_use]
pub fn name(&self) -> &Atom {
&self.name
}
#[must_use]
pub fn span(&self) -> Span {
self.span
}
#[must_use]
pub fn flags(&self) -> SymbolFlags {
self.flags
}
#[must_use]
pub fn slot(&self) -> Slot {
self.slot
}
#[must_use]
pub fn is_const(&self) -> bool {
self.flags.contains(SymbolFlags::ConstVariable)
}
#[must_use]
pub fn is_class(&self) -> bool {
self.flags.contains(SymbolFlags::Class)
}
#[must_use]
pub fn is_export(&self) -> bool {
self.flags.contains(SymbolFlags::Export)
}
#[must_use]
pub fn references(&self) -> &[ResolvedReferenceId] {
&self.references
}
#[must_use]
pub fn declaration(&self) -> AstNodeId {
self.declaration
}
}