4 using namespace tanlang;
18 void CompoundStmt::set_child_at(
size_t idx,
ASTBase *node) {
19 TAN_ASSERT(_children.size() > idx);
20 _children[idx] = node;
23 void CompoundStmt::append_child(
ASTBase *node) { _children.push_back(node); }
25 void CompoundStmt::clear_children() { _children.clear(); }
27 size_t CompoundStmt::get_children_size()
const {
return _children.size(); }
45 void Return::set_rhs(
Expr *rhs) { _rhs = rhs; }
47 Expr *Return::get_rhs()
const {
return _rhs; }
57 void Import::set_name(
const str &s) { _name = s; }
59 const str &Import::get_name()
const {
return _name; }
64 TAN_ASSERT(type == ASTNodeType::BREAK || type == ASTNodeType::CONTINUE);
67 Loop *BreakContinue::get_parent_loop()
const {
return _parent_loop; }
69 void BreakContinue::set_parent_loop(
Loop *parent_loop) { _parent_loop = parent_loop; }
93 void If::add_if_then_branch(
Expr *pred,
Stmt *branch) {
95 _predicates.push_back(pred);
96 _branches.push_back(branch);
99 void If::add_else_branch(
Stmt *branch) {
100 _predicates.push_back(
nullptr);
101 _branches.push_back(branch);
105 TAN_ASSERT(i < _predicates.size());
106 return _predicates[i];
109 void If::set_predicate(
size_t i,
Expr *expr) {
110 TAN_ASSERT(i < _predicates.size());
111 _predicates[i] = expr;
114 Stmt *If::get_branch(
size_t i)
const {
115 TAN_ASSERT(i < _branches.size());
119 size_t If::get_num_branches()
const {
return _branches.size(); }
122 vector<ASTBase *> ret = {};
123 std::for_each(_predicates.begin(), _predicates.end(), [&](
Expr *e) { ret.push_back((ASTBase *)e); });
124 std::for_each(_branches.begin(), _branches.end(), [&](
Stmt *e) { ret.push_back((ASTBase *)e); });
132 str PackageDecl::get_name()
const {
return _name; }
134 void PackageDecl::set_name(
const str &name) { _name = name; }
BreakContinue(ASTNodeType type, TokenizedSourceFile *src)
static CompoundStmt * Create(TokenizedSourceFile *src)
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
Represent if-[else] or if-elif-[else] statements.
vector< ASTBase * > get_children() const override
Get a ordered list of child nodes.
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.
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.