Make string and char pointers comparable

This commit is contained in:
2025-02-08 23:02:27 +01:00
parent 8a0f282714
commit d88bd652a4
15 changed files with 425 additions and 123 deletions

View File

@ -1,3 +1,20 @@
/* elna-tree.cc -- Utilities to manipulate GCC trees.
Copyright (C) 2025 Free Software Foundation, Inc.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "elna/gcc/elna-tree.h"
#include "elna/gcc/elna-diagnostic.h"
@ -24,8 +41,11 @@ namespace gcc
bool are_compatible_pointers(tree lhs, tree rhs)
{
return (lhs == null_pointer_node || rhs == null_pointer_node)
&& is_pointer_type(TREE_TYPE(lhs)) && is_pointer_type(TREE_TYPE(rhs));
tree lhs_type = TREE_TYPE(lhs);
tree rhs_type = TREE_TYPE(rhs);
return (is_pointer_type(lhs_type) && rhs == null_pointer_node)
|| (is_pointer_type(lhs_type) && lhs_type == rhs_type);
}
tree tree_chain_base::head()
@ -141,7 +161,7 @@ namespace gcc
record_chain.append(build_field(UNKNOWN_LOCATION, string_record, "length", initial_table->lookup("Word")));
record_chain.append(build_field(UNKNOWN_LOCATION, string_record, "ptr",
build_pointer_type(initial_table->lookup("Char"))));
build_pointer_type_for_mode(initial_table->lookup("Char"), VOIDmode, true)));
TYPE_FIELDS(string_record) = record_chain.head();
layout_type(string_record);
@ -216,7 +236,7 @@ namespace gcc
{
error_at(expression_location,
"invalid operands of type %s and %s for operator %s",
print_type(left_type), print_type(right_type),
print_type(left_type).c_str(), print_type(right_type).c_str(),
elna::boot::print_binary_operator(expression->operation()));
return error_mark_node;
}