You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
@@ -521,31 +521,38 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
||||
|
||||
while (true) {
|
||||
if (GETCHAR(i) == '.') {
|
||||
if (period_found || exponent_found || hexa_found || float_suffix_found)
|
||||
if (period_found || exponent_found || hexa_found || float_suffix_found) {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
period_found = true;
|
||||
} else if (GETCHAR(i) == 'x') {
|
||||
if (hexa_found || str.length() != 1 || str[0] != '0')
|
||||
if (hexa_found || str.length() != 1 || str[0] != '0') {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
hexa_found = true;
|
||||
} else if (GETCHAR(i) == 'e' && !hexa_found) {
|
||||
if (exponent_found || float_suffix_found)
|
||||
if (exponent_found || float_suffix_found) {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
exponent_found = true;
|
||||
} else if (GETCHAR(i) == 'f' && !hexa_found) {
|
||||
if (exponent_found)
|
||||
if (exponent_found) {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
float_suffix_found = true;
|
||||
} else if (_is_number(GETCHAR(i))) {
|
||||
if (float_suffix_found)
|
||||
if (float_suffix_found) {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
} else if (hexa_found && _is_hex(GETCHAR(i))) {
|
||||
} else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
|
||||
if (sign_found)
|
||||
if (sign_found) {
|
||||
return _make_token(TK_ERROR, "Invalid numeric constant");
|
||||
}
|
||||
sign_found = true;
|
||||
} else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
str += CharType(GETCHAR(i));
|
||||
i++;
|
||||
@@ -601,10 +608,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
||||
|
||||
char_idx += str.length();
|
||||
Token tk;
|
||||
if (period_found || exponent_found || float_suffix_found)
|
||||
if (period_found || exponent_found || float_suffix_found) {
|
||||
tk.type = TK_REAL_CONSTANT;
|
||||
else
|
||||
} else {
|
||||
tk.type = TK_INT_CONSTANT;
|
||||
}
|
||||
|
||||
if (hexa_found) {
|
||||
tk.constant = (double)str.hex_to_int64(true);
|
||||
@@ -647,10 +655,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
|
||||
return _make_token(TK_IDENTIFIER, str);
|
||||
}
|
||||
|
||||
if (GETCHAR(0) > 32)
|
||||
if (GETCHAR(0) > 32) {
|
||||
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)) + ": '" + String::chr(GETCHAR(0)) + "'");
|
||||
else
|
||||
} else {
|
||||
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)));
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
@@ -747,10 +756,11 @@ bool ShaderLanguage::is_token_interpolation(TokenType p_type) {
|
||||
}
|
||||
|
||||
ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) {
|
||||
if (p_type == TK_INTERPOLATION_FLAT)
|
||||
if (p_type == TK_INTERPOLATION_FLAT) {
|
||||
return INTERPOLATION_FLAT;
|
||||
else
|
||||
} else {
|
||||
return INTERPOLATION_SMOOTH;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShaderLanguage::is_token_precision(TokenType p_type) {
|
||||
@@ -761,12 +771,13 @@ bool ShaderLanguage::is_token_precision(TokenType p_type) {
|
||||
}
|
||||
|
||||
ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) {
|
||||
if (p_type == TK_PRECISION_LOW)
|
||||
if (p_type == TK_PRECISION_LOW) {
|
||||
return PRECISION_LOWP;
|
||||
else if (p_type == TK_PRECISION_HIGH)
|
||||
} else if (p_type == TK_PRECISION_HIGH) {
|
||||
return PRECISION_HIGHP;
|
||||
else
|
||||
} else {
|
||||
return PRECISION_MEDIUMP;
|
||||
}
|
||||
}
|
||||
|
||||
String ShaderLanguage::get_precision_name(DataPrecision p_type) {
|
||||
@@ -969,8 +980,9 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<String
|
||||
}
|
||||
|
||||
for (int i = 0; i < shader->functions.size(); i++) {
|
||||
if (!shader->functions[i].callable)
|
||||
if (!shader->functions[i].callable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shader->functions[i].name == p_identifier) {
|
||||
if (r_data_type) {
|
||||
@@ -1352,8 +1364,9 @@ bool ShaderLanguage::_validate_operator(OperatorNode *p_op, DataType *r_ret_type
|
||||
}
|
||||
}
|
||||
|
||||
if (r_ret_type)
|
||||
if (r_ret_type) {
|
||||
*r_ret_type = ret_type;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
@@ -2130,8 +2143,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
}
|
||||
}
|
||||
|
||||
if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID)
|
||||
if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID) {
|
||||
fail = true; //make sure the number of arguments matches
|
||||
}
|
||||
|
||||
if (!fail) {
|
||||
//make sure its not an out argument used in the wrong way
|
||||
@@ -2192,8 +2206,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
p_func->arguments.write[i + 1] = conversion;
|
||||
}
|
||||
|
||||
if (r_ret_type)
|
||||
if (r_ret_type) {
|
||||
*r_ret_type = builtin_func_defs[idx].rettype;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2220,8 +2235,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
if (failed_builtin) {
|
||||
String err = "Invalid arguments for built-in function: " + String(name) + "(";
|
||||
for (int i = 0; i < argcount; i++) {
|
||||
if (i > 0)
|
||||
if (i > 0) {
|
||||
err += ",";
|
||||
}
|
||||
|
||||
if (p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && p_func->arguments[i + 1]->get_datatype() == TYPE_INT && static_cast<ConstantNode *>(p_func->arguments[i + 1])->values[0].sint < 0) {
|
||||
err += "-";
|
||||
@@ -2251,8 +2267,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
}
|
||||
|
||||
for (int i = 0; i < shader->functions.size(); i++) {
|
||||
if (name != shader->functions[i].name)
|
||||
if (name != shader->functions[i].name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!shader->functions[i].callable) {
|
||||
_set_error("Function '" + String(name) + " can't be called from source code.");
|
||||
@@ -2261,8 +2278,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
|
||||
FunctionNode *pfunc = shader->functions[i].function;
|
||||
|
||||
if (pfunc->arguments.size() != args.size())
|
||||
if (pfunc->arguments.size() != args.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool fail = false;
|
||||
|
||||
@@ -2294,8 +2312,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
|
||||
p_func->arguments.write[k + 1] = conversion;
|
||||
}
|
||||
|
||||
if (r_ret_type)
|
||||
if (r_ret_type) {
|
||||
*r_ret_type = pfunc->return_type;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2419,8 +2438,9 @@ bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_ty
|
||||
p_value->sint = p_constant->values[0].uint;
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShaderLanguage::is_scalar_type(DataType p_type) {
|
||||
@@ -2713,8 +2733,9 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
|
||||
return _validate_assign(op->arguments[1], p_builtin_types, r_message);
|
||||
|
||||
} else if (op->op == OP_CALL) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Assignment to function.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2726,20 +2747,23 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
|
||||
VariableNode *var = static_cast<VariableNode *>(p_node);
|
||||
|
||||
if (shader->uniforms.has(var->name)) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Assignment to uniform.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shader->varyings.has(var->name) && current_function != String("vertex")) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Varyings can only be assigned in vertex function.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shader->constants.has(var->name) || var->is_const) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Constants cannot be modified.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2750,22 +2774,25 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
|
||||
ArrayNode *arr = static_cast<ArrayNode *>(p_node);
|
||||
|
||||
if (arr->is_const) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Constants cannot be modified.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shader->varyings.has(arr->name) && current_function != String("vertex")) {
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = RTR("Varyings can only be assigned in vertex function.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (r_message)
|
||||
if (r_message) {
|
||||
*r_message = "Assignment to constant expression.";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2784,8 +2811,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
//handle subexpression
|
||||
|
||||
expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!expr)
|
||||
if (!expr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
tk = _get_token();
|
||||
|
||||
@@ -2865,8 +2893,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
completion_argument = carg;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!_validate_function_call(p_block, func, &func->return_cache)) {
|
||||
_set_error("No matching constructor found for: '" + String(funcname->name) + "'");
|
||||
@@ -2930,8 +2959,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
completion_argument = carg;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!_validate_function_call(p_block, func, &func->return_cache)) {
|
||||
_set_error("No matching function found for: '" + String(funcname->name) + "'");
|
||||
@@ -3042,14 +3072,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
p_block->block_tag = SubClassTag::TAG_ARRAY;
|
||||
call_expression = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
p_block->block_tag = SubClassTag::TAG_GLOBAL;
|
||||
if (!call_expression)
|
||||
if (!call_expression) {
|
||||
return nullptr;
|
||||
}
|
||||
data_type = call_expression->get_datatype();
|
||||
} else { // indexing
|
||||
|
||||
index_expression = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!index_expression)
|
||||
if (!index_expression) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (index_expression->get_datatype() != TYPE_INT && index_expression->get_datatype() != TYPE_UINT) {
|
||||
_set_error("Only integer expressions are allowed for indexing");
|
||||
@@ -3291,8 +3323,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
*/
|
||||
} else if (tk.type == TK_BRACKET_OPEN) {
|
||||
Node *index = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!index)
|
||||
if (!index) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (index->get_datatype() != TYPE_INT && index->get_datatype() != TYPE_UINT) {
|
||||
_set_error("Only integer datatypes are allowed for indexing");
|
||||
@@ -3750,8 +3783,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
if (!_validate_operator(op, &op->return_cache)) {
|
||||
String at;
|
||||
for (int j = 0; j < op->arguments.size(); j++) {
|
||||
if (j > 0)
|
||||
if (j > 0) {
|
||||
at += " and ";
|
||||
}
|
||||
at += get_datatype_name(op->arguments[j]->get_datatype());
|
||||
}
|
||||
_set_error("Invalid arguments to unary operator '" + get_operator_text(op->op) + "' :" + at);
|
||||
@@ -3782,8 +3816,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
if (!_validate_operator(op, &op->return_cache)) {
|
||||
String at;
|
||||
for (int i = 0; i < op->arguments.size(); i++) {
|
||||
if (i > 0)
|
||||
if (i > 0) {
|
||||
at += " and ";
|
||||
}
|
||||
at += get_datatype_name(op->arguments[i]->get_datatype());
|
||||
}
|
||||
_set_error("Invalid argument to ternary ?: operator: " + at);
|
||||
@@ -3834,8 +3869,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
if (!_validate_operator(op, &op->return_cache)) {
|
||||
String at;
|
||||
for (int i = 0; i < op->arguments.size(); i++) {
|
||||
if (i > 0)
|
||||
if (i > 0) {
|
||||
at += " and ";
|
||||
}
|
||||
at += get_datatype_name(op->arguments[i]->get_datatype());
|
||||
}
|
||||
_set_error("Invalid arguments to operator '" + get_operator_text(op->op) + "' :" + at);
|
||||
@@ -3851,8 +3887,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||
}
|
||||
|
||||
ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node) {
|
||||
if (p_node->type != Node::TYPE_OPERATOR)
|
||||
if (p_node->type != Node::TYPE_OPERATOR) {
|
||||
return p_node;
|
||||
}
|
||||
|
||||
//for now only reduce simple constructors
|
||||
OperatorNode *op = static_cast<OperatorNode *>(p_node);
|
||||
@@ -3960,8 +3997,9 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha
|
||||
|
||||
ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) {
|
||||
ShaderLanguage::Node *expr = _parse_expression(p_block, p_builtin_types);
|
||||
if (!expr) //errored
|
||||
if (!expr) { //errored
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
expr = _reduce_expression(p_block, expr);
|
||||
|
||||
@@ -4229,10 +4267,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
decl.initializer.push_back(n);
|
||||
break;
|
||||
} else {
|
||||
if (curly)
|
||||
if (curly) {
|
||||
_set_error("Expected '}' or ','");
|
||||
else
|
||||
} else {
|
||||
_set_error("Expected ')' or ','");
|
||||
}
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -4270,8 +4309,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
|
||||
//variable created with assignment! must parse an expression
|
||||
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (node->is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) {
|
||||
_set_error("Expected constant expression after '='");
|
||||
return ERR_PARSE_ERROR;
|
||||
@@ -4332,8 +4372,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
|
||||
cf->flow_op = FLOW_OP_IF;
|
||||
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (n->get_datatype() != TYPE_BOOL) {
|
||||
_set_error("Expected boolean expression");
|
||||
@@ -4353,8 +4394,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
p_block->statements.push_back(cf);
|
||||
|
||||
Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
pos = _get_tkpos();
|
||||
tk = _get_token();
|
||||
@@ -4382,8 +4424,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
|
||||
cf->flow_op = FLOW_OP_SWITCH;
|
||||
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (n->get_datatype() != TYPE_INT) {
|
||||
_set_error("Expected integer expression");
|
||||
return ERR_PARSE_ERROR;
|
||||
@@ -4510,8 +4553,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
p_block->statements.push_back(cf);
|
||||
|
||||
Error err = _parse_block(case_block, p_builtin_types, false, true, false);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -4543,8 +4587,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
p_block->statements.push_back(cf);
|
||||
|
||||
Error err = _parse_block(default_block, p_builtin_types, false, true, false);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -4559,8 +4604,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
do_block->parent_block = p_block;
|
||||
|
||||
Error err = _parse_block(do_block, p_builtin_types, true, true, true);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
tk = _get_token();
|
||||
if (tk.type != TK_CF_WHILE) {
|
||||
@@ -4582,8 +4628,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
cf->flow_op = FLOW_OP_WHILE;
|
||||
}
|
||||
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
tk = _get_token();
|
||||
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
||||
@@ -4598,8 +4645,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
p_block->statements.push_back(cf);
|
||||
|
||||
Error err = _parse_block(block, p_builtin_types, true, true, true);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
cf->expressions.push_back(n);
|
||||
cf->blocks.push_back(do_block);
|
||||
@@ -4631,8 +4679,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
}
|
||||
|
||||
Node *n = _parse_and_reduce_expression(init_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (n->get_datatype() != TYPE_BOOL) {
|
||||
_set_error("Middle expression is expected to be boolean.");
|
||||
@@ -4648,8 +4697,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
cf->expressions.push_back(n);
|
||||
|
||||
n = _parse_and_reduce_expression(init_block, p_builtin_types);
|
||||
if (!n)
|
||||
if (!n) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
cf->expressions.push_back(n);
|
||||
|
||||
@@ -4665,8 +4715,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
p_block->statements.push_back(cf);
|
||||
|
||||
Error err = _parse_block(block, p_builtin_types, true, true, true);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
} else if (tk.type == TK_CF_RETURN) {
|
||||
//check return type
|
||||
@@ -4700,8 +4751,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
} else {
|
||||
_set_tkpos(pos); //rollback, wants expression
|
||||
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!expr)
|
||||
if (!expr) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (b->parent_function->return_type != expr->get_datatype()) {
|
||||
_set_error("Expected return expression of type '" + get_datatype_name(b->parent_function->return_type) + "'");
|
||||
@@ -4802,8 +4854,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
//nothing else, so expression
|
||||
_set_tkpos(pos); //rollback
|
||||
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
||||
if (!expr)
|
||||
if (!expr) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
p_block->statements.push_back(expr);
|
||||
tk = _get_token();
|
||||
|
||||
@@ -4813,8 +4866,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
|
||||
}
|
||||
}
|
||||
|
||||
if (p_just_one)
|
||||
if (p_just_one) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
@@ -5136,8 +5190,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
||||
|
||||
if (tk.type == TK_OP_ASSIGN) {
|
||||
Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>());
|
||||
if (!expr)
|
||||
if (!expr) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
if (expr->type != Node::TYPE_CONSTANT) {
|
||||
_set_error("Expected constant expression after '='");
|
||||
return ERR_PARSE_ERROR;
|
||||
@@ -5277,8 +5332,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
||||
|
||||
//variable created with assignment! must parse an expression
|
||||
Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>());
|
||||
if (!expr)
|
||||
if (!expr) {
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
if (expr->type == Node::TYPE_OPERATOR && ((OperatorNode *)expr)->op == OP_CALL) {
|
||||
_set_error("Expected constant expression after '='");
|
||||
@@ -5474,8 +5530,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
|
||||
current_function = name;
|
||||
|
||||
Error err = _parse_block(func_node->body, builtin_types);
|
||||
if (err)
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (func_node->return_type != DataType::TYPE_VOID) {
|
||||
BlockNode *block = func_node->body;
|
||||
@@ -5571,8 +5628,9 @@ static int _get_first_ident_pos(const String &p_code) {
|
||||
if (GETCHAR(0) == '/' && GETCHAR(1) == '/') {
|
||||
idx += 2;
|
||||
while (true) {
|
||||
if (GETCHAR(0) == 0)
|
||||
if (GETCHAR(0) == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (GETCHAR(0) == '\n') {
|
||||
idx++;
|
||||
break; // loop
|
||||
@@ -5582,8 +5640,9 @@ static int _get_first_ident_pos(const String &p_code) {
|
||||
} else if (GETCHAR(0) == '/' && GETCHAR(1) == '*') {
|
||||
idx += 2;
|
||||
while (true) {
|
||||
if (GETCHAR(0) == 0)
|
||||
if (GETCHAR(0) == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (GETCHAR(0) == '*' && GETCHAR(1) == '/') {
|
||||
idx += 2;
|
||||
break; // loop
|
||||
@@ -5634,8 +5693,9 @@ String ShaderLanguage::get_shader_type(const String &p_code) {
|
||||
}
|
||||
}
|
||||
|
||||
if (reading_type)
|
||||
if (reading_type) {
|
||||
return cur_identifier;
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
@@ -5735,8 +5795,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
}
|
||||
|
||||
for (int i = 0; i < shader->functions.size(); i++) {
|
||||
if (!shader->functions[i].callable || shader->functions[i].name == skip_function)
|
||||
if (!shader->functions[i].callable || shader->functions[i].name == skip_function) {
|
||||
continue;
|
||||
}
|
||||
matches.insert(String(shader->functions[i].name), ScriptCodeCompletionOption::KIND_FUNCTION);
|
||||
}
|
||||
|
||||
@@ -5780,8 +5841,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
} break;
|
||||
case COMPLETION_CALL_ARGUMENTS: {
|
||||
for (int i = 0; i < shader->functions.size(); i++) {
|
||||
if (!shader->functions[i].callable)
|
||||
if (!shader->functions[i].callable) {
|
||||
continue;
|
||||
}
|
||||
if (shader->functions[i].name == completion_function) {
|
||||
String calltip;
|
||||
|
||||
@@ -5791,10 +5853,11 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
calltip += "(";
|
||||
|
||||
for (int j = 0; j < shader->functions[i].function->arguments.size(); j++) {
|
||||
if (j > 0)
|
||||
if (j > 0) {
|
||||
calltip += ", ";
|
||||
else
|
||||
} else {
|
||||
calltip += " ";
|
||||
}
|
||||
|
||||
if (j == completion_argument) {
|
||||
calltip += CharType(0xFFFF);
|
||||
@@ -5809,8 +5872,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
}
|
||||
}
|
||||
|
||||
if (shader->functions[i].function->arguments.size())
|
||||
if (shader->functions[i].function->arguments.size()) {
|
||||
calltip += " ";
|
||||
}
|
||||
calltip += ")";
|
||||
|
||||
r_call_hint = calltip;
|
||||
@@ -5835,8 +5899,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
continue;
|
||||
}
|
||||
|
||||
if (calltip.length())
|
||||
if (calltip.length()) {
|
||||
calltip += "\n";
|
||||
}
|
||||
|
||||
calltip += get_datatype_name(builtin_func_defs[idx].rettype);
|
||||
calltip += " ";
|
||||
@@ -5845,13 +5910,15 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
|
||||
bool found_arg = false;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (builtin_func_defs[idx].args[i] == TYPE_VOID)
|
||||
if (builtin_func_defs[idx].args[i] == TYPE_VOID) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
if (i > 0) {
|
||||
calltip += ", ";
|
||||
else
|
||||
} else {
|
||||
calltip += " ";
|
||||
}
|
||||
|
||||
if (i == completion_argument) {
|
||||
calltip += CharType(0xFFFF);
|
||||
@@ -5866,8 +5933,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
|
||||
found_arg = true;
|
||||
}
|
||||
|
||||
if (found_arg)
|
||||
if (found_arg) {
|
||||
calltip += " ";
|
||||
}
|
||||
calltip += ")";
|
||||
}
|
||||
idx++;
|
||||
|
||||
Reference in New Issue
Block a user