slang_frontend/semantic_analysis/analyzer_modules/
scope_manager.rs

1use super::super::traits::ScopeManager;
2use slang_shared::{CompilationContext, SymbolKind};
3use slang_types::TypeId;
4
5/// Context-based scope manager that implements scope lifecycle operations
6/// using the compilation context's scoping mechanisms.
7///
8/// This implementation provides the standard scope management behavior
9/// by delegating to the compilation context's scope operations.
10pub struct ContextScopeManager<'a> {
11    context: &'a mut CompilationContext,
12}
13
14impl<'a> ContextScopeManager<'a> {
15    /// Create a new context-based scope manager
16    ///
17    /// # Arguments
18    /// * `context` - The compilation context to manage scopes for
19    pub fn new(context: &'a mut CompilationContext) -> Self {
20        Self { context }
21    }
22}
23
24impl ScopeManager for ContextScopeManager<'_> {
25    fn enter_scope(&mut self) {
26        self.context.begin_scope();
27    }
28
29    fn exit_scope(&mut self) {
30        self.context.end_scope();
31    }
32
33    fn define_symbol(
34        &mut self,
35        name: String,
36        kind: SymbolKind,
37        type_id: TypeId,
38        is_mutable: bool,
39    ) -> Result<(), String> {
40        self.context.define_symbol(name, kind, type_id, is_mutable)
41    }
42}