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

#include <ImportSolver.hpp>

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

Public Member Functions

 ImportSolver (unsigned debug, const std::vector< std::filesystem::path > &libenv)
 Create a new ImportSolver.
 
ImportSolversetup (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 Nodeast () const noexcept override
 Output of the compiler pass.
 
- 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

std::pair< Node, bool > findAndReplaceImports (const Node &ast)
 Visits the AST, looking for import nodes to replace with their parsed module version.
 
std::vector< ImportparseImport (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< Importm_imports
 
std::unordered_map< std::string, Packagem_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

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

Detailed Description

Definition at line 28 of file ImportSolver.hpp.

Constructor & Destructor Documentation

◆ ImportSolver()

Ark::internal::ImportSolver::ImportSolver ( unsigned debug,
const std::vector< std::filesystem::path > & libenv )

Create a new ImportSolver.

Parameters
debugdebug level
libenvlist of paths to the standard library

Definition at line 13 of file ImportSolver.cpp.

Member Function Documentation

◆ ast()

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

Output of the compiler pass.

Returns
const Node& the modified AST

Implements Ark::internal::Pass.

Definition at line 136 of file ImportSolver.cpp.

References m_ast.

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

◆ findAndReplaceImports()

std::pair< Node, bool > Ark::internal::ImportSolver::findAndReplaceImports ( const Node & ast)
private

◆ findFile()

std::filesystem::path Ark::internal::ImportSolver::findFile ( const std::filesystem::path & file,
const Import & import ) const
nodiscardprivate

Search for an import file, using the root file path.

Parameters
filepath to the file containing the import
importcurrent import directive
Returns
std::filesystem::path

Definition at line 192 of file ImportSolver.cpp.

References m_libenv, m_root, and Ark::internal::testExtensions().

Referenced by parseImport().

◆ parseImport()

std::vector< Import > Ark::internal::ImportSolver::parseImport ( const std::filesystem::path & base_path,
const Import & import )
private

Parse a given file and returns a list of its imports. The AST is parsed and stored in m_modules[import.prefix].

Parameters
base_pathpath to the file containing the import
importcurrent import directive
Returns
std::vector<Import> imports found in the processed file

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

◆ process()

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

◆ setup()

ImportSolver & Ark::internal::ImportSolver::setup ( const std::filesystem::path & root,
const std::vector< Import > & origin_imports )

Configure the ImportSolver.

Parameters
rootpath to the root file that imports all others
origin_importsthe first imports to go through
Returns
ImportSolver& *this

Definition at line 17 of file ImportSolver.cpp.

References m_imports, and m_root.

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

Member Data Documentation

◆ m_ast

Node Ark::internal::ImportSolver::m_ast
private

Definition at line 54 of file ImportSolver.hpp.

Referenced by ast(), and process().

◆ m_debug_level

unsigned Ark::internal::ImportSolver::m_debug_level
private

Definition at line 51 of file ImportSolver.hpp.

Referenced by parseImport().

◆ m_imported

std::vector<std::string> Ark::internal::ImportSolver::m_imported
private

List of imports, in the order they were found and parsed.

Definition at line 57 of file ImportSolver.hpp.

Referenced by findAndReplaceImports().

◆ m_imports

std::stack<Import> Ark::internal::ImportSolver::m_imports
private

Definition at line 55 of file ImportSolver.hpp.

Referenced by process(), and setup().

◆ m_libenv

std::vector<std::filesystem::path> Ark::internal::ImportSolver::m_libenv
private

Definition at line 52 of file ImportSolver.hpp.

Referenced by findFile().

◆ m_packages

std::unordered_map<std::string, Package> Ark::internal::ImportSolver::m_packages
private

Package name to package AST & data mapping.

Definition at line 56 of file ImportSolver.hpp.

Referenced by findAndReplaceImports(), and parseImport().

◆ m_root

std::filesystem::path Ark::internal::ImportSolver::m_root
private

Folder were the entry file is.

Definition at line 53 of file ImportSolver.hpp.

Referenced by findFile(), and setup().


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