From a02e053ed23363bbec3c862b883edac3e1e2f68d Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 23 Apr 2025 09:28:58 +0200 Subject: [PATCH] Set STUB_DECL for unique types --- gcc/elna-builtins.cc | 10 +++++++--- gcc/elna-diagnostic.cc | 11 ++++++----- gcc/elna-generic.cc | 17 ++++++++++++----- gcc/elna-tree.cc | 4 ++-- include/elna/gcc/elna-tree.h | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/gcc/elna-builtins.cc b/gcc/elna-builtins.cc index 60b929c..1ea0eae 100644 --- a/gcc/elna-builtins.cc +++ b/gcc/elna-builtins.cc @@ -50,15 +50,16 @@ namespace elna::gcc } static - void declare_builtin_type(std::shared_ptr symbol_table, const char *name, tree type) + tree declare_builtin_type(std::shared_ptr symbol_table, const char *name, tree type) { tree identifier = get_identifier(name); tree type_declaration = build_decl(UNKNOWN_LOCATION, TYPE_DECL, identifier, type); TREE_PUBLIC(type_declaration) = 1; - TYPE_NAME(type_declaration) = identifier; symbol_table->enter(name, type_declaration); + + return type_declaration; } std::shared_ptr builtin_symbol_table() @@ -71,7 +72,10 @@ namespace elna::gcc declare_builtin_type(symbol_table, "Bool", elna_bool_type_node); declare_builtin_type(symbol_table, "Byte", elna_byte_type_node); declare_builtin_type(symbol_table, "Float", elna_float_type_node); - declare_builtin_type(symbol_table, "String", elna_string_type_node); + + tree string_declaration = declare_builtin_type(symbol_table, "String", elna_string_type_node); + TYPE_NAME(elna_string_type_node) = DECL_NAME(string_declaration); + TYPE_STUB_DECL(elna_string_type_node) = string_declaration; return symbol_table; } diff --git a/gcc/elna-diagnostic.cc b/gcc/elna-diagnostic.cc index ddcbf15..b30ba75 100644 --- a/gcc/elna-diagnostic.cc +++ b/gcc/elna-diagnostic.cc @@ -45,6 +45,7 @@ namespace elna::gcc gcc_assert(TYPE_P(type)); tree unqualified_type = get_qualified_type(type, TYPE_UNQUALIFIED); + tree_code code = TREE_CODE(type); if (unqualified_type == elna_int_type_node) { @@ -91,7 +92,7 @@ namespace elna::gcc return std::string("^" + print_type(pointer_target_type)); } } - else if (TREE_CODE(type) == FUNCTION_TYPE) + else if (code == FUNCTION_TYPE) { std::string output = "proc("; tree parameter_type = TYPE_ARG_TYPES(type); @@ -117,19 +118,19 @@ namespace elna::gcc } return output; } - else if (is_array_type(unqualified_type)) + else if (code == ARRAY_TYPE) { return "array"; } - else if (TREE_CODE(type) == RECORD_TYPE) + else if (code == RECORD_TYPE) { return print_aggregate_name(unqualified_type, "record"); } - else if (TREE_CODE(type) == UNION_TYPE) + else if (code == UNION_TYPE) { return print_aggregate_name(unqualified_type, "union"); } - else if (TREE_CODE(type) == ENUMERAL_TYPE) + else if (code == ENUMERAL_TYPE) { return print_aggregate_name(unqualified_type, "enumeration"); } diff --git a/gcc/elna-generic.cc b/gcc/elna-generic.cc index 3ed458d..0865ca1 100644 --- a/gcc/elna-generic.cc +++ b/gcc/elna-generic.cc @@ -862,8 +862,15 @@ namespace elna::gcc get_identifier(definition->identifier.identifier.c_str()), this->current_expression); TREE_PUBLIC(definition_tree) = definition->identifier.exported; - TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.identifier.c_str()); - + if (is_unique_type(this->current_expression)) + { + TYPE_NAME(this->current_expression) = DECL_NAME(definition_tree); + TYPE_STUB_DECL(this->current_expression) = definition_tree; + } + else + { + TYPE_NAME(this->current_expression) = definition_tree; + } auto result = this->symbols->enter(definition->identifier.identifier, definition_tree); gcc_assert(result); @@ -993,7 +1000,7 @@ namespace elna::gcc } tree offset = build2(MINUS_EXPR, elna_word_type_node, this->current_expression, size_one_node); - if (is_array_type(TREE_TYPE(designator))) + if (TREE_CODE(TREE_TYPE(designator)) == ARRAY_TYPE) { tree element_type = TREE_TYPE(TREE_TYPE(designator)); @@ -1127,12 +1134,12 @@ namespace elna::gcc location_t expression_location = get_location(&expression->position()); tree aggregate_type = TREE_TYPE(this->current_expression); - if (is_array_type(aggregate_type) && expression->field() == "length") + if (TREE_CODE(aggregate_type) == ARRAY_TYPE && expression->field() == "length") { this->current_expression = convert(build_qualified_type(elna_word_type_node, TYPE_QUAL_CONST), TYPE_MAX_VALUE(TYPE_DOMAIN(aggregate_type))); } - else if (is_array_type(aggregate_type) && expression->field() == "ptr") + else if (TREE_CODE(aggregate_type) == ARRAY_TYPE && expression->field() == "ptr") { tree ptr_type = build_global_pointer_type(TREE_TYPE(aggregate_type)); this->current_expression = build1(ADDR_EXPR, diff --git a/gcc/elna-tree.cc b/gcc/elna-tree.cc index 3767ea9..5b66da8 100644 --- a/gcc/elna-tree.cc +++ b/gcc/elna-tree.cc @@ -37,10 +37,10 @@ namespace elna::gcc return is_integral_type(type) || type == elna_float_type_node; } - bool is_array_type(tree type) + bool is_unique_type(tree type) { gcc_assert(TYPE_P(type)); - return TREE_CODE(type) == ARRAY_TYPE; + return RECORD_OR_UNION_TYPE_P(type) || TREE_CODE(type) == ENUMERAL_TYPE; } bool is_void_type(tree type) diff --git a/include/elna/gcc/elna-tree.h b/include/elna/gcc/elna-tree.h index cafe435..c6b8429 100644 --- a/include/elna/gcc/elna-tree.h +++ b/include/elna/gcc/elna-tree.h @@ -36,7 +36,7 @@ namespace elna::gcc bool is_integral_type(tree type); bool is_numeric_type(tree type); - bool is_array_type(tree type); + bool is_unique_type(tree type); bool is_void_type(tree type); /**