Check only a pointer can be dereferenced

This commit is contained in:
Eugen Wissner 2025-03-23 10:14:04 +01:00
parent 07ed40cc24
commit 6ccb195c09
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 45 additions and 33 deletions

View File

@ -71,35 +71,6 @@ namespace elna::boot
return nullptr; return nullptr;
} }
void statement::accept(parser_visitor *visitor)
{
if (assign_statement *node = is_assign())
{
return node->accept(visitor);
}
else if (if_statement *node = is_if())
{
return node->accept(visitor);
}
else if (while_statement *node = is_while())
{
return node->accept(visitor);
}
else if (return_statement *node = is_return())
{
return node->accept(visitor);
}
else if (defer_statement *node = is_defer())
{
return node->accept(visitor);
}
else if (procedure_call *node = is_call_statement())
{
return node->accept(visitor);
}
__builtin_unreachable();
}
expression::expression() expression::expression()
{ {
} }

View File

@ -1071,9 +1071,20 @@ namespace elna::gcc
void generic_visitor::visit(boot::dereference_expression *expression) void generic_visitor::visit(boot::dereference_expression *expression)
{ {
expression->base().accept(this); expression->base().accept(this);
location_t expression_location = get_location(&expression->position());
tree expression_type = TREE_TYPE(this->current_expression);
this->current_expression = build1_loc(get_location(&expression->position()), INDIRECT_REF, if (is_pointer_type(expression_type))
TREE_TYPE(TREE_TYPE(this->current_expression)), this->current_expression); {
this->current_expression = build1_loc(expression_location, INDIRECT_REF,
TREE_TYPE(expression_type), this->current_expression);
}
else
{
error_at(expression_location, "Type '%s' cannot be dereferenced, it is not a pointer",
print_type(expression_type).c_str());
this->current_expression = error_mark_node;
}
} }
void generic_visitor::visit(boot::assign_statement *statement) void generic_visitor::visit(boot::assign_statement *statement)

View File

@ -156,7 +156,36 @@ namespace elna::boot
virtual defer_statement *is_defer(); virtual defer_statement *is_defer();
virtual procedure_call *is_call_statement(); virtual procedure_call *is_call_statement();
void accept(parser_visitor *visitor); template<typename V>
void accept(V *visitor)
{
if (assign_statement *node = is_assign())
{
return visitor->visit(node);
}
else if (if_statement *node = is_if())
{
return visitor->visit(node);
}
else if (while_statement *node = is_while())
{
return visitor->visit(node);
}
else if (return_statement *node = is_return())
{
return visitor->visit(node);
}
else if (defer_statement *node = is_defer())
{
return visitor->visit(node);
}
else if (procedure_call *node = is_call_statement())
{
return visitor->visit(node);
}
__builtin_unreachable();
}
~statement() = 0; ~statement() = 0;
protected: protected:
@ -739,7 +768,8 @@ namespace elna::boot
} }
} }
void accept(parser_visitor *visitor) template<typename V>
void accept(V *visitor)
{ {
visitor->visit(this); visitor->visit(this);
} }