Set STUB_DECL for unique types

This commit is contained in:
Eugen Wissner 2025-04-23 09:28:58 +02:00
parent 09ad85b058
commit a02e053ed2
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
5 changed files with 28 additions and 16 deletions

View File

@ -50,15 +50,16 @@ namespace elna::gcc
} }
static static
void declare_builtin_type(std::shared_ptr<symbol_table> symbol_table, const char *name, tree type) tree declare_builtin_type(std::shared_ptr<symbol_table> symbol_table, const char *name, tree type)
{ {
tree identifier = get_identifier(name); tree identifier = get_identifier(name);
tree type_declaration = build_decl(UNKNOWN_LOCATION, TYPE_DECL, identifier, type); tree type_declaration = build_decl(UNKNOWN_LOCATION, TYPE_DECL, identifier, type);
TREE_PUBLIC(type_declaration) = 1; TREE_PUBLIC(type_declaration) = 1;
TYPE_NAME(type_declaration) = identifier;
symbol_table->enter(name, type_declaration); symbol_table->enter(name, type_declaration);
return type_declaration;
} }
std::shared_ptr<symbol_table> builtin_symbol_table() std::shared_ptr<symbol_table> 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, "Bool", elna_bool_type_node);
declare_builtin_type(symbol_table, "Byte", elna_byte_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, "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; return symbol_table;
} }

View File

@ -45,6 +45,7 @@ namespace elna::gcc
gcc_assert(TYPE_P(type)); gcc_assert(TYPE_P(type));
tree unqualified_type = get_qualified_type(type, TYPE_UNQUALIFIED); tree unqualified_type = get_qualified_type(type, TYPE_UNQUALIFIED);
tree_code code = TREE_CODE(type);
if (unqualified_type == elna_int_type_node) if (unqualified_type == elna_int_type_node)
{ {
@ -91,7 +92,7 @@ namespace elna::gcc
return std::string("^" + print_type(pointer_target_type)); return std::string("^" + print_type(pointer_target_type));
} }
} }
else if (TREE_CODE(type) == FUNCTION_TYPE) else if (code == FUNCTION_TYPE)
{ {
std::string output = "proc("; std::string output = "proc(";
tree parameter_type = TYPE_ARG_TYPES(type); tree parameter_type = TYPE_ARG_TYPES(type);
@ -117,19 +118,19 @@ namespace elna::gcc
} }
return output; return output;
} }
else if (is_array_type(unqualified_type)) else if (code == ARRAY_TYPE)
{ {
return "array"; return "array";
} }
else if (TREE_CODE(type) == RECORD_TYPE) else if (code == RECORD_TYPE)
{ {
return print_aggregate_name(unqualified_type, "record"); 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"); 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"); return print_aggregate_name(unqualified_type, "enumeration");
} }

View File

@ -862,8 +862,15 @@ namespace elna::gcc
get_identifier(definition->identifier.identifier.c_str()), this->current_expression); get_identifier(definition->identifier.identifier.c_str()), this->current_expression);
TREE_PUBLIC(definition_tree) = definition->identifier.exported; 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); auto result = this->symbols->enter(definition->identifier.identifier, definition_tree);
gcc_assert(result); 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); 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)); tree element_type = TREE_TYPE(TREE_TYPE(designator));
@ -1127,12 +1134,12 @@ namespace elna::gcc
location_t expression_location = get_location(&expression->position()); location_t expression_location = get_location(&expression->position());
tree aggregate_type = TREE_TYPE(this->current_expression); 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), this->current_expression = convert(build_qualified_type(elna_word_type_node, TYPE_QUAL_CONST),
TYPE_MAX_VALUE(TYPE_DOMAIN(aggregate_type))); 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)); tree ptr_type = build_global_pointer_type(TREE_TYPE(aggregate_type));
this->current_expression = build1(ADDR_EXPR, this->current_expression = build1(ADDR_EXPR,

View File

@ -37,10 +37,10 @@ namespace elna::gcc
return is_integral_type(type) || type == elna_float_type_node; 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)); 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) bool is_void_type(tree type)

View File

@ -36,7 +36,7 @@ namespace elna::gcc
bool is_integral_type(tree type); bool is_integral_type(tree type);
bool is_numeric_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); bool is_void_type(tree type);
/** /**