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

#include <NameResolutionPass.hpp>

Inheritance diagram for Ark::internal::NameResolutionPass:
[legend]
Collaboration diagram for Ark::internal::NameResolutionPass:
[legend]

Public Member Functions

 NameResolutionPass (unsigned debug)
 Create a NameResolutionPass.
 
void process (const Node &ast) override
 Start visiting the given AST, checking for mutability violation and unbound variables.
 
const Nodeast () const noexcept override
 Unused overload that return the input AST (untouched as this pass only generates errors)
 
std::string addDefinedSymbol (const std::string &sym, bool is_mutable)
 Register a symbol as defined, so that later we can throw errors on undefined symbols.
 
- Public Member Functions inherited from Ark::internal::Pass
 Pass (std::string name, unsigned debug_level)
 Construct a new Pass object.
 
virtual ~Pass ()=default
 

Private Member Functions

void visit (Node &node, bool register_declarations)
 Recursively visit nodes.
 
void visitKeyword (Node &node, Keyword keyword, bool register_declarations)
 
void addSymbolNode (const Node &symbol, const std::string &old_name="")
 Register a given node in the symbol table.
 
bool mayBeFromPlugin (const std::string &name) const noexcept
 Checking if a symbol may be coming from a plugin.
 
std::string updateSymbolWithFullyQualifiedName (Node &symbol)
 
void checkForUndefinedSymbol () const
 Checks for undefined symbols, not present in the defined symbols table.
 
std::string offerSuggestion (const std::string &str) const
 Suggest a symbol of what the user may have meant to input.
 

Private Attributes

Node m_ast
 
std::unordered_set< std::string > m_language_symbols
 Precomputed set of language symbols that can't be used to define variables.
 
std::vector< Nodem_symbol_nodes
 
std::unordered_set< std::string > m_defined_symbols
 
std::vector< std::string > m_plugin_names
 
ScopeResolver m_scope_resolver
 

Additional Inherited Members

- Protected Attributes inherited from Ark::internal::Pass
Logger m_logger
 

Detailed Description

Definition at line 24 of file NameResolutionPass.hpp.

Constructor & Destructor Documentation

◆ NameResolutionPass()

Ark::internal::NameResolutionPass::NameResolutionPass ( unsigned debug)
explicit

Member Function Documentation

◆ addDefinedSymbol()

std::string Ark::internal::NameResolutionPass::addDefinedSymbol ( const std::string & sym,
bool is_mutable )

Register a symbol as defined, so that later we can throw errors on undefined symbols.

Parameters
sym
is_mutabletrue if the symbol is inside mut/set, false otherwise (let)

Definition at line 48 of file NameResolutionPass.cpp.

References m_defined_symbols, m_scope_resolver, and Ark::internal::ScopeResolver::registerInCurrent().

Referenced by Ark::Welder::registerSymbol(), and visitKeyword().

◆ addSymbolNode()

void Ark::internal::NameResolutionPass::addSymbolNode ( const Node & symbol,
const std::string & old_name = "" )
private

Register a given node in the symbol table.

Parameters
symbol
old_nameold name for symbol, to replace it with the new one if it was renamed

Definition at line 269 of file NameResolutionPass.cpp.

References Ark::internal::Node::col(), Ark::internal::Node::filename(), Ark::internal::Node::line(), m_language_symbols, m_symbol_nodes, and Ark::internal::Node::string().

Referenced by visit().

◆ ast()

const Node & Ark::internal::NameResolutionPass::ast ( ) const
nodiscardoverridevirtualnoexcept

Unused overload that return the input AST (untouched as this pass only generates errors)

Returns
const Node& ast

Implements Ark::internal::Pass.

Definition at line 43 of file NameResolutionPass.cpp.

References m_ast.

Referenced by Ark::Welder::computeAST(), and process().

◆ checkForUndefinedSymbol()

void Ark::internal::NameResolutionPass::checkForUndefinedSymbol ( ) const
private

Checks for undefined symbols, not present in the defined symbols table.

Definition at line 348 of file NameResolutionPass.cpp.

References m_defined_symbols, m_symbol_nodes, mayBeFromPlugin(), and offerSuggestion().

Referenced by process().

◆ mayBeFromPlugin()

bool Ark::internal::NameResolutionPass::mayBeFromPlugin ( const std::string & name) const
nodiscardprivatenoexcept

Checking if a symbol may be coming from a plugin.

Parameters
namesymbol name
Returns
true the symbol may be from a plugin, loaded at runtime
false

Definition at line 300 of file NameResolutionPass.cpp.

References Ark::Utils::splitString().

Referenced by checkForUndefinedSymbol().

◆ offerSuggestion()

std::string Ark::internal::NameResolutionPass::offerSuggestion ( const std::string & str) const
nodiscardprivate

Suggest a symbol of what the user may have meant to input.

Parameters
strthe string
Returns
std::string

Definition at line 378 of file NameResolutionPass.cpp.

References Ark::Utils::levenshteinDistance(), m_defined_symbols, and m_language_symbols.

Referenced by checkForUndefinedSymbol().

◆ process()

void Ark::internal::NameResolutionPass::process ( const Node & ast)
overridevirtual

Start visiting the given AST, checking for mutability violation and unbound variables.

Parameters
astAST to analyze

Implements Ark::internal::Pass.

Definition at line 25 of file NameResolutionPass.cpp.

References ast(), checkForUndefinedSymbol(), Ark::internal::Node::debugPrint(), m_ast, Ark::internal::Pass::m_logger, Ark::internal::Logger::shouldTrace(), Ark::internal::Logger::trace(), Ark::internal::Logger::traceEnd(), Ark::internal::Logger::traceStart(), and visit().

Referenced by Ark::Welder::computeAST().

◆ updateSymbolWithFullyQualifiedName()

◆ visit()

◆ visitKeyword()

Member Data Documentation

◆ m_ast

Node Ark::internal::NameResolutionPass::m_ast
private

Definition at line 54 of file NameResolutionPass.hpp.

Referenced by ast(), and process().

◆ m_defined_symbols

std::unordered_set<std::string> Ark::internal::NameResolutionPass::m_defined_symbols
private

◆ m_language_symbols

std::unordered_set<std::string> Ark::internal::NameResolutionPass::m_language_symbols
private

Precomputed set of language symbols that can't be used to define variables.

Definition at line 55 of file NameResolutionPass.hpp.

Referenced by addSymbolNode(), NameResolutionPass(), offerSuggestion(), updateSymbolWithFullyQualifiedName(), and visitKeyword().

◆ m_plugin_names

std::vector<std::string> Ark::internal::NameResolutionPass::m_plugin_names
private

Definition at line 58 of file NameResolutionPass.hpp.

Referenced by visitKeyword().

◆ m_scope_resolver

ScopeResolver Ark::internal::NameResolutionPass::m_scope_resolver
private

◆ m_symbol_nodes

std::vector<Node> Ark::internal::NameResolutionPass::m_symbol_nodes
private

Definition at line 56 of file NameResolutionPass.hpp.

Referenced by addSymbolNode(), and checkForUndefinedSymbol().


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