/*! @file src/Sema/Analyzer.hpp @brief 语义分析器定义 */ #pragma once #include #include #include #include #include #include namespace Fig { class Analyzer { private: Arena arena; SourceManager &manager; TypeContext typeCtx; Environment env; Diagnostics diag; HashMap globalTypes; HashMap globalSymbols; bool hasInit = false; bool hasMain = false; // 核心递归查找:解决跨越函数边界的捕获问题 Result resolveSymbolInternal(const String &name, const SourceLocation &loc, Scope* startScope); Result resolveTypeExpr(TypeExpr *texpr); Result pass1(Program *prog); Result resolveTypes(Program *prog); Result checkBodies(Program *prog); Result analyzeStmt(Stmt *stmt); Result analyzeExpr(Expr *expr); int addUpvalue(Scope *scope, Symbol *target, bool isLocal); public: Analyzer(SourceManager &m) : manager(m) {} Result Analyze(Program *prog); Diagnostics& GetDiagnostics() { return diag; } TypeContext& GetTypeContext() { return typeCtx; } }; }