55
66class VarDecl ;
77
8+ class FunctionDecl ;
9+
10+ class Expr ;
11+
812class Stmt : public ASTNode {
913public:
1014 ~Stmt () override = default ;
@@ -19,37 +23,71 @@ class ValueStmt : public Stmt {
1923// 复合语句
2024class CompoundStmt : public Stmt {
2125public:
26+
27+ explicit CompoundStmt (const SharedPtrVector<Stmt> &childStmts);
28+
2229 ~CompoundStmt () override = default ;
30+
31+ SharedPtrVector<Stmt> childStmts;
2332};
2433
25- // 声明语句
34+ // 变量声明语句
2635class VarDeclStmt : public Stmt {
2736public:
2837 ~VarDeclStmt () override = default ;
29- virtual void pushVarDecl (SharedPtr<VarDecl> varDecl);
3038
31- void codegen () override ;
39+ virtual void pushVarDecl ( const SharedPtr<VarDecl> &varDecl) ;
3240
3341private:
3442 SharedPtrVector<VarDecl> childVarDecls;
3543};
3644
45+ // 函数声明语句
46+ class FunctionDeclStmt : public Stmt {
47+ public:
48+ explicit FunctionDeclStmt (const SharedPtr<FunctionDecl> &childFunctionDecl);
49+
50+ ~FunctionDeclStmt () override = default ;
51+
52+ private:
53+ SharedPtr<FunctionDecl> childFunctionDecl;
54+ };
55+
3756// if语句
3857class IfStmt : public Stmt {
3958public:
59+ IfStmt (const SharedPtr<Expr> &condition, const SharedPtr<Stmt> &thenStmt, const SharedPtr<Stmt> &elseStmt);
60+
4061 ~IfStmt () override = default ;
62+
63+ SharedPtr<Expr> condition;
64+ SharedPtr<Stmt> thenBody;
65+ SharedPtr<Stmt> elseBody;
4166};
4267
4368// while语句
4469class WhileStmt : public Stmt {
4570public:
71+ WhileStmt (const SharedPtr<Expr> &condition, const SharedPtr<Stmt> &body);
72+
4673 ~WhileStmt () override = default ;
74+
75+ SharedPtr<Expr> condition;
76+ SharedPtr<Stmt> body;
4777};
4878
4979// for语句
5080class ForStmt : public Stmt {
5181public:
82+ ForStmt (const SharedPtr<VarDeclStmt> &forInitVarDecls, const SharedPtrVector<Expr> &forInitExprList, const SharedPtr<Expr> &forCondition,
83+ const SharedPtrVector<Expr> &forUpdate, const SharedPtr<Stmt> &body);
84+
5285 ~ForStmt () override = default ;
86+ SharedPtr<VarDeclStmt> forInitVarDecls;
87+ SharedPtrVector<Expr> forInitExprList;
88+ SharedPtr<Expr> forCondition;
89+ SharedPtrVector<Expr> forUpdate;
90+ SharedPtr<Stmt> body;
5391};
5492
5593// continue语句
@@ -67,7 +105,10 @@ class BreakStmt : public Stmt {
67105// return语句
68106class ReturnStmt : public Stmt {
69107public:
108+ explicit ReturnStmt (const SharedPtr<Expr> &argument);
109+
70110 ~ReturnStmt () override = default ;
111+ SharedPtr<Expr> argument;
71112};
72113
73114
0 commit comments