- 更新了类型系统,新增了类型并优化了结构。 - 引入了基类型和派生类,用于函数、结构体和接口类型。 - 实现了类型上下文,用于管理内置类型和类型解析。 - 添加了诊断类,用于收集和报告警告和错误。 - 通过改进错误处理增强了虚拟机执行,以应对递归限制问题。 - 实现了反汇编器,将字节码转换为代码,以改善调试和分析。 - 添加了新的抽象语法树节点,用于成员表达式、对象初始化、接口和结构体定义。 - 引入了语义错误测试,包括重定义、未声明的变量和无效的结构字段。
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
/*!
|
|
@file src/Sema/Analyzer.hpp
|
|
@brief 语义分析器定义
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Ast/Ast.hpp>
|
|
#include <Sema/Type.hpp>
|
|
#include <Sema/Environment.hpp>
|
|
#include <Utils/Arena.hpp>
|
|
#include <Error/Diagnostics.hpp>
|
|
#include <SourceManager/SourceManager.hpp>
|
|
|
|
namespace Fig
|
|
{
|
|
class Analyzer
|
|
{
|
|
private:
|
|
Arena arena;
|
|
SourceManager &manager;
|
|
TypeContext typeCtx;
|
|
Environment env;
|
|
Diagnostics diag;
|
|
|
|
HashMap<String, BaseType*> globalTypes;
|
|
HashMap<String, Symbol*> globalSymbols;
|
|
|
|
bool hasInit = false;
|
|
bool hasMain = false;
|
|
|
|
// 核心递归查找:解决跨越函数边界的捕获问题
|
|
Result<Symbol*, Error> resolveSymbolInternal(const String &name, const SourceLocation &loc, Scope* startScope);
|
|
|
|
Result<Type, Error> resolveTypeExpr(TypeExpr *texpr);
|
|
Result<void, Error> pass1(Program *prog);
|
|
Result<void, Error> resolveTypes(Program *prog);
|
|
Result<void, Error> checkBodies(Program *prog);
|
|
|
|
Result<void, Error> analyzeStmt(Stmt *stmt);
|
|
Result<Type, Error> analyzeExpr(Expr *expr);
|
|
|
|
int addUpvalue(Scope *scope, Symbol *target, bool isLocal);
|
|
|
|
public:
|
|
Analyzer(SourceManager &m) : manager(m) {}
|
|
|
|
Result<void, Error> Analyze(Program *prog);
|
|
|
|
Diagnostics& GetDiagnostics() { return diag; }
|
|
TypeContext& GetTypeContext() { return typeCtx; }
|
|
};
|
|
}
|