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 @@
# Make-lang.in -- Top level -*- makefile -*- fragment for the Elna frontend.
# 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/>.
ELNA_INSTALL_NAME := $(shell echo gelna|sed '$(program_transform_name)')
ELNA_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gelna|sed '$(program_transform_name)')

View File

@@ -1,3 +1,27 @@
# config-lang.in -- Top level configure fragment for gcc Elna frontend.
# 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/>.
# Configure looks for the existence of this file to auto-config each language.
# We define several parameters used by configure:
#
# language - name of language as it would appear in $(LANGUAGES)
# boot_language - "yes" if we need to build this language in stage1
# compilers - value to add to $(COMPILERS)
language="elna"
gcc_subdir="elna/gcc"

View File

@@ -1,3 +1,20 @@
/* elna-convert.cc -- Data type conversion routines.
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 "config.h"
#include "system.h"
#include "coretypes.h"

View File

@@ -1,3 +1,20 @@
/* elna-diagnostic.cc -- Elna frontend specific diagnostic routines.
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-diagnostic.h"
#include "elna/gcc/elna-tree.h"
@@ -12,7 +29,7 @@ namespace gcc
return linemap_position_for_column(line_table, position->column);
}
const char *print_type(tree type)
std::string print_type(tree type)
{
gcc_assert(TYPE_P(type));
@@ -38,7 +55,7 @@ namespace gcc
}
else if (is_pointer_type(type))
{
return "pointer";
return std::string("\"pointer to " + print_type(TREE_TYPE(type)) + "\"");
}
else if (TREE_CODE(type) == ARRAY_TYPE)
{

View File

@@ -1,3 +1,20 @@
/* elna-generic.cc -- Visitor generating a GENERIC tree.
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 <array>
#include "elna/gcc/elna-generic.h"
@@ -295,6 +312,7 @@ namespace gcc
tree index_constant = build_int_cstu(index_type, string->number().size());
tree element_type = this->symbol_map->lookup("Char");
tree string_type = build_array_type(element_type, build_index_type(index_constant));
tree string_record = this->symbol_map->lookup("String");
tree string_literal = build_string(string->number().size(), string->number().c_str());
TREE_TYPE(string_literal) = string_type;
@@ -302,12 +320,11 @@ namespace gcc
TREE_READONLY(string_literal) = 1;
TREE_STATIC(string_literal) = 1;
string_type = build_pointer_type(element_type);
string_type = TREE_TYPE(TREE_CHAIN(TYPE_FIELDS(string_record)));
string_literal = build4(ARRAY_REF, element_type, string_literal, integer_zero_node, NULL_TREE, NULL_TREE);
string_literal = build1(ADDR_EXPR, string_type, string_literal);
vec<constructor_elt, va_gc> *elms = NULL;
tree string_record = this->symbol_map->lookup("String");
CONSTRUCTOR_APPEND_ELT(elms, TYPE_FIELDS(string_record), index_constant);
CONSTRUCTOR_APPEND_ELT(elms, TREE_CHAIN(TYPE_FIELDS(string_record)), string_literal);
@@ -373,11 +390,11 @@ namespace gcc
}
return;
}
if (left_type != right_type && !are_compatible_pointers(left, right))
if (left_type != right_type && !are_compatible_pointers(left, right) && !are_compatible_pointers(right, left))
{
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(),
boot::print_binary_operator(expression->operation()));
this->current_expression = error_mark_node;
return;
@@ -719,7 +736,7 @@ namespace gcc
return;
}
if (TREE_TYPE(this->current_expression) == TREE_TYPE(lvalue)
|| (is_pointer_type(TREE_TYPE(lvalue)) && this->current_expression == null_pointer_node))
|| are_compatible_pointers(lvalue, this->current_expression))
{
tree assignment = build2_loc(statement_location, MODIFY_EXPR,
void_type_node, lvalue, this->current_expression);
@@ -731,8 +748,8 @@ namespace gcc
{
error_at(statement_location,
"cannot assign value of type %s to variable of type %s",
print_type(TREE_TYPE(this->current_expression)),
print_type(TREE_TYPE(lvalue)));
print_type(TREE_TYPE(this->current_expression)).c_str(),
print_type(TREE_TYPE(lvalue)).c_str());
this->current_expression = error_mark_node;
}
}
@@ -771,7 +788,7 @@ namespace gcc
{
error_at(get_location(&branch.prerequisite().position()),
"expected expression of boolean type but its type is %s",
print_type(TREE_TYPE(this->current_expression)));
print_type(TREE_TYPE(this->current_expression)).c_str());
this->current_expression = error_mark_node;
return;
}
@@ -818,7 +835,7 @@ namespace gcc
{
error_at(get_location(&statement->body().prerequisite().position()),
"expected expression of boolean type but its type is %s",
print_type(TREE_TYPE(this->current_expression)));
print_type(TREE_TYPE(this->current_expression)).c_str());
this->current_expression = error_mark_node;
return;
}

View File

@@ -1,3 +1,20 @@
/* elna-spec.c -- Specific flags and argument handling of the Elna front end.
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/>. */
void
lang_specific_driver (struct cl_decoded_option ** /* in_decoded_options */,
unsigned int * /* in_decoded_options_count */,

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;
}

View File

@@ -1,3 +1,20 @@
/* elna1.cc -- Language-dependent hooks for Elna.
Copyright (C) 2006-2024 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 "config.h"
#include "system.h"
#include "coretypes.h"

View File

@@ -1,3 +1,20 @@
/* lang-specs.h -- GCC driver specs for Elna frontend.
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/>. */
/* gcc/gcc.cc */
{".elna", "@elna", nullptr, 0, 0},
{"@elna",