aboutsummaryrefslogtreecommitdiff
path: root/include/elna/boot/symbol.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/elna/boot/symbol.h')
-rw-r--r--include/elna/boot/symbol.h30
1 files changed, 23 insertions, 7 deletions
diff --git a/include/elna/boot/symbol.h b/include/elna/boot/symbol.h
index 5bbe2c6..a5f7ca8 100644
--- a/include/elna/boot/symbol.h
+++ b/include/elna/boot/symbol.h
@@ -19,7 +19,7 @@ along with GCC; see the file COPYING3. If not see
#include <cstdint>
#include <filesystem>
-#include <forward_list>
+#include <map>
#include <memory>
#include <optional>
#include <string>
@@ -300,11 +300,13 @@ namespace elna::boot
std::is_convertible_v<U, T> || std::is_assignable_v<T, U>,
T
>;
- using iterator = std::unordered_map<std::string, symbol_ptr>::iterator;
- using const_iterator = std::unordered_map<std::string, symbol_ptr>::const_iterator;
+ using iterator = std::map<std::string, symbol_ptr>::iterator;
+ using const_iterator = std::map<std::string, symbol_ptr>::const_iterator;
private:
- std::unordered_map<std::string, symbol_ptr> entries;
+ // Ordered, so that a pass iterating the table reports in a stable
+ // order without sorting first.
+ std::map<std::string, symbol_ptr> entries;
std::shared_ptr<symbol_map> outer_scope;
public:
@@ -528,6 +530,16 @@ namespace elna::boot
std::shared_ptr<symbol_table> builtin_symbol_table(const target_info& target);
/**
+ * A name exported by more than one imported module.
+ */
+ struct import_collision
+ {
+ std::string name;
+ /// The symbol imported first, which keeps the name.
+ std::shared_ptr<info> original;
+ };
+
+ /**
* Symbol bag contains:
*
* - the symbol table of a module itself
@@ -537,7 +549,7 @@ namespace elna::boot
class symbol_bag
{
std::shared_ptr<symbol_table> symbols;
- std::forward_list<std::shared_ptr<symbol_table>> imports;
+ std::vector<std::shared_ptr<symbol_table>> imports;
forward_table unresolved;
std::shared_ptr<info> lookup_import(const std::string& name) const;
@@ -619,11 +631,15 @@ namespace elna::boot
bool forward_declare(const std::string& symbol_name, std::shared_ptr<alias_type> forward_declaration);
/**
- * Add imported symbols to the scope.
+ * Add imported symbols to the scope. The symbols are appended, so an
+ * earlier import keeps its names.
*
* \param symbols Exported symbol table of another module.
+ *
+ * \return Names an earlier import already brought into the scope,
+ * sorted by name.
*/
- void add_import(const std::shared_ptr<symbol_table>& symbols);
+ std::vector<import_collision> add_import(const std::shared_ptr<symbol_table>& symbols);
/**
* Tells whether the current scope is the module global scope.