Implements length() shader function for arrays in structs

This commit is contained in:
Yuri Roubinsky 2021-05-19 21:50:11 +03:00
parent f1f5b92b8e
commit 6135744786
3 changed files with 13 additions and 2 deletions

View file

@ -1280,6 +1280,9 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
} else if (mnode->assign_expression != nullptr) {
code += "=";
code += _dump_node_code(mnode->assign_expression, p_level, r_gen_code, p_actions, p_default_actions, true, false);
} else if (mnode->call_expression != nullptr) {
code += ".";
code += _dump_node_code(mnode->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning, false);
}
} break;
}

View file

@ -4301,8 +4301,15 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
}
mn->assign_expression = assign_expression;
} else if (tk.type == TK_PERIOD) {
_set_error("Nested array length() is not yet implemented");
return nullptr;
completion_class = TAG_ARRAY;
p_block->block_tag = SubClassTag::TAG_ARRAY;
Node *call_expression = _parse_and_reduce_expression(p_block, p_function_info);
p_block->block_tag = SubClassTag::TAG_GLOBAL;
if (!call_expression) {
return nullptr;
}
mn->datatype = call_expression->get_datatype();
mn->call_expression = call_expression;
} else if (tk.type == TK_BRACKET_OPEN) {
Node *index_expression = _parse_and_reduce_expression(p_block, p_function_info);
if (!index_expression) {

View file

@ -546,6 +546,7 @@ public:
Node *owner = nullptr;
Node *index_expression = nullptr;
Node *assign_expression = nullptr;
Node *call_expression = nullptr;
bool has_swizzling_duplicates = false;
virtual DataType get_datatype() const { return datatype; }