Gyoji Compiler
|
This represents an if condition in one of several forms. More...
#include <tree.hpp>
Public Member Functions | |
StatementIfElse (Gyoji::owned< Terminal > _if_token, Gyoji::owned< Terminal > _paren_l_token, Gyoji::owned< Expression > _expression, Gyoji::owned< Terminal > _paren_r_token, Gyoji::owned< ScopeBody > _if_scope_body) | |
StatementIfElse (Gyoji::owned< Terminal > _if_token, Gyoji::owned< Terminal > _paren_l_token, Gyoji::owned< Expression > _expression, Gyoji::owned< Terminal > _paren_r_token, Gyoji::owned< ScopeBody > _if_scope_body, Gyoji::owned< Terminal > _else_token, Gyoji::owned< ScopeBody > _else_scope_body) | |
StatementIfElse (Gyoji::owned< Terminal > _if_token, Gyoji::owned< Terminal > _paren_l_token, Gyoji::owned< Expression > _expression, Gyoji::owned< Terminal > _paren_r_token, Gyoji::owned< ScopeBody > _if_scope_body, Gyoji::owned< Terminal > _else_token, Gyoji::owned< StatementIfElse > _statement_if_else) | |
~StatementIfElse () | |
const Expression & | get_expression () const |
const ScopeBody & | get_if_scope_body () const |
const StatementIfElse & | get_else_if () const |
const ScopeBody & | get_else_scope_body () const |
![]() | |
SyntaxNode (Gyoji::context::TokenID _type, specific_type_t _data, const Gyoji::context::SourceReference &_source_ref) | |
const std::vector< std::reference_wrapper< const SyntaxNode > > & | get_children () const |
const Gyoji::context::TokenID & | get_type () const |
template<class T > | |
bool | has_data () const |
template<class T > | |
const T & | get_data () const |
const SyntaxNode & | get_syntax_node () const |
const Gyoji::context::SourceReference & | get_source_ref () const |
This represents an if condition in one of several forms.
The if/else construct in Gyoji comes in several forms. It is designed slightly differently than the C equivalent in order to ensure that it does not have the "dangling else" ambiguity. The curly-braces are mandatory as a part of eliminating that ambiguity. The only excption to this case is the 'else if' construct which does NOT require curly braces after the 'else' and allows very familiar semantics.
The following are examples of the various forms that the if construct may take.
If without else:
... if (foo) { bar(); } ...
If with else. Note that in this case, the curly braces '{' are mandatory for both the if and else blocks.
... if (foo) { bar(); } else { baz(); } ...
If/else if/else if chain. Note that ONLY in this case, we are allowed to skip the curly brace between the 'else' and the next 'if', allowing the semantics to be unambiguious.
... if (foo) { bar(); } else if (q) { baz(); } else { end(); } ...
StatementIfElse::StatementIfElse | ( | Gyoji::owned< Terminal > | _if_token, |
Gyoji::owned< Terminal > | _paren_l_token, | ||
Gyoji::owned< Expression > | _expression, | ||
Gyoji::owned< Terminal > | _paren_r_token, | ||
Gyoji::owned< ScopeBody > | _if_scope_body | ||
) |
Constructs an 'if' statement with a single block for when the condition is true.
StatementIfElse::StatementIfElse | ( | Gyoji::owned< Terminal > | _if_token, |
Gyoji::owned< Terminal > | _paren_l_token, | ||
Gyoji::owned< Expression > | _expression, | ||
Gyoji::owned< Terminal > | _paren_r_token, | ||
Gyoji::owned< ScopeBody > | _if_scope_body, | ||
Gyoji::owned< Terminal > | _else_token, | ||
Gyoji::owned< ScopeBody > | _else_scope_body | ||
) |
Constructs an if/else block where one block represents the expression true and the other block represents the code for the expression false.
StatementIfElse::StatementIfElse | ( | Gyoji::owned< Terminal > | _if_token, |
Gyoji::owned< Terminal > | _paren_l_token, | ||
Gyoji::owned< Expression > | _expression, | ||
Gyoji::owned< Terminal > | _paren_r_token, | ||
Gyoji::owned< ScopeBody > | _if_scope_body, | ||
Gyoji::owned< Terminal > | _else_token, | ||
Gyoji::owned< StatementIfElse > | _statement_if_else | ||
) |
Constructs an if/elseif chain where each 'else if' can be modelled as the next element of a chain of conditions.
StatementIfElse::~StatementIfElse | ( | ) |
Destructor, nothing special.
const StatementIfElse & StatementIfElse::get_else_if | ( | ) | const |
If ths statement is an 'else if' block, this represents the 'next' if block to execute in the chain, so another condition and another set of blocks can be specified.
const ScopeBody & StatementIfElse::get_else_scope_body | ( | ) | const |
In an 'else' block, this represents the scope body to execute when the expression evaluates to 'false'.
const Expression & StatementIfElse::get_expression | ( | ) | const |
This is the expression that is evaluated when the if statement is reached. It must have the type of 'boolean' and governs what happens during execution.
const ScopeBody & StatementIfElse::get_if_scope_body | ( | ) | const |
This represents the scope body to execute when the expression evaluates to true.