12#ifndef ARK_COMPILER_NAMERESOLUTIONPASS_HPP
13#define ARK_COMPILER_NAMERESOLUTIONPASS_HPP
17#include <unordered_set>
43 [[nodiscard]]
const Node&
ast()
const noexcept override;
66 void visit(
Node& node,
bool register_declarations);
91 [[nodiscard]]
bool mayBeFromPlugin(
const std::string& name)
const noexcept;
107 [[nodiscard]] std::string
offerSuggestion(
const std::string& str)
const;
Interface for a compiler pass (take in an AST, output an AST)
Handle scope resolution at compile time.
std::vector< std::string > m_plugin_names
void visit(Node &node, bool register_declarations)
Recursively visit nodes.
void visitKeyword(Node &node, Keyword keyword, bool register_declarations)
const Node & ast() const noexcept override
Unused overload that return the input AST (untouched as this pass only generates errors)
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.
std::unordered_set< std::string > m_language_symbols
Precomputed set of language symbols that can't be used to define variables.
std::unordered_set< std::string > m_defined_symbols
bool mayBeFromPlugin(const std::string &name) const noexcept
Checking if a symbol may be coming from a plugin.
void process(const Node &ast) override
Start visiting the given AST, checking for mutability violation and unbound variables.
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.
std::string updateSymbolWithFullyQualifiedName(Node &symbol)
void addSymbolNode(const Node &symbol, const std::string &old_name="")
Register a given node in the symbol table.
NameResolutionPass(unsigned debug)
Create a NameResolutionPass.
ScopeResolver m_scope_resolver
std::vector< Node > m_symbol_nodes
A node of an Abstract Syntax Tree for ArkScript.
An interface to describe compiler passes.
Keyword
The different keywords available.