Gyoji Compiler
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Gyoji::frontend::tree::StatementIfElse Class Reference

This represents an if condition in one of several forms. More...

#include <tree.hpp>

Inheritance diagram for Gyoji::frontend::tree::StatementIfElse:
Inheritance graph
[legend]
Collaboration diagram for Gyoji::frontend::tree::StatementIfElse:
Collaboration graph
[legend]

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 StatementIfElseget_else_if () const
 
const ScopeBody & get_else_scope_body () const
 
- Public Member Functions inherited from Gyoji::frontend::ast::SyntaxNode
 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 SyntaxNodeget_syntax_node () const
 
const Gyoji::context::SourceReferenceget_source_ref () const
 

Detailed Description

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();
}
...

Constructor & Destructor Documentation

◆ StatementIfElse() [1/3]

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() [2/3]

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() [3/3]

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::~StatementIfElse ( )

Destructor, nothing special.

Member Function Documentation

◆ get_else_if()

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.

◆ get_else_scope_body()

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'.

◆ get_expression()

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.

◆ get_if_scope_body()

const ScopeBody & StatementIfElse::get_if_scope_body ( ) const

This represents the scope body to execute when the expression evaluates to true.


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