aboutsummaryrefslogtreecommitdiff
path: root/boot/symbol.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/symbol.cc')
-rw-r--r--boot/symbol.cc20
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()