1 #ifndef __TAN_SRC_AST_STMT_H__
2 #define __TAN_SRC_AST_STMT_H__
15 [[nodiscard]] vector<ASTBase *>
get_children()
const override;
17 bool is_stmt()
const override {
return true; }
18 bool is_expr()
const override {
return false; }
31 void set_child_at(
size_t idx,
ASTBase *node);
32 void append_child(
ASTBase *node);
33 void clear_children();
34 [[nodiscard]]
size_t get_children_size()
const;
35 [[nodiscard]] vector<ASTBase *>
get_children()
const override;
44 vector<ASTBase *> _children{};
62 void set_rhs(
Expr *rhs);
63 [[nodiscard]]
Expr *get_rhs()
const;
65 [[nodiscard]] vector<ASTBase *>
get_children()
const override;
78 void set_name(
const str &s);
79 [[nodiscard]]
const str &get_name()
const;
82 vector<FunctionDecl *> _imported_funcs{};
83 vector<TypeDecl *> _imported_types{};
94 [[nodiscard]]
Loop *get_parent_loop()
const;
95 void set_parent_loop(
Loop *parent_loop);
98 Loop *_parent_loop =
nullptr;
117 enum class ASTLoopType { FOR, WHILE };
126 [[nodiscard]] vector<ASTBase *>
get_children()
const override;
131 ASTLoopType _loop_type = ASTLoopType::WHILE;
132 llvm::BasicBlock *_loop_start =
nullptr;
133 llvm::BasicBlock *_loop_end =
nullptr;
135 Expr *_initialization =
nullptr;
136 Expr *_predicate =
nullptr;
137 Stmt *_body =
nullptr;
138 Expr *_iteration =
nullptr;
155 void add_if_then_branch(
Expr *pred,
Stmt *branch);
156 void add_else_branch(
Stmt *branch);
163 void set_predicate(
size_t i,
Expr *expr);
165 [[nodiscard]]
Stmt *get_branch(
size_t i)
const;
166 [[nodiscard]]
size_t get_num_branches()
const;
168 [[nodiscard]] vector<ASTBase *>
get_children()
const override;
172 vector<Expr *> _predicates{};
173 vector<Stmt *> _branches{};
184 str get_name()
const;
185 void set_name(
const str &name);
virtual str to_string(bool include_source_code=false) const
Different from repr, to_string output doesn't include child nodes.
BreakContinue(ASTNodeType type, TokenizedSourceFile *src)
static CompoundStmt * Create(TokenizedSourceFile *src)
str terminal_token() const override
Which terminal token is expected immediately after this node.
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
str to_string(bool=false) const override
Different from repr, to_string output doesn't include child nodes.
Represent if-[else] or if-elif-[else] statements.
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
str terminal_token() const override
Which terminal token is expected immediately after this node.
Expr * get_predicate(size_t i) const
If(TokenizedSourceFile *src)
static Import * Create(TokenizedSourceFile *src)
static Loop * Create(TokenizedSourceFile *src)
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
str terminal_token() const override
Which terminal token is expected immediately after this node.
static Program * Create(TokenizedSourceFile *src)
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
Return(TokenizedSourceFile *src)
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
Stmt(ASTNodeType type, TokenizedSourceFile *src)
Different from SourceFile, TokenizedSourceFile manages the tokenized text of a source file.