Document symbol bag class and methods
This commit is contained in:
@@ -314,7 +314,7 @@ namespace elna::boot
|
||||
|
||||
procedure_info::procedure_info(const procedure_type symbol, const std::vector<std::string> names,
|
||||
std::shared_ptr<symbol_table> scope)
|
||||
: symbol(symbol), names(names), symbols(scope)
|
||||
: symbol(symbol), names(names), scope(scope)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -323,6 +323,11 @@ namespace elna::boot
|
||||
return std::static_pointer_cast<procedure_info>(shared_from_this());
|
||||
}
|
||||
|
||||
bool procedure_info::is_extern() const
|
||||
{
|
||||
return this->scope == nullptr;
|
||||
}
|
||||
|
||||
constant_info::constant_info(const variant& symbol)
|
||||
: symbol(symbol)
|
||||
{
|
||||
@@ -333,8 +338,8 @@ namespace elna::boot
|
||||
return std::static_pointer_cast<constant_info>(shared_from_this());
|
||||
}
|
||||
|
||||
variable_info::variable_info(const type symbol)
|
||||
: symbol(symbol)
|
||||
variable_info::variable_info(const type symbol, bool is_extern)
|
||||
: symbol(symbol), is_extern(is_extern)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -358,14 +363,10 @@ namespace elna::boot
|
||||
return result;
|
||||
}
|
||||
|
||||
symbol_bag::symbol_bag()
|
||||
{
|
||||
this->symbols = std::make_shared<symbol_table>();
|
||||
}
|
||||
|
||||
symbol_bag::symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> symbols)
|
||||
: symbols(symbols), unresolved(unresolved)
|
||||
symbol_bag::symbol_bag(forward_table&& unresolved, std::shared_ptr<symbol_table> global_table)
|
||||
: unresolved(unresolved)
|
||||
{
|
||||
this->symbols = std::make_shared<symbol_table>(global_table);
|
||||
}
|
||||
|
||||
std::shared_ptr<info> symbol_bag::lookup(const std::string& name)
|
||||
@@ -396,18 +397,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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user