![]() |
Gorgon Game Engine
|
A new scope is created automatically when a new input source or a function like construct is created. More...
Public Member Functions | |
Scope (InputProvider &provider, const std::string &name, bool terminal=false) | |
Constructor requires an input provider and a name to define this input source. More... | |
Scope (Scope &parent, const std::string &name, bool terminal=false) | |
This constructor allows a scope without an input provider. More... | |
std::string | GetName () const |
Returns the name of this scope. More... | |
Scope & | GetParent () const |
long | GetPhysicalLine (unsigned long line) |
Current physical line. More... | |
Variable * | GetVariable (const std::string &name) |
bool | HasInstance () const |
bool | HasParent () const |
std::shared_ptr< ScopeInstance > | Instantiate () |
std::shared_ptr< ScopeInstance > | Instantiate (ScopeInstance ¤t) |
bool | IsInteractive () const |
Returns if this scope is interactive (i.e. code is entered by user) More... | |
bool | IsTerminal () const |
Returns if this scope is terminal scope. More... | |
ScopeInstance & | LastInstance () const |
const Instruction * | ReadInstruction (unsigned long line) |
Reads the instruction in the given line. More... | |
unsigned | ReadyInstructionCount () const |
Current number of instructions that are prepared. More... | |
void | SaveInstruction (Instruction inst, long pline) |
Saves an instruction to the scope. More... | |
void | SaveInstructions (const std::vector< Instruction > &insts) |
Saves a list of instructions to this scope. More... | |
void | SetName (const std::string &name) |
In rare cases where scope name cannot be determined at the construction, this function can be used to set its name. More... | |
void | SetVariable (const std::string &name, const Data &data) |
void | Unload () |
Unloads an input source by erasing all current data. More... | |
bool | UnsetVariable (const std::string &name) |
A new scope is created automatically when a new input source or a function like construct is created.
Scopes can be linked to each other. There are two methods to supply codes to a scope: from an InputProvider and directly registering instructions to it.
Scope | ( | InputProvider & | provider, |
const std::string & | name, | ||
bool | terminal = false |
||
) |
Constructor requires an input provider and a name to define this input source.
References Gorgon::Utils::ASSERT_FALSE(), InputProvider::GetDialect(), InputProvider::Intermediate, and InputProvider::Programming.
This constructor allows a scope without an input provider.
This allows function like constructs to have their own scopes with designated source code supplied from external sources
std::string GetName | ( | ) | const |
Returns the name of this scope.
Scope& GetParent | ( | ) | const |
long GetPhysicalLine | ( | unsigned long | line | ) |
Current physical line.
References Scope::ReadInstruction().
Variable* GetVariable | ( | const std::string & | name | ) |
bool HasInstance | ( | ) | const |
bool HasParent | ( | ) | const |
std::shared_ptr< ScopeInstance > Instantiate | ( | ) |
References Scope::ScopeInstance.
std::shared_ptr< ScopeInstance > Instantiate | ( | ScopeInstance & | current | ) |
References Scope::Instantiate().
bool IsInteractive | ( | ) | const |
Returns if this scope is interactive (i.e. code is entered by user)
References InputProvider::IsInteractive().
bool IsTerminal | ( | ) | const |
Returns if this scope is terminal scope.
If a scope is terminal, variable lookup to the parent scopes terminates at this scope
ScopeInstance& LastInstance | ( | ) | const |
References ASSERT.
const Instruction * ReadInstruction | ( | unsigned long | line | ) |
Reads the instruction in the given line.
References Gorgon::Utils::ASSERT_FALSE(), Base::Compile(), InputProvider::Console, Base::Finalize(), InputProvider::GetDialect(), Scope::GetName(), InputProvider::Intermediate, Base::List, InputProvider::Programming, InputProvider::ReadLine(), and InputProvider::SetDialect().
unsigned ReadyInstructionCount | ( | ) | const |
Current number of instructions that are prepared.
void SaveInstruction | ( | Instruction | inst, |
long | pline | ||
) |
Saves an instruction to the scope.
void SaveInstructions | ( | const std::vector< Instruction > & | insts | ) |
Saves a list of instructions to this scope.
void SetName | ( | const std::string & | name | ) |
In rare cases where scope name cannot be determined at the construction, this function can be used to set its name.
void SetVariable | ( | const std::string & | name, |
const Data & | data | ||
) |
void Unload | ( | ) |
Unloads an input source by erasing all current data.
Unload should only be called when no more callbacks can be performed and no more lines are left.
References InputProvider::Reset(), and Gorgon::swap().
bool UnsetVariable | ( | const std::string & | name | ) |