ArkScript
A small, lisp-inspired, functional scripting language
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)
 Start visiting the given AST, checking for mutability violation and unbound variables.
 
const Node & ast () const noexcept
 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
 
void configureLogger (std::ostream &os)
 Set a custom output stream for the logger.
 

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< Node > m_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 25 of file NameResolutionPass.hpp.

Constructor & Destructor Documentation

◆ NameResolutionPass()

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 50 of file NameResolutionPass.cpp.

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

Referenced by Ark::Welder::computeASTFromStringWithKnownSymbols(), 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 270 of file NameResolutionPass.cpp.

References Ark::internal::Node::filename(), m_language_symbols, m_symbol_nodes, Ark::internal::Node::position(), Ark::internal::FileSpan::start, and Ark::internal::Node::string().

Referenced by visit().

◆ ast()

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

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

Returns
const Node& ast

Definition at line 45 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 344 of file NameResolutionPass.cpp.

References Ark::internal::HiddenSymbolSuffix, 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 380 of file NameResolutionPass.cpp.

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

Referenced by checkForUndefinedSymbol().

◆ process()

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

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

Parameters
astAST to analyze

Definition at line 27 of file NameResolutionPass.cpp.

References ast(), checkForUndefinedSymbol(), Ark::internal::Logger::debug(), Ark::internal::Node::debugPrint(), m_ast, Ark::internal::Pass::m_logger, Ark::internal::Logger::shouldDebug(), 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 55 of file NameResolutionPass.hpp.

Referenced by ast(), process(), and updateSymbolWithFullyQualifiedName().

◆ 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 56 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 59 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 57 of file NameResolutionPass.hpp.

Referenced by addSymbolNode(), and checkForUndefinedSymbol().


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