tipc
A TIP to LLVM compiler
ASTIfStmt.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ASTExpr.h"
4 #include "ASTStmt.h"
5 
8 class ASTIfStmt : public ASTStmt {
9  std::shared_ptr<ASTExpr> COND;
10  std::shared_ptr<ASTStmt> THEN, ELSE;
11 
12 public:
13  std::vector<std::shared_ptr<ASTNode>> getChildren() override;
14  ASTIfStmt(std::shared_ptr<ASTExpr> COND, std::shared_ptr<ASTStmt> THEN,
15  std::shared_ptr<ASTStmt> ELSE)
16  : COND(COND), THEN(THEN), ELSE(ELSE) {}
17  ASTExpr *getCondition() const { return COND.get(); }
18  ASTStmt *getThen() const { return THEN.get(); }
19 
23  ASTStmt *getElse() const { return ELSE.get(); }
24  void accept(ASTVisitor *visitor) override;
25  llvm::Value *codegen() override;
26 
27 protected:
28  std::ostream &print(std::ostream &out) const override;
29 };
Abstract class for all expression subtypes.
Definition: ASTExpr.h:7
Class for if-then-else.
Definition: ASTIfStmt.h:8
std::vector< std::shared_ptr< ASTNode > > getChildren() override
Return all of the children for the node.
Definition: ASTIfStmt.cpp:24
llvm::Value * codegen() override
Perform code generation and return an LLVM value the code.
Definition: CodeGenFunctions.cpp:931
std::ostream & print(std::ostream &out) const override
Definition: ASTIfStmt.cpp:15
ASTExpr * getCondition() const
Definition: ASTIfStmt.h:17
void accept(ASTVisitor *visitor) override
Visit the children of this node and apply the visitor.
Definition: ASTIfStmt.cpp:4
ASTStmt * getElse() const
Definition: ASTIfStmt.h:23
ASTStmt * getThen() const
Definition: ASTIfStmt.h:18
ASTIfStmt(std::shared_ptr< ASTExpr > COND, std::shared_ptr< ASTStmt > THEN, std::shared_ptr< ASTStmt > ELSE)
Definition: ASTIfStmt.h:14
Base class for all statement nodes.
Definition: ASTStmt.h:7
Base class for AST visitors.
Definition: ASTVisitor.h:23