Fix casting array to pointer in IR compiler
This commit is contained in:
parent
fefe741b16
commit
8fd548fb92
3 changed files with 16 additions and 0 deletions
|
|
@ -341,6 +341,13 @@ namespace pslang::ir
|
|||
|
||||
node_ref apply(ast::cast_operation const & node)
|
||||
{
|
||||
if (types::is_array_type(*get_type(*node.expression)) && types::is_pointer_type(*node.inferred_type))
|
||||
{
|
||||
if (auto result = apply_get_address(node.expression))
|
||||
return *result;
|
||||
throw std::runtime_error("Unable to cast array to pointer");
|
||||
}
|
||||
|
||||
auto arg = apply(*node.expression);
|
||||
mcontext.nodes->emplace_back(cast_operation{arg, node.inferred_type}, node.inferred_type);
|
||||
return last();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace pslang::types
|
|||
bool is_floating_point_type(type const & type);
|
||||
bool is_numeric_type(type const & type);
|
||||
bool is_builtin_type(type const & type);
|
||||
bool is_array_type(type const & type);
|
||||
bool is_function_type(type const & type);
|
||||
bool is_pointer_type(type const & type);
|
||||
|
||||
|
|
|
|||
|
|
@ -123,6 +123,14 @@ namespace pslang::types
|
|||
return false;
|
||||
}
|
||||
|
||||
bool is_array_type(type const & type)
|
||||
{
|
||||
if (std::get_if<array_type>(&type))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_function_type(type const & type)
|
||||
{
|
||||
if (std::get_if<function_type>(&type))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue