1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Manually fix, merge and close #15168

This commit is contained in:
Juan Linietsky
2018-07-29 12:17:45 -03:00
parent b62586c9f9
commit d2aaf460fb
2 changed files with 47 additions and 13 deletions

View File

@@ -2306,25 +2306,55 @@ bool ShaderLanguage::_is_operator_assign(Operator p_op) const {
return false; return false;
} }
bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types) { bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message) {
if (p_node->type == Node::TYPE_OPERATOR) { if (p_node->type == Node::TYPE_OPERATOR) {
OperatorNode *op = static_cast<OperatorNode *>(p_node); OperatorNode *op = static_cast<OperatorNode *>(p_node);
if (op->op == OP_INDEX) { if (op->op == OP_INDEX) {
return _validate_assign(op->arguments[0], p_builtin_types); return _validate_assign(op->arguments[0], p_builtin_types, r_message);
}
} else if (_is_operator_assign(op->op)) {
//chained assignment
return _validate_assign(op->arguments[1], p_builtin_types, r_message);
} else if (op->op == OP_CALL) {
if (r_message)
*r_message = RTR("Assignment to function.");
return false;
} }
if (p_node->type == Node::TYPE_VARIABLE) { } else if (p_node->type == Node::TYPE_MEMBER) {
MemberNode *member = static_cast<MemberNode *>(p_node);
return _validate_assign(member->owner, p_builtin_types, r_message);
} else if (p_node->type == Node::TYPE_VARIABLE) {
VariableNode *var = static_cast<VariableNode *>(p_node); VariableNode *var = static_cast<VariableNode *>(p_node);
if (p_builtin_types.has(var->name) && p_builtin_types[var->name].constant) {
return false; //ops not valid if (shader->uniforms.has(var->name)) {
if (r_message)
*r_message = RTR("Assignment to uniform.");
return false;
} }
if (shader->varyings.has(var->name) && current_function != String("vertex")) {
if (r_message)
*r_message = RTR("Varyings can only be assigned in vertex function.");
return false;
} }
if (!(p_builtin_types.has(var->name) && p_builtin_types[var->name].constant)) {
return true; return true;
} }
}
if (r_message)
*r_message = "Assignment to constant expression.";
return false;
}
ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) { ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) {
@@ -3090,11 +3120,15 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
ERR_FAIL_V(NULL); ERR_FAIL_V(NULL);
} }
if (_is_operator_assign(op->op) && !_validate_assign(expression[next_op - 1].node, p_builtin_types)) { if (_is_operator_assign(op->op)) {
_set_error("Assignment to constant expression."); String assign_message;
if (!_validate_assign(expression[next_op - 1].node, p_builtin_types, &assign_message)) {
_set_error(assign_message);
return NULL; return NULL;
} }
}
if (expression[next_op + 1].is_op) { if (expression[next_op + 1].is_op) {
// this is not invalid and can really appear // this is not invalid and can really appear

View File

@@ -617,7 +617,7 @@ private:
bool _find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL); bool _find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type = NULL, IdentifierType *r_type = NULL);
bool _is_operator_assign(Operator p_op) const; bool _is_operator_assign(Operator p_op) const;
bool _validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types); bool _validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message = NULL);
bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = NULL); bool _validate_operator(OperatorNode *p_op, DataType *r_ret_type = NULL);