End while and if statements with the end token

This commit is contained in:
2025-01-17 10:11:40 +01:00
parent ef667e3ace
commit a79def50e5
10 changed files with 197 additions and 99 deletions

View File

@ -15,9 +15,9 @@ namespace elna
{
namespace gcc
{
generic_visitor::generic_visitor()
generic_visitor::generic_visitor(std::shared_ptr<source::symbol_table<tree>> symbol_table)
{
this->symbol_map = std::make_shared<source::symbol_table<tree>>();
this->symbol_map = symbol_table;
}
void generic_visitor::visit(source::call_statement *statement)
@ -270,7 +270,7 @@ namespace gcc
this->current_expression = build_string_literal(string->string().size() + 1, string->string().c_str());
}
void generic_visitor::build_binarary_operation(bool condition, source::binary_expression *expression,
void generic_visitor::build_binary_operation(bool condition, source::binary_expression *expression,
tree_code operator_code, tree left, tree right, tree target_type)
{
auto expression_location = get_location(&expression->position());
@ -354,7 +354,7 @@ namespace gcc
}
if (operator_code != ERROR_MARK) // An arithmetic operation.
{
build_binarary_operation(left_type == integer_type_node || left_type == double_type_node,
build_binary_operation(left_type == integer_type_node || left_type == double_type_node,
expression, operator_code, left, right, target_type);
return;
}
@ -373,7 +373,7 @@ namespace gcc
}
if (operator_code != ERROR_MARK) // A logical operation.
{
build_binarary_operation(left_type == boolean_type_node,
build_binary_operation(left_type == boolean_type_node,
expression, operator_code, left, right, target_type);
return;
}
@ -538,7 +538,7 @@ namespace gcc
tree record_type_node = make_node(RECORD_TYPE);
tree_chain record_chain;
for (auto& field : record_type->fields())
for (auto& field : record_type->fields)
{
if (field_names.find(field.first) != field_names.cend())
{
@ -564,6 +564,38 @@ namespace gcc
return record_type_node;
}
else if (source::union_type_expression *union_type = type.is_union())
{
std::set<std::string> field_names;
tree union_type_node = make_node(UNION_TYPE);
tree_chain union_chain;
for (auto& field : union_type->fields)
{
if (field_names.find(field.first) != field_names.cend())
{
error_at(get_location(&field.second->position()), "repeated field name");
return error_mark_node;
}
field_names.insert(field.first);
tree field_type = build_type(*field.second);
if (field_type == NULL_TREE || field_type == error_mark_node)
{
return field_type;
}
tree field_declaration = build_decl(get_location(&field.second->position()),
FIELD_DECL, get_identifier(field.first.c_str()), field_type);
TREE_ADDRESSABLE(field_declaration) = 1;
DECL_CONTEXT(field_declaration) = union_type_node;
union_chain.append(field_declaration);
}
TYPE_FIELDS(union_type_node) = union_chain.head();
layout_type(union_type_node);
return union_type_node;
}
return NULL_TREE;
}