Skip to content
Snippets Groups Projects
Commit 2de704ec authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Prevent multiple importing of a given module

parent 3f08cc74
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -19,6 +19,12 @@ ASTModulesImporter::_importModule(ASTNode& import_node) ...@@ -19,6 +19,12 @@ ASTModulesImporter::_importModule(ASTNode& import_node)
ASTNode& module_name_node = *import_node.children[0]; ASTNode& module_name_node = *import_node.children[0];
const std::string module_name = module_name_node.string(); const std::string module_name = module_name_node.string();
if (auto [i_module_name, success] = m_imported_modules.insert(module_name); not success) {
std::cout << " * ignoring '" << rang::fgB::green << module_name << rang::style::reset
<< "' module, already imported\n";
return;
}
std::cout << " * importing '" << rang::fgB::green << module_name << rang::style::reset << "' module\n"; std::cout << " * importing '" << rang::fgB::green << module_name << rang::style::reset << "' module\n";
if (module_name == "math") { if (module_name == "math") {
......
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
#include <ASTNode.hpp> #include <ASTNode.hpp>
#include <set>
#include <string>
class SymbolTable; class SymbolTable;
class ASTModulesImporter class ASTModulesImporter
{ {
std::set<std::string> m_imported_modules;
SymbolTable& m_symbol_table; SymbolTable& m_symbol_table;
void _importModule(ASTNode& import_node); void _importModule(ASTNode& import_node);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment