/*! @file src/Ast/Stmt/FnDefStmt.hpp @brief 函数定义 AST 节点 */ #pragma once #include #include #include namespace Fig { struct Param : public AstNode { String name; Expr *typeSpecifier; Expr *defaultValue; Type resolvedType; Param() { type = AstType::AstNode; } virtual ~Param() = default; }; struct PosParam final : public Param { PosParam(String _n, Expr *_ts, Expr *_dv, SourceLocation _loc) { name = std::move(_n); typeSpecifier = _ts; defaultValue = _dv; location = std::move(_loc); } virtual String toString() const override { return name; } }; struct FnDefStmt final : public Stmt { String name; DynArray params; Expr *returnTypeSpecifier; BlockStmt *body; Type resolvedReturnType; Symbol *resolvedSymbol = nullptr; // 连接物理符号 int protoIndex = -1; // 在CompiledModule扁平化protos的下标 DynArray upvalues; FnDefStmt() { type = AstType::FnDefStmt; } FnDefStmt(bool _p, String _n, DynArray _pa, Expr *_rt, BlockStmt *_b, SourceLocation _loc) : name(std::move(_n)), params(std::move(_pa)), returnTypeSpecifier(_rt), body(_b) { type = AstType::FnDefStmt; isPublic = _p; location = std::move(_loc); } virtual String toString() const override { return std::format("", name); } }; }