Support while … else

This commit is contained in:
2025-04-13 18:40:49 +02:00
parent 8ec407515a
commit 1cd44508c3
6 changed files with 145 additions and 135 deletions

View File

@ -267,8 +267,8 @@ namespace elna::gcc
void generic_visitor::declare_procedure(boot::procedure_definition *const definition)
{
tree declaration_type = build_procedure_type(definition->heading());
tree fndecl = build_fn_decl(definition->identifier.c_str(), declaration_type);
this->symbols->enter(definition->identifier, fndecl);
tree fndecl = build_fn_decl(definition->identifier.identifier.c_str(), declaration_type);
this->symbols->enter(definition->identifier.identifier, fndecl);
if (definition->heading().return_type.no_return)
{
@ -296,7 +296,7 @@ namespace elna::gcc
++parameter_name;
}
DECL_ARGUMENTS(fndecl) = argument_chain;
TREE_PUBLIC(fndecl) = definition->exported;
TREE_PUBLIC(fndecl) = definition->identifier.exported;
TREE_ADDRESSABLE(fndecl) = 1;
DECL_EXTERNAL(fndecl) = definition->body == nullptr;
}
@ -386,7 +386,7 @@ namespace elna::gcc
{
return;
}
tree fndecl = this->symbols->lookup(definition->identifier);
tree fndecl = this->symbols->lookup(definition->identifier.identifier);
push_struct_function(fndecl, false);
DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>();
@ -778,15 +778,15 @@ namespace elna::gcc
return;
}
tree definition_tree = build_decl(definition_location, CONST_DECL,
get_identifier(definition->identifier.c_str()), TREE_TYPE(this->current_expression));
auto result = this->symbols->enter(definition->identifier, definition_tree);
get_identifier(definition->identifier.identifier.c_str()), TREE_TYPE(this->current_expression));
auto result = this->symbols->enter(definition->identifier.identifier, definition_tree);
if (result)
{
DECL_INITIAL(definition_tree) = this->current_expression;
TREE_CONSTANT(definition_tree) = 1;
TREE_READONLY(definition_tree) = 1;
TREE_PUBLIC(definition_tree) = definition->exported;
TREE_PUBLIC(definition_tree) = definition->identifier.exported;
if (!lang_hooks.decls.global_bindings_p())
{
@ -798,7 +798,7 @@ namespace elna::gcc
else
{
error_at(definition_location, "Variable '%s' already declared in this scope",
definition->identifier.c_str());
definition->identifier.identifier.c_str());
}
this->current_expression = NULL_TREE;
}
@ -806,16 +806,16 @@ namespace elna::gcc
void generic_visitor::visit(boot::type_definition *definition)
{
location_t definition_location = get_location(&definition->position());
this->current_expression = this->unresolved.at(definition->identifier);
this->current_expression = this->unresolved.at(definition->identifier.identifier);
definition->body().accept(this);
tree definition_tree = build_decl(definition_location, TYPE_DECL,
get_identifier(definition->identifier.c_str()), this->current_expression);
get_identifier(definition->identifier.identifier.c_str()), this->current_expression);
TREE_PUBLIC(definition_tree) = definition->exported;
TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.c_str());
TREE_PUBLIC(definition_tree) = definition->identifier.exported;
TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.identifier.c_str());
auto result = this->symbols->enter(definition->identifier, definition_tree);
auto result = this->symbols->enter(definition->identifier.identifier, definition_tree);
gcc_assert(result);
this->current_expression = NULL_TREE;
@ -878,8 +878,8 @@ namespace elna::gcc
location_t declaration_location = get_location(&declaration->position());
tree declaration_tree = build_decl(declaration_location, VAR_DECL,
get_identifier(declaration->identifier.c_str()), this->current_expression);
bool result = this->symbols->enter(declaration->identifier, declaration_tree);
get_identifier(declaration->identifier.identifier.c_str()), this->current_expression);
bool result = this->symbols->enter(declaration->identifier.identifier, declaration_tree);
if (POINTER_TYPE_P(this->current_expression))
{
@ -889,7 +889,7 @@ namespace elna::gcc
if (!result)
{
error_at(declaration_location, "variable '%s' already declared in this scope",
declaration->identifier.c_str());
declaration->identifier.identifier.c_str());
}
else if (lang_hooks.decls.global_bindings_p())
{
@ -1277,6 +1277,13 @@ namespace elna::gcc
{
make_if_branch(*branch, goto_check);
}
if (statement->alternative != nullptr)
{
enter_scope();
visit_statements(*statement->alternative);
tree mapping = leave_scope();
append_statement(mapping);
}
append_statement(branch_end_expression);
this->current_expression = NULL_TREE;
}