diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-08-28 02:39:42 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-08-28 02:39:42 +0200 |
| commit | 8e655a0786aec5e0215e09f2a9629c6f32e34793 (patch) | |
| tree | 0788634cf66fed9c1a1d264b5b8c30da49380559 /boot/symbol.cc | |
| parent | 4d4537866690a1ef3d882f5e9a6e01d8220a3650 (diff) | |
| download | elna-8e655a0786aec5e0215e09f2a9629c6f32e34793.tar.gz | |
Reject declarations shadowing imports
Diffstat (limited to 'boot/symbol.cc')
| -rw-r--r-- | boot/symbol.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/boot/symbol.cc b/boot/symbol.cc index 8855d52..7ef09c9 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 <ranges> #include <cassert> #include <utility> @@ -356,21 +357,28 @@ namespace elna::boot this->symbols = std::make_shared<symbol_table>(global_table); } + std::shared_ptr<info> symbol_bag::lookup_import(const std::string& name) const + { + const auto found = std::ranges::find_if(this->imports, + [&name](const std::shared_ptr<symbol_table>& import_bag) { + return import_bag->lookup(name) != nullptr; + } + ); + return found == this->imports.cend() ? nullptr : (*found)->lookup(name); + } + std::shared_ptr<info> symbol_bag::lookup(const std::string& name) { - for (const auto& import_bag : this->imports) + if (auto result = this->lookup_import(name)) { - if (auto result = import_bag->lookup(name)) - { - return result; - } + return result; } return this->symbols->lookup(name); } bool symbol_bag::enter(const std::string& name, const std::shared_ptr<info>& entry) { - return this->symbols->enter(name, entry); + return this->lookup_import(name) == nullptr && this->symbols->enter(name, entry); } std::shared_ptr<symbol_table> symbol_bag::enter() |
