Implement enumeration type
This commit is contained in:
@ -26,12 +26,6 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
namespace elna::gcc
|
||||
{
|
||||
bool is_pointer_type(tree type)
|
||||
{
|
||||
gcc_assert(TYPE_P(type));
|
||||
return TREE_CODE(type) == POINTER_TYPE;
|
||||
}
|
||||
|
||||
bool is_integral_type(tree type)
|
||||
{
|
||||
gcc_assert(TYPE_P(type));
|
||||
@ -62,10 +56,12 @@ namespace elna::gcc
|
||||
return type == NULL_TREE || type == void_type_node;
|
||||
}
|
||||
|
||||
bool is_aggregate_type(tree type)
|
||||
bool is_castable_type(tree type)
|
||||
{
|
||||
gcc_assert(TYPE_P(type));
|
||||
return TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE;
|
||||
auto code = TREE_CODE(type);
|
||||
|
||||
return is_primitive_type(type) || POINTER_TYPE_P(type) || code == ENUMERAL_TYPE;
|
||||
}
|
||||
|
||||
bool are_compatible_pointers(tree lhs_type, tree rhs)
|
||||
@ -73,8 +69,8 @@ namespace elna::gcc
|
||||
gcc_assert(TYPE_P(lhs_type));
|
||||
tree rhs_type = TREE_TYPE(rhs);
|
||||
|
||||
return (is_pointer_type(lhs_type) && rhs == elna_pointer_nil_node)
|
||||
|| (is_pointer_type(lhs_type) && lhs_type == rhs_type);
|
||||
return (POINTER_TYPE_P(lhs_type) && rhs == elna_pointer_nil_node)
|
||||
|| (POINTER_TYPE_P(lhs_type) && lhs_type == rhs_type);
|
||||
}
|
||||
|
||||
tree prepare_rvalue(tree rvalue)
|
||||
@ -152,12 +148,12 @@ namespace elna::gcc
|
||||
tree pointer{ NULL_TREE };
|
||||
tree offset{ NULL_TREE };
|
||||
|
||||
if (is_pointer_type(left_type) && is_integral_type(right_type))
|
||||
if (POINTER_TYPE_P(left_type) && is_integral_type(right_type))
|
||||
{
|
||||
pointer = left;
|
||||
offset = right;
|
||||
}
|
||||
else if (is_integral_type(left_type) && is_pointer_type(right_type))
|
||||
else if (is_integral_type(left_type) && POINTER_TYPE_P(right_type))
|
||||
{
|
||||
pointer = right;
|
||||
offset = left;
|
||||
@ -175,7 +171,7 @@ namespace elna::gcc
|
||||
}
|
||||
else if (binary_operator == boot::binary_operator::subtraction)
|
||||
{
|
||||
if (is_pointer_type(left_type) && is_integral_type(right_type))
|
||||
if (POINTER_TYPE_P(left_type) && is_integral_type(right_type))
|
||||
{
|
||||
tree pointer_type = left_type;
|
||||
tree offset_type = right_type;
|
||||
@ -187,7 +183,7 @@ namespace elna::gcc
|
||||
convert_expression = fold_build1(NEGATE_EXPR, sizetype, convert_expression);
|
||||
return fold_build2(POINTER_PLUS_EXPR, pointer_type, left, convert_expression);
|
||||
}
|
||||
else if (is_pointer_type(left_type) && is_pointer_type(right_type) && left_type == right_type)
|
||||
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);
|
||||
}
|
||||
@ -224,9 +220,9 @@ namespace elna::gcc
|
||||
}
|
||||
tree field_declaration = TYPE_FIELDS(type);
|
||||
|
||||
if (!is_aggregate_type(type))
|
||||
if (!RECORD_OR_UNION_TYPE_P(type))
|
||||
{
|
||||
error_at(expression_location, "type '%s' does not have a field named '%s'",
|
||||
error_at(expression_location, "Type '%s' does not have a field named '%s'",
|
||||
print_type(type).c_str(), field_name.c_str());
|
||||
return error_mark_node;
|
||||
}
|
||||
@ -243,7 +239,7 @@ namespace elna::gcc
|
||||
}
|
||||
if (field_declaration == NULL_TREE)
|
||||
{
|
||||
error_at(expression_location, "record type does not have a field named '%s'", field_name.c_str());
|
||||
error_at(expression_location, "Aggregate type does not have a field '%s'", field_name.c_str());
|
||||
return error_mark_node;
|
||||
}
|
||||
return field_declaration;
|
||||
@ -253,4 +249,13 @@ namespace elna::gcc
|
||||
{
|
||||
return build_pointer_type_for_mode(type, VOIDmode, true);
|
||||
}
|
||||
|
||||
tree build_label_decl(const char *name, location_t loc)
|
||||
{
|
||||
auto label_decl = build_decl(loc, LABEL_DECL, get_identifier(name), void_type_node);
|
||||
|
||||
DECL_CONTEXT(label_decl) = current_function_decl;
|
||||
|
||||
return label_decl;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user