Allow multiple variable declarations with a single type
This commit is contained in:
@ -43,9 +43,9 @@ namespace gcc
|
||||
tree string_ptr_type = build_pointer_type_for_mode(elna_char_type_node, VOIDmode, true);
|
||||
|
||||
elna_string_length_field_node = build_field(UNKNOWN_LOCATION,
|
||||
elna_string_type_node, "length", elna_word_type_node);
|
||||
elna_string_type_node, "length", build_qualified_type(elna_word_type_node, TYPE_QUAL_CONST));
|
||||
elna_string_ptr_field_node = build_field(UNKNOWN_LOCATION,
|
||||
elna_string_type_node, "ptr", string_ptr_type);
|
||||
elna_string_type_node, "ptr", build_qualified_type(string_ptr_type, TYPE_QUAL_CONST));
|
||||
|
||||
TYPE_FIELDS(elna_string_type_node) = chainon(elna_string_ptr_field_node, elna_string_length_field_node);
|
||||
layout_type(elna_string_type_node);
|
||||
|
@ -108,7 +108,8 @@ namespace gcc
|
||||
break;
|
||||
}
|
||||
argument->accept(this);
|
||||
if (!is_assignable_from(TREE_TYPE(record_fields), this->current_expression))
|
||||
tree unqualified_field = get_qualified_type(TREE_TYPE(record_fields), TYPE_UNQUALIFIED);
|
||||
if (!is_assignable_from(unqualified_field, this->current_expression))
|
||||
{
|
||||
error_at(argument_location,
|
||||
"cannot assign value of type '%s' to variable of type '%s'",
|
||||
@ -548,11 +549,11 @@ namespace gcc
|
||||
{
|
||||
expression->lhs().accept(this);
|
||||
tree left = this->current_expression;
|
||||
tree left_type = TREE_TYPE(left);
|
||||
tree left_type = get_qualified_type(TREE_TYPE(left), TYPE_UNQUALIFIED);
|
||||
|
||||
expression->rhs().accept(this);
|
||||
tree right = this->current_expression;
|
||||
tree right_type = TREE_TYPE(right);
|
||||
tree right_type = get_qualified_type(TREE_TYPE(right), TYPE_UNQUALIFIED);
|
||||
|
||||
location_t expression_location = get_location(&expression->position());
|
||||
|
||||
@ -1012,9 +1013,8 @@ namespace gcc
|
||||
error_at(statement_location, "cannot modify constant '%s'",
|
||||
statement->lvalue().is_variable()->name().c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
}
|
||||
if (is_assignable_from(TREE_TYPE(lvalue), this->current_expression))
|
||||
else if (is_assignable_from(TREE_TYPE(lvalue), this->current_expression))
|
||||
{
|
||||
tree assignment = build2_loc(statement_location, MODIFY_EXPR,
|
||||
void_type_node, lvalue, this->current_expression);
|
||||
|
@ -79,7 +79,7 @@ namespace gcc
|
||||
|
||||
bool is_assignable_from(tree assignee, tree assignment)
|
||||
{
|
||||
return TREE_TYPE(assignment) == assignee
|
||||
return get_qualified_type(TREE_TYPE(assignment), TYPE_UNQUALIFIED) == assignee
|
||||
|| are_compatible_pointers(assignee, assignment);
|
||||
}
|
||||
|
||||
@ -133,17 +133,19 @@ namespace gcc
|
||||
|
||||
tree do_pointer_arithmetic(boot::binary_operator binary_operator, tree left, tree right)
|
||||
{
|
||||
tree left_type = get_qualified_type(TREE_TYPE(left), TYPE_UNQUALIFIED);
|
||||
tree right_type = get_qualified_type(TREE_TYPE(right), TYPE_UNQUALIFIED);
|
||||
if (binary_operator == boot::binary_operator::sum)
|
||||
{
|
||||
tree pointer{ NULL_TREE };
|
||||
tree offset{ NULL_TREE };
|
||||
|
||||
if (is_pointer_type(TREE_TYPE(left)) && is_integral_type(TREE_TYPE(right)))
|
||||
if (is_pointer_type(left_type) && is_integral_type(right_type))
|
||||
{
|
||||
pointer = left;
|
||||
offset = right;
|
||||
}
|
||||
else if (is_integral_type(TREE_TYPE(left)) && is_pointer_type(TREE_TYPE(right)))
|
||||
else if (is_integral_type(left_type) && is_pointer_type(right_type))
|
||||
{
|
||||
pointer = right;
|
||||
offset = left;
|
||||
@ -161,10 +163,10 @@ namespace gcc
|
||||
}
|
||||
else if (binary_operator == boot::binary_operator::subtraction)
|
||||
{
|
||||
if (is_pointer_type(TREE_TYPE(left)) && is_integral_type(TREE_TYPE(right)))
|
||||
if (is_pointer_type(left_type) && is_integral_type(right_type))
|
||||
{
|
||||
tree pointer_type = TREE_TYPE(left);
|
||||
tree offset_type = TREE_TYPE(right);
|
||||
tree pointer_type = left_type;
|
||||
tree offset_type = right_type;
|
||||
tree size_exp = fold_convert(offset_type, size_in_bytes(TREE_TYPE(pointer_type)));
|
||||
|
||||
tree convert_expression = fold_build2(MULT_EXPR, offset_type, right, size_exp);
|
||||
@ -172,8 +174,8 @@ namespace 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(TREE_TYPE(left)) && is_pointer_type(TREE_TYPE(right))
|
||||
&& TREE_TYPE(left) == TREE_TYPE(right))
|
||||
}
|
||||
else if (is_pointer_type(left_type) && is_pointer_type(right_type) && left_type == right_type)
|
||||
{
|
||||
return fold_build2(POINTER_DIFF_EXPR, ssizetype, left, right);
|
||||
}
|
||||
@ -185,8 +187,8 @@ namespace gcc
|
||||
tree_code operator_code, tree left, tree right, tree target_type)
|
||||
{
|
||||
location_t expression_location = get_location(&expression->position());
|
||||
tree left_type = TREE_TYPE(left);
|
||||
tree right_type = TREE_TYPE(right);
|
||||
tree left_type = get_qualified_type(TREE_TYPE(left), TYPE_UNQUALIFIED);
|
||||
tree right_type = get_qualified_type(TREE_TYPE(right), TYPE_UNQUALIFIED);
|
||||
|
||||
if (condition)
|
||||
{
|
||||
|
Reference in New Issue
Block a user