Implement case statements

This commit is contained in:
2025-04-10 23:55:56 +02:00
parent 18c4e79012
commit f68667d5e5
10 changed files with 135 additions and 94 deletions

View File

@ -37,14 +37,6 @@ namespace elna::gcc
return is_integral_type(type) || type == elna_float_type_node;
}
bool is_primitive_type(tree type)
{
gcc_assert(TYPE_P(type));
return TREE_CODE(type) == INTEGER_TYPE
|| type == elna_float_type_node
|| type == elna_bool_type_node;
}
bool is_array_type(tree type)
{
gcc_assert(TYPE_P(type));
@ -59,9 +51,7 @@ namespace elna::gcc
bool is_castable_type(tree type)
{
gcc_assert(TYPE_P(type));
auto code = TREE_CODE(type);
return is_primitive_type(type) || POINTER_TYPE_P(type) || code == ENUMERAL_TYPE;
return INTEGRAL_TYPE_P(type) || POINTER_TYPE_P(type) || TREE_CODE(type) == REAL_TYPE;
}
bool are_compatible_pointers(tree lhs_type, tree rhs)
@ -139,7 +129,8 @@ namespace elna::gcc
return field_declaration;
}
tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right)
tree do_pointer_arithmetic(boot::binary_operator binary_operator,
tree left, tree right, location_t operation_location)
{
tree left_type = get_qualified_type(TREE_TYPE(left), TYPE_UNQUALIFIED);
tree right_type = get_qualified_type(TREE_TYPE(right), TYPE_UNQUALIFIED);
@ -167,7 +158,7 @@ namespace elna::gcc
offset = fold_build2(MULT_EXPR, TREE_TYPE(offset), offset, size_exp);
offset = fold_convert(sizetype, offset);
return fold_build2(POINTER_PLUS_EXPR, TREE_TYPE(pointer), pointer, offset);
return fold_build2_loc(operation_location, POINTER_PLUS_EXPR, TREE_TYPE(pointer), pointer, offset);
}
else if (binary_operator == boot::binary_operator::subtraction)
{
@ -181,11 +172,11 @@ namespace elna::gcc
convert_expression = fold_convert(sizetype, convert_expression);
convert_expression = fold_build1(NEGATE_EXPR, sizetype, convert_expression);
return fold_build2(POINTER_PLUS_EXPR, pointer_type, left, convert_expression);
return fold_build2_loc(operation_location, POINTER_PLUS_EXPR, pointer_type, left, convert_expression);
}
else if (POINTER_TYPE_P(left_type) && POINTER_TYPE_P(right_type) && left_type == right_type)
{
return fold_build2(POINTER_DIFF_EXPR, ssizetype, left, right);
return fold_build2_loc(operation_location, POINTER_DIFF_EXPR, ssizetype, left, right);
}
}
gcc_unreachable();
@ -200,7 +191,7 @@ namespace elna::gcc
if (condition)
{
return build2_loc(expression_location, operator_code, target_type, left, right);
return fold_build2_loc(expression_location, operator_code, target_type, left, right);
}
else
{