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

@@ -747,15 +747,15 @@ namespace elna::gcc
{
for (const auto& variable_identifier : declaration->identifiers)
{
this->current_expression = get_inner_alias(
this->bag.lookup(variable_identifier.identifier)->is_variable()->symbol,
this->symbols);
location_t declaration_location = get_location(&declaration->position());
tree declaration_tree = build_decl(declaration_location, VAR_DECL,
get_identifier(variable_identifier.identifier.c_str()), this->current_expression);
bool result = this->symbols->enter(variable_identifier.identifier, declaration_tree);
tree declaration_tree = this->symbols->lookup(variable_identifier.identifier);
if (declaration_tree == NULL_TREE)
{
auto variable_symbol = this->bag.lookup(variable_identifier.identifier)->is_variable();
declaration_tree = declare_variable(variable_identifier.identifier, *variable_symbol, this->symbols);
}
// Set initializer if given.
if (declaration->body != nullptr)
{
@@ -771,19 +771,18 @@ namespace elna::gcc
print_type(TREE_TYPE(this->current_expression)).c_str());
}
}
else if (POINTER_TYPE_P(this->current_expression))
else if (declaration->is_extern)
{
DECL_EXTERNAL(declaration_tree) = declaration->is_extern;
}
else if (POINTER_TYPE_P(TREE_TYPE(declaration_tree)))
{
DECL_INITIAL(declaration_tree) = elna_pointer_nil_node;
}
DECL_EXTERNAL(declaration_tree) = declaration->is_extern;
TREE_PUBLIC(declaration_tree) = variable_identifier.exported;
this->current_expression = NULL_TREE;
if (!result)
{
error_at(declaration_location, "Variable '%s' already declared in this scope",
variable_identifier.identifier.c_str());
}
else if (lang_hooks.decls.global_bindings_p())
if (lang_hooks.decls.global_bindings_p())
{
TREE_STATIC(declaration_tree) = 1;
varpool_node::get_create(declaration_tree);