Skip parameter names in procedure type expressions

This commit is contained in:
2025-03-18 11:37:10 +01:00
parent 6eb4e91b2c
commit 5e8555b4f4
20 changed files with 469 additions and 490 deletions

View File

@ -24,9 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include "fold-const.h"
#include "diagnostic-core.h"
namespace elna
{
namespace gcc
namespace elna::gcc
{
bool is_pointer_type(tree type)
{
@ -209,5 +207,37 @@ namespace gcc
return error_mark_node;
}
}
}
tree find_field_by_name(location_t expression_location, tree type, const std::string& field_name)
{
if (type == error_mark_node)
{
return type;
}
tree field_declaration = TYPE_FIELDS(type);
if (!is_aggregate_type(type))
{
error_at(expression_location, "type '%s' does not have a field named '%s'",
print_type(type).c_str(), field_name.c_str());
return error_mark_node;
}
while (field_declaration != NULL_TREE)
{
tree declaration_name = DECL_NAME(field_declaration);
const char *identifier_pointer = IDENTIFIER_POINTER(declaration_name);
if (field_name == identifier_pointer)
{
break;
}
field_declaration = TREE_CHAIN(field_declaration);
}
if (field_declaration == NULL_TREE)
{
error_at(expression_location, "record type does not have a field named '%s'", field_name.c_str());
return error_mark_node;
}
return field_declaration;
}
}