slang_frontend/semantic_analysis/analyzer_modules/
symbol_resolver.rs

1use slang_shared::{CompilationContext, Symbol, SymbolKind};
2use super::super::traits::SymbolResolver;
3
4/// Context-based symbol resolver that implements symbol lookup operations
5/// using the compilation context's symbol table.
6/// 
7/// This implementation provides the standard symbol resolution behavior
8/// by delegating to the compilation context's symbol lookup mechanisms.
9pub struct ContextSymbolResolver<'a> {
10    context: &'a CompilationContext,
11}
12
13impl<'a> ContextSymbolResolver<'a> {
14    /// Create a new context-based symbol resolver
15    /// 
16    /// # Arguments
17    /// * `context` - The compilation context containing the symbol table
18    pub fn new(context: &'a CompilationContext) -> Self {
19        Self { context }
20    }
21}
22
23impl<'a> SymbolResolver for ContextSymbolResolver<'a> {
24    fn resolve_variable(&self, name: &str) -> Option<&Symbol> {
25        self.context.lookup_symbol(name)
26            .filter(|symbol| symbol.kind() == SymbolKind::Variable)
27    }
28
29    fn resolve_function(&self, name: &str) -> Option<&Symbol> {
30        self.context.lookup_symbol(name)
31            .filter(|symbol| symbol.kind() == SymbolKind::Function)
32    }
33
34    fn resolve_value(&self, name: &str) -> Option<&Symbol> {
35        self.context.lookup_symbol(name)
36            .filter(|symbol| matches!(symbol.kind(), SymbolKind::Variable | SymbolKind::Function))
37    }
38}