12#ifndef ARK_COMPILER_IMPORTSOLVER_HPP
13#define ARK_COMPILER_IMPORTSOLVER_HPP
19#include <unordered_map>
36 ImportSolver(
unsigned debug,
const std::vector<std::filesystem::path>& libenv);
44 ImportSolver&
setup(
const std::filesystem::path& root,
const std::vector<Import>& origin_imports);
48 [[nodiscard]]
const Node&
ast()
const noexcept override;
74 std::vector<Import>
parseImport(
const std::filesystem::path& base_path,
const Import&
import);
83 [[nodiscard]] std::filesystem::path
findFile(
const std::filesystem::path& file,
const Import&
import)
const;
AST node used by the parser, optimizer and compiler.
Interface for a compiler pass (take in an AST, output an AST)
std::filesystem::path m_root
Folder were the entry file is.
std::unordered_map< std::string, Package > m_packages
Package name to package AST & data mapping.
void process(const Node &origin_ast) override
Start processing the given AST.
std::filesystem::path findFile(const std::filesystem::path &file, const Import &import) const
Search for an import file, using the root file path.
std::vector< std::filesystem::path > m_libenv
std::stack< Import > m_imports
std::pair< Node, bool > findAndReplaceImports(const Node &ast)
Visits the AST, looking for import nodes to replace with their parsed module version.
ImportSolver & setup(const std::filesystem::path &root, const std::vector< Import > &origin_imports)
Configure the ImportSolver.
ImportSolver(unsigned debug, const std::vector< std::filesystem::path > &libenv)
Create a new ImportSolver.
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[impor...
std::vector< std::string > m_imported
List of imports, in the order they were found and parsed.
const Node & ast() const noexcept override
Output of the compiler pass.
A node of an Abstract Syntax Tree for ArkScript.
An interface to describe compiler passes.