Document symbol bag class and methods

This commit is contained in:
2025-08-23 00:48:58 +02:00
parent 809e41bcc3
commit 8fc60202ff
9 changed files with 168 additions and 52 deletions

View File

@@ -358,14 +358,20 @@ namespace elna::boot
return result;
}
symbol_bag::symbol_bag()
symbol_bag::symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> global_table)
: unresolved(unresolved)
{
this->symbols = std::make_shared<symbol_table>();
this->symbols = std::make_shared<symbol_table>(global_table);
}
symbol_bag::symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> symbols)
: symbols(symbols), unresolved(unresolved)
forward_table::const_iterator symbol_bag::begin()
{
return unresolved.cbegin();
}
forward_table::const_iterator symbol_bag::end()
{
return unresolved.cend();
}
std::shared_ptr<info> symbol_bag::lookup(const std::string& name)
@@ -396,18 +402,31 @@ namespace elna::boot
this->symbols = child;
}
void symbol_bag::leave()
std::shared_ptr<symbol_table> symbol_bag::leave()
{
this->symbols = this->symbols->scope();
std::shared_ptr<symbol_table> result = this->symbols;
this->symbols = result->scope();
return result;
}
void symbol_bag::add_import(std::shared_ptr<symbol_table> table)
std::shared_ptr<alias_type> symbol_bag::declared(const std::string& symbol_name)
{
this->imports.push_front(table);
auto unresolved_alias = this->unresolved.find(symbol_name);
return unresolved_alias == this->unresolved.end() ? std::shared_ptr<alias_type>() : unresolved_alias->second;
}
std::shared_ptr<alias_type> symbol_bag::resolve(const std::string& symbol_name, type& resolution)
{
auto unresolved_declaration = this->unresolved.at(symbol_name);
unresolved_declaration->reference = resolution;
return unresolved_declaration;
}
void symbol_bag::add_import(const symbol_bag& bag)
{
add_import(bag.symbols);
this->imports.push_front(bag.symbols);
}
}