![]() |
ArkScript
A small, fast, functional and scripting language for video games
|
#include <ImportSolver.hpp>
Public Member Functions | |
ImportSolver (unsigned debug, const std::vector< std::filesystem::path > &libenv) | |
Create a new ImportSolver. | |
ImportSolver & | setup (const std::filesystem::path &root, const std::vector< Import > &origin_imports) |
Configure the ImportSolver. | |
void | process (const Node &origin_ast) override |
Start processing the given AST. | |
const Node & | ast () const noexcept override |
Output of the compiler pass. | |
![]() | |
Pass (std::string name, unsigned debug_level) | |
Construct a new Pass object. | |
virtual | ~Pass ()=default |
Private Member Functions | |
std::pair< Node, bool > | findAndReplaceImports (const Node &ast) |
Visits the AST, looking for import nodes to replace with their parsed module version. | |
std::vector< Import > | parseImport (const std::filesystem::path &base_path, const Import &import) |
Parse a given file and returns a list of its imports. The AST is parsed and stored in m_modules[import.prefix]. | |
std::filesystem::path | findFile (const std::filesystem::path &file, const Import &import) const |
Search for an import file, using the root file path. | |
Private Attributes | |
unsigned | m_debug_level |
std::vector< std::filesystem::path > | m_libenv |
std::filesystem::path | m_root |
Folder were the entry file is. | |
Node | m_ast |
std::stack< Import > | m_imports |
std::unordered_map< std::string, Package > | m_packages |
Package name to package AST & data mapping. | |
std::vector< std::string > | m_imported |
List of imports, in the order they were found and parsed. | |
Additional Inherited Members | |
![]() | |
Logger | m_logger |
Definition at line 28 of file ImportSolver.hpp.
Ark::internal::ImportSolver::ImportSolver | ( | unsigned | debug, |
const std::vector< std::filesystem::path > & | libenv ) |
Create a new ImportSolver.
debug | debug level |
libenv | list of paths to the standard library |
Definition at line 13 of file ImportSolver.cpp.
|
nodiscardoverridevirtualnoexcept |
Output of the compiler pass.
Implements Ark::internal::Pass.
Definition at line 136 of file ImportSolver.cpp.
References m_ast.
Referenced by Ark::Welder::computeAST(), and findAndReplaceImports().
|
private |
Visits the AST, looking for import nodes to replace with their parsed module version.
ast |
Definition at line 69 of file ImportSolver.cpp.
References Ark::internal::Node::arkNamespace(), ast(), Ark::internal::Namespace::ast, Ark::internal::Begin, Ark::internal::Node::col(), Ark::internal::Node::constList(), Ark::internal::Node::filename(), findAndReplaceImports(), Ark::internal::Import, Ark::internal::Keyword, Ark::internal::Node::line(), Ark::internal::List, Ark::internal::Node::list(), m_imported, m_packages, Ark::internal::Node::nodeType(), and Ark::internal::Node::push_back().
Referenced by findAndReplaceImports(), and process().
|
nodiscardprivate |
Search for an import file, using the root file path.
file | path to the file containing the import |
import | current import directive |
Definition at line 192 of file ImportSolver.cpp.
References m_libenv, m_root, and Ark::internal::testExtensions().
Referenced by parseImport().
|
private |
Parse a given file and returns a list of its imports. The AST is parsed and stored in m_modules[import.prefix].
base_path | path to the file containing the import |
import | current import directive |
Definition at line 141 of file ImportSolver.cpp.
References Ark::internal::Parser::ast(), findFile(), Ark::internal::Import, Ark::internal::Parser::imports(), Ark::internal::List, m_debug_level, Ark::internal::Pass::m_logger, m_packages, Ark::internal::Parser::process(), Ark::Utils::readFile(), Ark::internal::Logger::traceEnd(), and Ark::internal::Logger::traceStart().
|
overridevirtual |
Start processing the given AST.
ast |
Implements Ark::internal::Pass.
Definition at line 30 of file ImportSolver.cpp.
References Ark::internal::Logger::debug(), findAndReplaceImports(), m_ast, m_imports, Ark::internal::Pass::m_logger, Ark::internal::Logger::traceEnd(), and Ark::internal::Logger::traceStart().
Referenced by Ark::Welder::computeAST().
ImportSolver & Ark::internal::ImportSolver::setup | ( | const std::filesystem::path & | root, |
const std::vector< Import > & | origin_imports ) |
Configure the ImportSolver.
root | path to the root file that imports all others |
origin_imports | the first imports to go through |
Definition at line 17 of file ImportSolver.cpp.
References m_imports, and m_root.
Referenced by Ark::Welder::computeAST().
|
private |
Definition at line 54 of file ImportSolver.hpp.
|
private |
Definition at line 51 of file ImportSolver.hpp.
Referenced by parseImport().
|
private |
List of imports, in the order they were found and parsed.
Definition at line 57 of file ImportSolver.hpp.
Referenced by findAndReplaceImports().
|
private |
Definition at line 55 of file ImportSolver.hpp.
|
private |
Definition at line 52 of file ImportSolver.hpp.
Referenced by findFile().
|
private |
Package name to package AST & data mapping.
Definition at line 56 of file ImportSolver.hpp.
Referenced by findAndReplaceImports(), and parseImport().
|
private |
Folder were the entry file is.
Definition at line 53 of file ImportSolver.hpp.
Referenced by findFile(), and setup().