Gyoji Compiler
|
Represents variable declarations, labels, and goto inside a lexical scope. More...
#include <function-scope.hpp>
Public Member Functions | |
Scope () | |
Scope (bool _is_loop, size_t _loop_break_blockid, size_t _loop_continue_blockid) | |
~Scope () | |
Move along, nothing to see here. | |
const LocalVariable * | get_variable (std::string name) const |
Represents variable declarations, labels, and goto inside a lexical scope.
This class represents a highly simplified representation of operations inside a lexical scope. The only operations that happen here are sub-scopes, labels, goto statements, and variable declarations. The order of the operations is important because it's important to reason about whether initialization has happened before labels in the context of a 'goto' to a different scope.
In addition, if the scope is a 'loop' (i.e. a while or for loop), this tracks the Block ID of where a 'continue' or 'break' statment should branch to.
Scope::Scope | ( | ) |
This is an anonymous scope that is NOT a loop (i.e. break and continue are not permitted here).
Scope::Scope | ( | bool | _is_loop, |
size_t | _loop_break_blockid, | ||
size_t | _loop_continue_blockid | ||
) |
This is a scope that is associated with some loop like a 'for' or 'while'. The block ID for where to jump to in case of break or continue are provided so that they can be known if they are needed.
Scope::~Scope | ( | ) |
Move along, nothing to see here.
Move along, nothing to see here.
const LocalVariable * Scope::get_variable | ( | std::string | name | ) | const |
If the given variable is defined in this scope, return the type of it. If no such variable is defined, returns nullptr.