ArkScript
A small, fast, functional and scripting language for video games
|
#include <ScopeResolver.hpp>
Public Member Functions | |
ScopeResolver () | |
Create a ScopeResolver. | |
ScopeResolver (const ScopeResolver &)=delete | |
ScopeResolver & | operator= (const ScopeResolver &)=delete |
ScopeResolver (ScopeResolver &&)=default | |
ScopeResolver & | operator= (ScopeResolver &&)=default |
void | createNew () |
Create a new scope. | |
void | removeLastScope () |
Remove the last scope. | |
void | createNewNamespace (const std::string &name, bool with_prefix, bool is_glob, const std::vector< std::string > &symbols) |
Create a new namespace scope. | |
std::string | registerInCurrent (const std::string &name, bool is_mutable) |
Register a Declaration in the current (last) scope. | |
void | saveNamespaceAndRemove () |
Save the last scope as a namespace, by attaching it to the nearest namespace scope. | |
std::optional< bool > | isImmutable (const std::string &name) const |
Checks the scopes in reverse order for 'name' and returns its mutability status. | |
bool | isRegistered (const std::string &name) const |
Checks if any scope has 'name', in reverse order. | |
bool | isInScope (const std::string &name) const |
Checks if 'name' is in the current scope. | |
std::string | getFullyQualifiedNameInNearestScope (const std::string &name) const |
Get a FQN from a variable name in the nearest scope it is declared in. | |
std::pair< bool, std::string > | canFullyQualifyName (const std::string &name) |
Checks if a name can be fully qualified (allows only unprefixed names to be resolved by glob namespaces or inside their own namespace) | |
StaticScope * | currentScope () const |
Return a non-owning raw pointer to the current scope. | |
Private Attributes | |
std::vector< std::unique_ptr< StaticScope > > | m_scopes |
Definition at line 25 of file ScopeResolver.hpp.
Ark::internal::ScopeResolver::ScopeResolver | ( | ) |
Create a ScopeResolver.
Kickstart by create a default global scope
Definition at line 7 of file ScopeResolver.cpp.
References createNewNamespace().
|
delete |
|
default |
|
nodiscard |
Checks if a name can be fully qualified (allows only unprefixed names to be resolved by glob namespaces or inside their own namespace)
name |
Definition at line 78 of file ScopeResolver.cpp.
References getFullyQualifiedNameInNearestScope(), and m_scopes.
Referenced by Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().
void Ark::internal::ScopeResolver::createNew | ( | ) |
Create a new scope.
Definition at line 12 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visitKeyword().
void Ark::internal::ScopeResolver::createNewNamespace | ( | const std::string & | name, |
bool | with_prefix, | ||
bool | is_glob, | ||
const std::vector< std::string > & | symbols ) |
Create a new namespace scope.
name | |
with_prefix | |
is_glob | |
symbols |
Definition at line 22 of file ScopeResolver.cpp.
References m_scopes.
Referenced by ScopeResolver(), and Ark::internal::NameResolutionPass::visit().
|
nodiscard |
Return a non-owning raw pointer to the current scope.
Definition at line 114 of file ScopeResolver.cpp.
References Ark::internal::StaticScope::get(), and m_scopes.
Referenced by Ark::internal::NameResolutionPass::visit().
|
nodiscard |
Get a FQN from a variable name in the nearest scope it is declared in.
name |
Definition at line 68 of file ScopeResolver.cpp.
References m_scopes.
Referenced by canFullyQualifyName(), and Ark::internal::NameResolutionPass::visit().
|
nodiscard |
Checks the scopes in reverse order for 'name' and returns its mutability status.
name |
Definition at line 43 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visit(), and Ark::internal::NameResolutionPass::visitKeyword().
|
nodiscard |
Checks if 'name' is in the current scope.
name |
Definition at line 63 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visitKeyword().
|
nodiscard |
Checks if any scope has 'name', in reverse order.
name |
Definition at line 53 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visitKeyword().
|
delete |
|
default |
std::string Ark::internal::ScopeResolver::registerInCurrent | ( | const std::string & | name, |
bool | is_mutable ) |
Register a Declaration in the current (last) scope.
name | |
is_mutable |
Definition at line 27 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::addDefinedSymbol().
void Ark::internal::ScopeResolver::removeLastScope | ( | ) |
Remove the last scope.
Definition at line 17 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visitKeyword().
void Ark::internal::ScopeResolver::saveNamespaceAndRemove | ( | ) |
Save the last scope as a namespace, by attaching it to the nearest namespace scope.
Also handle removing the scope from the scope pile.
Definition at line 32 of file ScopeResolver.cpp.
References m_scopes.
Referenced by Ark::internal::NameResolutionPass::visit().
|
private |
Definition at line 121 of file ScopeResolver.hpp.
Referenced by canFullyQualifyName(), createNew(), createNewNamespace(), currentScope(), getFullyQualifiedNameInNearestScope(), isImmutable(), isInScope(), isRegistered(), registerInCurrent(), removeLastScope(), and saveNamespaceAndRemove().