ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::ScopeResolver Class Reference

#include <ScopeResolver.hpp>

Collaboration diagram for Ark::internal::ScopeResolver:
[legend]

Public Member Functions

 ScopeResolver ()
 Create a ScopeResolver.
 
 ScopeResolver (const ScopeResolver &)=delete
 
ScopeResolveroperator= (const ScopeResolver &)=delete
 
 ScopeResolver (ScopeResolver &&)=default
 
ScopeResolveroperator= (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)
 
StaticScopecurrentScope () const
 Return a non-owning raw pointer to the current scope.
 

Private Attributes

std::vector< std::unique_ptr< StaticScope > > m_scopes
 

Detailed Description

Definition at line 25 of file ScopeResolver.hpp.

Constructor & Destructor Documentation

◆ ScopeResolver() [1/3]

Ark::internal::ScopeResolver::ScopeResolver ( )

Create a ScopeResolver.

Kickstart by create a default global scope

Definition at line 7 of file ScopeResolver.cpp.

References createNewNamespace().

◆ ScopeResolver() [2/3]

Ark::internal::ScopeResolver::ScopeResolver ( const ScopeResolver & )
delete

◆ ScopeResolver() [3/3]

Ark::internal::ScopeResolver::ScopeResolver ( ScopeResolver && )
default

Member Function Documentation

◆ canFullyQualifyName()

std::pair< bool, std::string > Ark::internal::ScopeResolver::canFullyQualifyName ( const std::string & name)
nodiscard

Checks if a name can be fully qualified (allows only unprefixed names to be resolved by glob namespaces or inside their own namespace)

Parameters
name
Returns
std::pair<bool, std::string> if the name can be fully qualified, first element is true ; second element is the FQN

Definition at line 78 of file ScopeResolver.cpp.

References getFullyQualifiedNameInNearestScope(), and m_scopes.

Referenced by Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().

◆ createNew()

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

◆ createNewNamespace()

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.

Parameters
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().

◆ currentScope()

StaticScope * Ark::internal::ScopeResolver::currentScope ( ) const
nodiscard

Return a non-owning raw pointer to the current scope.

Returns
StaticScope* non-owning pointer to the current scope
nullptr if there are no scope

Definition at line 114 of file ScopeResolver.cpp.

References Ark::internal::StaticScope::get(), and m_scopes.

Referenced by Ark::internal::NameResolutionPass::visit().

◆ getFullyQualifiedNameInNearestScope()

std::string Ark::internal::ScopeResolver::getFullyQualifiedNameInNearestScope ( const std::string & name) const
nodiscard

Get a FQN from a variable name in the nearest scope it is declared in.

Parameters
name
Returns
std::string

Definition at line 68 of file ScopeResolver.cpp.

References m_scopes.

Referenced by canFullyQualifyName(), and Ark::internal::NameResolutionPass::visit().

◆ isImmutable()

std::optional< bool > Ark::internal::ScopeResolver::isImmutable ( const std::string & name) const
nodiscard

Checks the scopes in reverse order for 'name' and returns its mutability status.

Parameters
name
Returns
std::nullopt if the Declaration could not be found
true if immutable
false if mutable

Definition at line 43 of file ScopeResolver.cpp.

References m_scopes.

Referenced by Ark::internal::NameResolutionPass::visit(), and Ark::internal::NameResolutionPass::visitKeyword().

◆ isInScope()

bool Ark::internal::ScopeResolver::isInScope ( const std::string & name) const
nodiscard

Checks if 'name' is in the current scope.

Parameters
name
Returns

Definition at line 63 of file ScopeResolver.cpp.

References m_scopes.

Referenced by Ark::internal::NameResolutionPass::visitKeyword().

◆ isRegistered()

bool Ark::internal::ScopeResolver::isRegistered ( const std::string & name) const
nodiscard

Checks if any scope has 'name', in reverse order.

Parameters
name
Returns

Definition at line 53 of file ScopeResolver.cpp.

References m_scopes.

Referenced by Ark::internal::NameResolutionPass::visitKeyword().

◆ operator=() [1/2]

ScopeResolver & Ark::internal::ScopeResolver::operator= ( const ScopeResolver & )
delete

◆ operator=() [2/2]

ScopeResolver & Ark::internal::ScopeResolver::operator= ( ScopeResolver && )
default

◆ registerInCurrent()

std::string Ark::internal::ScopeResolver::registerInCurrent ( const std::string & name,
bool is_mutable )

Register a Declaration in the current (last) scope.

Parameters
name
is_mutable
Returns
std::string the fully qualified name assigned by the scope

Definition at line 27 of file ScopeResolver.cpp.

References m_scopes.

Referenced by Ark::internal::NameResolutionPass::addDefinedSymbol().

◆ removeLastScope()

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

◆ saveNamespaceAndRemove()

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

Member Data Documentation

◆ m_scopes


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