55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use crate::scope::block_scope::BlockScope;
|
|
use crate::scope::class_body_scope::ClassBodyScope;
|
|
use crate::scope::class_scope::ClassScope;
|
|
use crate::scope::function_scope::FunctionScope;
|
|
use crate::scope::module_scope::ModuleScope;
|
|
use std::fmt::{Debug, Formatter};
|
|
|
|
pub mod block_scope;
|
|
pub mod class_body_scope;
|
|
pub mod class_scope;
|
|
pub mod function_scope;
|
|
pub mod module_scope;
|
|
|
|
pub enum Scope {
|
|
Module(ModuleScope),
|
|
Class(ClassScope),
|
|
ClassBody(ClassBodyScope),
|
|
Function(FunctionScope),
|
|
Block(BlockScope),
|
|
}
|
|
|
|
impl Scope {
|
|
pub fn parent_id(&self) -> Option<usize> {
|
|
match self {
|
|
Scope::Module(module_scope) => module_scope.parent_id(),
|
|
Scope::Class(class_scope) => Some(class_scope.parent_id()),
|
|
Scope::ClassBody(class_body_scope) => Some(class_body_scope.parent_id()),
|
|
Scope::Function(function_scope) => Some(function_scope.parent_id()),
|
|
Scope::Block(block_scope) => Some(block_scope.parent_id()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Debug for Scope {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Scope::Module(module_scope) => {
|
|
write!(f, "{:?}", module_scope)
|
|
}
|
|
Scope::Class(class_scope) => {
|
|
write!(f, "{:?}", class_scope)
|
|
}
|
|
Scope::ClassBody(class_body_scope) => {
|
|
write!(f, "{:?}", class_body_scope)
|
|
}
|
|
Scope::Function(function_scope) => {
|
|
write!(f, "{:?}", function_scope)
|
|
}
|
|
Scope::Block(block_scope) => {
|
|
write!(f, "{:?}", block_scope)
|
|
}
|
|
}
|
|
}
|
|
}
|