GSC Interpreter
A Turing-complete interpreter developed for a compiler course
Loading...
Searching...
No Matches
If Class Reference

Represents an if statement. More...

#include <stmt.hpp>

Inheritance diagram for If:
Collaboration diagram for If:

Public Member Functions

 If (const std::shared_ptr< Expr > &condition, const std::shared_ptr< Stmt > &thenBranch, const std::shared_ptr< Stmt > &elseBranch)
 
std::any accept (StmtVisitor &visitor) override
 
std::shared_ptr< ExprgetCondition () const
 
std::shared_ptr< StmtgetThenBranch () const
 
std::shared_ptr< StmtgetElseBranch () const
 

Private Attributes

const std::shared_ptr< Exprcondition
 
const std::shared_ptr< StmtthenBranch
 
const std::shared_ptr< StmtelseBranch
 

Detailed Description

Represents an if statement.

Note
This class holds the condition expression, the then branch, and the else branch, allowing visiting it.

Definition at line 136 of file stmt.hpp.

Constructor & Destructor Documentation

◆ If()

If::If ( const std::shared_ptr< Expr > &  condition,
const std::shared_ptr< Stmt > &  thenBranch,
const std::shared_ptr< Stmt > &  elseBranch 
)
inline

Definition at line 143 of file stmt.hpp.

146 : condition(std::move(condition)), thenBranch(std::move(thenBranch)),
147 elseBranch(std::move(elseBranch)) {}
const std::shared_ptr< Stmt > thenBranch
Definition stmt.hpp:139
const std::shared_ptr< Stmt > elseBranch
Definition stmt.hpp:140
const std::shared_ptr< Expr > condition
Definition stmt.hpp:138

Member Function Documentation

◆ accept()

std::any If::accept ( StmtVisitor visitor)
inlineoverridevirtual

Implements Stmt.

Definition at line 149 of file stmt.hpp.

149 {
150 return visitor.visitIfStmt(shared_from_this());
151 }
virtual std::any visitIfStmt(std::shared_ptr< If > stmt)=0

◆ getCondition()

std::shared_ptr< Expr > If::getCondition ( ) const
inline

Definition at line 153 of file stmt.hpp.

153{ return condition; }

◆ getElseBranch()

std::shared_ptr< Stmt > If::getElseBranch ( ) const
inline

Definition at line 157 of file stmt.hpp.

157{ return elseBranch; }

◆ getThenBranch()

std::shared_ptr< Stmt > If::getThenBranch ( ) const
inline

Definition at line 155 of file stmt.hpp.

155{ return thenBranch; }

Member Data Documentation

◆ condition

const std::shared_ptr<Expr> If::condition
private

Definition at line 138 of file stmt.hpp.

◆ elseBranch

const std::shared_ptr<Stmt> If::elseBranch
private

Definition at line 140 of file stmt.hpp.

◆ thenBranch

const std::shared_ptr<Stmt> If::thenBranch
private

Definition at line 139 of file stmt.hpp.


The documentation for this class was generated from the following file: