aboutsummaryrefslogtreecommitdiff
path: root/boot/symbol.cc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-19 23:52:00 +0200
committerEugen Wissner <belka@caraus.de>2026-09-19 23:52:00 +0200
commit74e75e41fe12f19e5365a3152ffafa1a29376240 (patch)
tree5cee18580124db1bd9c8bc01e8b58ed16b0cf159 /boot/symbol.cc
parentb3cf1d087283bd85e0d9906dfdc320bd9eb4021a (diff)
downloadelna-74e75e41fe12f19e5365a3152ffafa1a29376240.tar.gz
Reject exporting symbols with the same name from 2 modulesHEADcpp
Diffstat (limited to 'boot/symbol.cc')
-rw-r--r--boot/symbol.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/boot/symbol.cc b/boot/symbol.cc
index 58524ad..962808a 100644
--- a/boot/symbol.cc
+++ b/boot/symbol.cc
@@ -17,6 +17,7 @@ along with GCC; see the file COPYING3. If not see
#include "elna/boot/symbol.h"
+#include <algorithm>
#include <ranges>
#include <cassert>
#include <utility>
@@ -511,9 +512,24 @@ namespace elna::boot
return this->unresolved.insert({ symbol_name, std::move(forward_declaration) }).second;
}
- void symbol_bag::add_import(const std::shared_ptr<symbol_table>& symbols)
+ std::vector<import_collision> symbol_bag::add_import(const std::shared_ptr<symbol_table>& symbols)
{
- this->imports.push_front(symbols);
+ std::vector<import_collision> collisions;
+
+ for (const auto& [name, imported] : *symbols)
+ {
+ std::shared_ptr<info> original = lookup_import(name);
+
+ // The same module imported twice hands out the same symbol, which
+ // doesn't conflict with itself.
+ if (original != nullptr && original != imported)
+ {
+ collisions.push_back({ .name = name, .original = std::move(original) });
+ }
+ }
+ this->imports.push_back(symbols);
+
+ return collisions;
}
bool symbol_bag::is_global() const