forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
900 B
30 lines
900 B
|
|
// AST 节点定义与实现:
|
|
// - 表达式、语句、声明、函数、类型等节点
|
|
// - 支持后续阶段在节点上附加信息(类型、符号绑定、常量值等)
|
|
#include "ast/AstNodes.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace ast {
|
|
|
|
NumberExpr::NumberExpr(int v) : value(v) {}
|
|
|
|
VarExpr::VarExpr(std::string n) : name(std::move(n)) {}
|
|
|
|
BinaryExpr::BinaryExpr(BinaryOp op, std::shared_ptr<Expr> lhs,
|
|
std::shared_ptr<Expr> rhs)
|
|
: op(op), lhs(std::move(lhs)), rhs(std::move(rhs)) {}
|
|
|
|
ReturnStmt::ReturnStmt(std::shared_ptr<Expr> v) : value(std::move(v)) {}
|
|
|
|
VarDecl::VarDecl(std::string n, std::shared_ptr<Expr> i)
|
|
: name(std::move(n)), init(std::move(i)) {}
|
|
|
|
FuncDef::FuncDef(std::string n, std::shared_ptr<Block> b)
|
|
: name(std::move(n)), body(std::move(b)) {}
|
|
|
|
CompUnit::CompUnit(std::shared_ptr<FuncDef> f) : func(std::move(f)) {}
|
|
|
|
} // namespace ast
|