Check for duplicate fields in the declaration visitor

This commit is contained in:
2025-03-15 23:01:05 +01:00
parent fa73f14070
commit 978dd44a25
5 changed files with 131 additions and 47 deletions

View File

@ -32,15 +32,11 @@ along with GCC; see the file COPYING3. If not see
#include "varasm.h"
#include "fold-const.h"
#include "langhooks.h"
#include <set>
namespace elna
{
namespace gcc
{
tree handle_symbol(const std::string& symbol_name, const boot::type& type,
std::shared_ptr<boot::symbol_table> from, std::shared_ptr<symbol_table> to);
tree get_inner_alias(const boot::type& type,
std::shared_ptr<boot::symbol_table> from, std::shared_ptr<symbol_table> to)
{
@ -102,10 +98,6 @@ namespace gcc
{
handle_symbol(symbol_name, symbol_info->is_type()->symbol, info_table, symbols);
}
for (auto& [symbol_name, symbol_info] : *info_table)
{
// printf("%s\n", symbol_name.c_str());
}
}
return std::move(declaration_visitor.errors());
}
@ -418,11 +410,6 @@ namespace gcc
return bind_expr;
}
tree generic_visitor::lookup(const std::string& name)
{
return this->symbols->lookup(name);
}
void generic_visitor::visit(boot::number_literal<std::int32_t> *literal)
{
this->current_expression = build_int_cst(elna_int_type_node, literal->value);
@ -775,7 +762,7 @@ namespace gcc
void generic_visitor::visit(boot::type_definition *definition)
{
location_t definition_location = get_location(&definition->position());
this->current_expression = lookup(definition->identifier);
this->current_expression = this->symbols->lookup(definition->identifier);
definition->body().accept(this);
tree definition_tree = build_decl(definition_location, TYPE_DECL,
@ -847,7 +834,7 @@ namespace gcc
void generic_visitor::visit(boot::variable_expression *expression)
{
auto symbol = lookup(expression->name);
auto symbol = this->symbols->lookup(expression->name);
if (symbol == NULL_TREE)
{
@ -1140,7 +1127,7 @@ namespace gcc
void generic_visitor::visit(boot::primitive_type_expression *type)
{
tree symbol = lookup(type->name);
tree symbol = this->symbols->lookup(type->name);
if (symbol == NULL_TREE || !TYPE_P(symbol))
{
@ -1181,21 +1168,12 @@ namespace gcc
void generic_visitor::visit(boot::record_type_expression *type)
{
std::set<std::string> field_names;
tree composite_type_node = this->current_expression == NULL_TREE
? make_node(RECORD_TYPE)
: this->current_expression;
for (auto& field : type->fields)
{
if (field_names.find(field.first) != field_names.cend())
{
error_at(get_location(&field.second->position()), "repeated field name");
this->current_expression = error_mark_node;
return;
}
field_names.insert(field.first);
field.second->accept(this);
if (this->current_expression == NULL_TREE || this->current_expression == error_mark_node)
{
@ -1213,21 +1191,12 @@ namespace gcc
void generic_visitor::visit(boot::union_type_expression *type)
{
std::set<std::string> field_names;
tree composite_type_node = this->current_expression == NULL_TREE
? make_node(UNION_TYPE)
: this->current_expression;
for (auto& field : type->fields)
{
if (field_names.find(field.first) != field_names.cend())
{
error_at(get_location(&field.second->position()), "repeated field name");
this->current_expression = error_mark_node;
return;
}
field_names.insert(field.first);
field.second->accept(this);
if (this->current_expression == NULL_TREE || this->current_expression == error_mark_node)
{