diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-10-08 19:45:19 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-10-08 19:45:19 +0200 |
| commit | 7d07bef760a8807fe49fbe5c90799a1822f95973 (patch) | |
| tree | 8b8d8ed0003dc61c4bd7313df86f6cbaea3d4b82 /include | |
| parent | d392f0c54a7748b816ab327758ae835f73cd1c0a (diff) | |
| download | elna-7d07bef760a8807fe49fbe5c90799a1822f95973.tar.gz | |
Make modules re-exportable
Diffstat (limited to 'include')
| -rw-r--r-- | include/elna/boot/ast.h | 8 | ||||
| -rw-r--r-- | include/elna/boot/dependency.h | 5 | ||||
| -rw-r--r-- | include/elna/boot/symbol.h | 9 |
3 files changed, 18 insertions, 4 deletions
diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h index 6edeb25..06e5d41 100644 --- a/include/elna/boot/ast.h +++ b/include/elna/boot/ast.h @@ -1027,13 +1027,19 @@ namespace elna::boot /** * Import statement. + * + * An asterisk after the module path marks a re-export: the symbols the + * imported module exports become visible to the modules importing this + * one as well. */ class import_declaration : public node { public: const std::vector<std::string> segments; + const bool exported; - import_declaration(const source_position position, std::vector<std::string>&& segments); + import_declaration(const source_position position, std::vector<std::string>&& segments, + const bool exported = false); void accept(parser_visitor *visitor) override; }; diff --git a/include/elna/boot/dependency.h b/include/elna/boot/dependency.h index 7bd3de9..f52bfb1 100644 --- a/include/elna/boot/dependency.h +++ b/include/elna/boot/dependency.h @@ -156,6 +156,8 @@ namespace elna::boot { source_position position; std::shared_ptr<symbol_table> symbols; + /// Whether the importing module re-exports the symbols. + bool reexport = false; }; /** @@ -302,7 +304,8 @@ namespace elna::boot } imports.push_back({ .position = sub_tree->position(), - .symbols = this->cache.find(module_path)->second.exported_symbols() + .symbols = this->cache.find(module_path)->second.exported_symbols(), + .reexport = sub_tree->exported }); } result.append(key, std::move(circular)); diff --git a/include/elna/boot/symbol.h b/include/elna/boot/symbol.h index 07bcf80..bdac269 100644 --- a/include/elna/boot/symbol.h +++ b/include/elna/boot/symbol.h @@ -558,6 +558,8 @@ namespace elna::boot { std::shared_ptr<symbol_table> symbols; std::vector<std::shared_ptr<symbol_table>> imports; + // The subset of imports that is re-exported by this module. + std::vector<std::shared_ptr<symbol_table>> reexports; forward_table unresolved; std::shared_ptr<info> lookup_import(const std::string& name) const; @@ -643,11 +645,14 @@ namespace elna::boot * earlier import keeps its names. * * \param symbols Exported symbol table of another module. + * \param reexport Whether the imported symbols are exported by this + * module as well, so they are visible to its importers. * * \return Names an earlier import already brought into the scope, * sorted by name. */ - std::vector<import_collision> add_import(const std::shared_ptr<symbol_table>& symbols); + std::vector<import_collision> add_import(const std::shared_ptr<symbol_table>& symbols, + const bool reexport = false); /** * Tells whether the current scope is the module global scope. @@ -661,7 +666,7 @@ namespace elna::boot /** * The symbol table containing the exported declarations of the - * module, computed lazily. Must be called while the current scope is + * module and the symbols of the modules it re-exports, computed lazily. Must be called while the current scope is * still the module scope. * * \return Exported symbols of the module. |
