- 增加了对 Lambda 表达式的初步解析支持,包括参数处理和返回类型。Lambda闭包尚未支持。 - 引入了用于对象初始化的新的表达式,支持可选的命名参数。 - 改进了表达式语法错误的错误报告。 - 更新了解析器和分析器以处理新的表达式类型并验证其语义。 - 修改了现有测试以涵盖新功能并确保其正确性。 - 改进了各种解析和语义错误的诊断。
120 lines
2.2 KiB
C++
120 lines
2.2 KiB
C++
/*!
|
|
@file src/Ast/Base.hpp
|
|
@brief AstNode基类定义
|
|
@author PuqiAR (im@puqiar.top)
|
|
@date 2026-03-08
|
|
*/
|
|
|
|
#pragma once
|
|
#include <Core/SourceLocations.hpp>
|
|
#include <Deps/Deps.hpp>
|
|
#include <Sema/Type.hpp>
|
|
#include <cstdint>
|
|
|
|
namespace Fig
|
|
{
|
|
enum class AstType : std::uint8_t
|
|
{
|
|
AstNode,
|
|
Program,
|
|
Expr,
|
|
Stmt,
|
|
BlockStmt,
|
|
|
|
/* Expressions */
|
|
IdentiExpr,
|
|
LiteralExpr,
|
|
PrefixExpr,
|
|
InfixExpr,
|
|
IndexExpr,
|
|
CallExpr,
|
|
MemberExpr, // obj.prop
|
|
NewExpr, // new Point{}
|
|
LambdaExpr,
|
|
|
|
/* Statements */
|
|
ExprStmt,
|
|
VarDecl,
|
|
IfStmt,
|
|
ElseIfStmt,
|
|
WhileStmt,
|
|
FnDefStmt,
|
|
StructDefStmt,
|
|
InterfaceDefStmt,
|
|
ImplStmt, // impl Document for File {}
|
|
ReturnStmt,
|
|
BreakStmt,
|
|
ContinueStmt,
|
|
|
|
/* Type Expressions */
|
|
TypeExpr,
|
|
NamedTypeExpr,
|
|
NullableTypeExpr,
|
|
FnTypeExpr,
|
|
};
|
|
|
|
struct AstNode
|
|
{
|
|
AstType type = AstType::AstNode;
|
|
SourceLocation location;
|
|
|
|
virtual String toString() const = 0;
|
|
virtual ~AstNode() {};
|
|
};
|
|
|
|
struct TypeExpr : public AstNode
|
|
{
|
|
TypeExpr()
|
|
{
|
|
type = AstType::TypeExpr;
|
|
}
|
|
virtual ~TypeExpr() = default;
|
|
};
|
|
|
|
struct Expr : public AstNode
|
|
{
|
|
// 语义分析后填充
|
|
Type resolvedType;
|
|
|
|
Expr()
|
|
{
|
|
type = AstType::Expr;
|
|
}
|
|
};
|
|
|
|
struct Stmt : public AstNode
|
|
{
|
|
bool isPublic = false;
|
|
Stmt()
|
|
{
|
|
type = AstType::Stmt;
|
|
}
|
|
};
|
|
|
|
struct Program final : public AstNode
|
|
{
|
|
DynArray<Stmt *> nodes;
|
|
Program()
|
|
{
|
|
type = AstType::Program;
|
|
}
|
|
virtual String toString() const override
|
|
{
|
|
return "<Program>";
|
|
}
|
|
};
|
|
|
|
struct BlockStmt final : public Stmt
|
|
{
|
|
DynArray<Stmt *> nodes;
|
|
BlockStmt()
|
|
{
|
|
type = AstType::BlockStmt;
|
|
}
|
|
virtual String toString() const override
|
|
{
|
|
return "<BlockStmt>";
|
|
}
|
|
};
|
|
} // namespace Fig
|