-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,027 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef ARK_MODULE_HPP | ||
#define ARK_MODULE_HPP | ||
|
||
#include <Ark/Compiler/AST/Node.hpp> | ||
|
||
namespace Ark::internal | ||
{ | ||
// TODO store something better than just the AST (AST+what we are importing as private/public/namespaced... vs all) | ||
// so that we can remember the order in which we encountered imports. | ||
struct Module | ||
{ | ||
Node ast; | ||
bool has_been_processed = false; // TODO document this | ||
}; | ||
} | ||
|
||
#endif // ARK_MODULE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef ARK_COMPILER_IMPORTSOLVER_HPP | ||
#define ARK_COMPILER_IMPORTSOLVER_HPP | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <filesystem> | ||
#include <unordered_map> | ||
|
||
#include <Ark/Compiler/AST/Node.hpp> | ||
#include <Ark/Compiler/AST/Import.hpp> | ||
#include <Ark/Compiler/AST/Module.hpp> | ||
|
||
namespace Ark::internal | ||
{ | ||
class ImportSolver final | ||
{ | ||
public: | ||
ImportSolver(unsigned debug, const std::vector<std::filesystem::path>& libenv); | ||
|
||
void process(const std::filesystem::path& root, const Node& origin_ast, const std::vector<Import>& origin_imports); | ||
|
||
const Node& ast() const noexcept; | ||
|
||
private: | ||
unsigned m_debug; | ||
std::vector<std::filesystem::path> m_libenv; | ||
std::filesystem::path m_root; ///< Folder were the entry file is | ||
Node m_ast; | ||
std::unordered_map<std::string, Module> m_modules; ///< Package to module map | ||
// TODO is this ok? is this fine? this is sort of ugly | ||
std::vector<std::string> m_imported; ///< List of imports, in the order they were found and parsed | ||
|
||
/** | ||
* @brief Visits the AST, looking for import nodes to replace with their parsed module version | ||
* @param ast | ||
* @return | ||
*/ | ||
std::pair<Node, bool> findAndReplaceImports(const Node& ast); | ||
|
||
/** | ||
* @brief Parse a given file and returns a list of its imports. | ||
* The AST is parsed and stored in m_modules[import.prefix] | ||
* | ||
* @param file path to the file containing the import | ||
* @param import current import directive | ||
* @return std::vector<Import> imports found in the processed file | ||
*/ | ||
std::vector<Import> parseImport(const std::filesystem::path& file, const Import& import); | ||
|
||
/** | ||
* @brief Search for an import file, using the root file path | ||
* | ||
* @param file path to the file containing the import | ||
* @param import current import directive | ||
* @return std::filesystem::path | ||
*/ | ||
std::filesystem::path findFile(const std::filesystem::path& file, const Import& import); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.