重构类型系统并改进诊断功能
- 更新了类型系统,新增了类型并优化了结构。 - 引入了基类型和派生类,用于函数、结构体和接口类型。 - 实现了类型上下文,用于管理内置类型和类型解析。 - 添加了诊断类,用于收集和报告警告和错误。 - 通过改进错误处理增强了虚拟机执行,以应对递归限制问题。 - 实现了反汇编器,将字节码转换为代码,以改善调试和分析。 - 添加了新的抽象语法树节点,用于成员表达式、对象初始化、接口和结构体定义。 - 引入了语义错误测试,包括重定义、未声明的变量和无效的结构字段。
This commit is contained in:
+43
-12
@@ -1,8 +1,6 @@
|
||||
/*!
|
||||
@file src/Ast/TypeExpr.hpp
|
||||
@brief TypeExpr定义
|
||||
@author PuqiAR (im@puqiar.top)
|
||||
@date 2026-02-25
|
||||
@brief 类型表达式 AST 定义:支持泛型与空安全
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -11,26 +9,59 @@
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
|
||||
struct NamedTypeExpr final : public TypeExpr
|
||||
{
|
||||
DynArray<String> path; // {"std", "file"} etc.
|
||||
DynArray<String> path;
|
||||
DynArray<TypeExpr *> arguments;
|
||||
|
||||
NamedTypeExpr()
|
||||
{
|
||||
type = AstType::NamedTypeExpr;
|
||||
}
|
||||
|
||||
NamedTypeExpr(DynArray<String> _path, SourceLocation _location) :
|
||||
path(std::move(_path))
|
||||
NamedTypeExpr(DynArray<String> _p, DynArray<TypeExpr *> _args, SourceLocation _loc) :
|
||||
path(std::move(_p)), arguments(std::move(_args))
|
||||
{
|
||||
type = AstType::NamedTypeExpr;
|
||||
location = std::move(_location);
|
||||
type = AstType::NamedTypeExpr;
|
||||
location = std::move(_loc);
|
||||
}
|
||||
|
||||
virtual String toString() const override
|
||||
{
|
||||
return std::format("<NamedTypeExpr '{}'>", path);
|
||||
String detail = "";
|
||||
for (size_t i = 0; i < path.size(); ++i)
|
||||
{
|
||||
detail += path[i];
|
||||
if (i < path.size() - 1)
|
||||
detail += ".";
|
||||
}
|
||||
if (!arguments.empty())
|
||||
{
|
||||
detail += "<";
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
{
|
||||
detail += arguments[i]->toString();
|
||||
if (i < arguments.size() - 1)
|
||||
detail += ", ";
|
||||
}
|
||||
detail += ">";
|
||||
}
|
||||
return std::format("<NamedTypeExpr '{}'>", detail);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct NullableTypeExpr final : public TypeExpr
|
||||
{
|
||||
TypeExpr *inner;
|
||||
|
||||
NullableTypeExpr(TypeExpr *_inner, SourceLocation _loc) : inner(_inner)
|
||||
{
|
||||
type = AstType::NullableTypeExpr;
|
||||
location = std::move(_loc);
|
||||
}
|
||||
|
||||
virtual String toString() const override
|
||||
{
|
||||
return std::format("<NullableTypeExpr '{}?'>", inner->toString());
|
||||
}
|
||||
};
|
||||
} // namespace Fig
|
||||
|
||||
Reference in New Issue
Block a user