slang_frontend/semantic_analysis/
semantic_analyzer.rs

1use crate::semantic_analysis::ErrorCollector;
2use slang_error::CompileResult;
3use slang_ir::ast::Statement;
4use slang_shared::CompilationContext;
5
6use super::analyzer_modules::core::CoreAnalyzer;
7use super::analyzer_modules::native_functions;
8
9/// Performs semantic analysis including type checking on a list of statements.
10/// This is the main entry point for the semantic analysis system.
11///
12/// ### Arguments
13/// * `statements` - The AST statements to analyze
14/// * `context` - The compilation context
15///
16/// ### Returns
17/// * `CompileResult<()>` - Ok if no semantic errors were found, otherwise Err with the list of errors
18pub fn execute(statements: &[Statement], context: &mut CompilationContext) -> CompileResult<()> {
19    let mut analyzer = CoreAnalyzer::new(context);
20    native_functions::register_native_functions(analyzer.context()); // Register native functions using the accessor
21
22    let mut error_collector = ErrorCollector::new();
23
24    for stmt in statements {
25        if let Err(error) = analyzer.analyze_statement(stmt) {
26            error_collector.add_semantic_error(error, analyzer.context());
27        }
28    }
29
30    if error_collector.has_errors() {
31        Err(error_collector.into_errors())
32    } else {
33        Ok(())
34    }
35}
36