Make array ptr and length properties constant
This commit is contained in:
@ -44,39 +44,41 @@ namespace elna::gcc
|
||||
{
|
||||
gcc_assert(TYPE_P(type));
|
||||
|
||||
if (type == elna_int_type_node)
|
||||
tree unqualified_type = get_qualified_type(type, TYPE_UNQUALIFIED);
|
||||
|
||||
if (unqualified_type == elna_int_type_node)
|
||||
{
|
||||
return "Int";
|
||||
}
|
||||
else if (type == elna_word_type_node)
|
||||
else if (unqualified_type == elna_word_type_node)
|
||||
{
|
||||
return "Word";
|
||||
}
|
||||
else if (type == elna_bool_type_node)
|
||||
else if (unqualified_type == elna_bool_type_node)
|
||||
{
|
||||
return "Bool";
|
||||
}
|
||||
else if (type == elna_byte_type_node)
|
||||
else if (unqualified_type == elna_byte_type_node)
|
||||
{
|
||||
return "Byte";
|
||||
}
|
||||
else if (type == elna_float_type_node)
|
||||
else if (unqualified_type == elna_float_type_node)
|
||||
{
|
||||
return "Float";
|
||||
}
|
||||
else if (type == elna_char_type_node)
|
||||
else if (unqualified_type == elna_char_type_node)
|
||||
{
|
||||
return "Char";
|
||||
}
|
||||
else if (type == elna_string_type_node)
|
||||
else if (unqualified_type == elna_string_type_node)
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
else if (is_void_type(type)) // For procedures without a return type.
|
||||
else if (is_void_type(unqualified_type)) // For procedures without a return type.
|
||||
{
|
||||
return "()";
|
||||
}
|
||||
else if (is_pointer_type(type))
|
||||
else if (is_pointer_type(unqualified_type))
|
||||
{
|
||||
tree pointer_target_type = TREE_TYPE(type);
|
||||
|
||||
@ -107,23 +109,25 @@ namespace elna::gcc
|
||||
}
|
||||
}
|
||||
output += ')';
|
||||
if (!is_void_type(TREE_TYPE(type)))
|
||||
tree return_type = TREE_TYPE(type);
|
||||
|
||||
if (!is_void_type(return_type))
|
||||
{
|
||||
output += " -> " + print_type(TREE_TYPE(type));
|
||||
output += " -> " + print_type(return_type);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
else if (is_array_type(type))
|
||||
else if (is_array_type(unqualified_type))
|
||||
{
|
||||
return "array";
|
||||
}
|
||||
else if (TREE_CODE(type) == RECORD_TYPE)
|
||||
{
|
||||
return print_aggregate_name(type, "record");
|
||||
return print_aggregate_name(unqualified_type, "record");
|
||||
}
|
||||
else if (TREE_CODE(type) == UNION_TYPE)
|
||||
{
|
||||
return print_aggregate_name(type, "union");
|
||||
return print_aggregate_name(unqualified_type, "union");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1046,13 +1046,14 @@ namespace elna::gcc
|
||||
|
||||
if (is_array_type(aggregate_type) && expression->field() == "length")
|
||||
{
|
||||
this->current_expression = fold_convert(elna_word_type_node,
|
||||
this->current_expression = fold_convert(build_qualified_type(elna_word_type_node, TYPE_QUAL_CONST),
|
||||
TYPE_MAX_VALUE(TYPE_DOMAIN(aggregate_type)));
|
||||
}
|
||||
else if (is_array_type(aggregate_type) && expression->field() == "ptr")
|
||||
{
|
||||
tree ptr_type = build_pointer_type_for_mode(TREE_TYPE(aggregate_type), VOIDmode, true);
|
||||
this->current_expression = build1(ADDR_EXPR, ptr_type, this->current_expression);
|
||||
this->current_expression = build1(ADDR_EXPR,
|
||||
build_qualified_type(ptr_type, TYPE_QUAL_CONST), this->current_expression);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1099,25 +1100,27 @@ namespace elna::gcc
|
||||
|
||||
if (TREE_CODE(lvalue) == CONST_DECL)
|
||||
{
|
||||
error_at(statement_location, "cannot modify constant '%s'",
|
||||
error_at(statement_location, "Cannot modify constant '%s'",
|
||||
statement->lvalue().is_variable()->name.c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
}
|
||||
else if (TYPE_READONLY(TREE_TYPE(lvalue)))
|
||||
{
|
||||
error_at(statement_location, "Cannot modify a constant expression of type '%s'",
|
||||
print_type(TREE_TYPE(lvalue)).c_str());
|
||||
}
|
||||
else if (is_assignable_from(TREE_TYPE(lvalue), rvalue))
|
||||
{
|
||||
tree assignment = build2_loc(statement_location, MODIFY_EXPR, void_type_node, lvalue, rvalue);
|
||||
|
||||
append_statement(assignment);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_at(statement_location,
|
||||
"cannot assign value of type '%s' to variable of type '%s'",
|
||||
error_at(statement_location, "Cannot assign value of type '%s' to variable of type '%s'",
|
||||
print_type(TREE_TYPE(rvalue)).c_str(),
|
||||
print_type(TREE_TYPE(lvalue)).c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
}
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::if_statement *statement)
|
||||
|
Reference in New Issue
Block a user