Provide record initialization syntax

This commit is contained in:
2025-02-13 22:54:47 +01:00
parent 62d9398772
commit 7c3257a42f
7 changed files with 106 additions and 44 deletions

View File

@ -79,6 +79,18 @@ namespace gcc
this->current_expression = stmt;
}
}
else if (TYPE_P(symbol) && is_record_type(symbol))
{
vec<constructor_elt, va_gc> *arguments = NULL;
tree record_fields = TYPE_FIELDS(symbol);
for (std::size_t i = 0; i < expression->arguments().size(); ++i)
{
expression->arguments().at(i)->accept(this);
CONSTRUCTOR_APPEND_ELT(arguments, record_fields, this->current_expression);
record_fields = TREE_CHAIN(record_fields);
}
this->current_expression = build_constructor(symbol, arguments);
}
else
{
error_at(call_location, "'%s' cannot be called, it is neither a procedure nor record",

View File

@ -62,6 +62,11 @@ namespace gcc
return type == NULL_TREE || type == void_type_node;
}
bool is_record_type(tree type)
{
return TREE_CODE(type) == RECORD_TYPE;
}
bool are_compatible_pointers(tree lhs, tree rhs)
{
tree lhs_type = TREE_TYPE(lhs);