diff options
Diffstat (limited to 'servers/rendering/shader_language.cpp')
-rw-r--r-- | servers/rendering/shader_language.cpp | 900 |
1 files changed, 661 insertions, 239 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 08f1ced803..6f70a55948 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -237,92 +237,141 @@ ShaderLanguage::Token ShaderLanguage::_make_token(TokenType p_type, const String return tk; } +enum ContextFlag : uint32_t { + CF_UNSPECIFIED = 0U, + CF_BLOCK = 1U, // "void test() { <x> }" + CF_FUNC_DECL_PARAM_SPEC = 2U, // "void test(<x> int param) {}" + CF_FUNC_DECL_PARAM_TYPE = 4U, // "void test(<x> param) {}" + CF_IF_DECL = 8U, // "if(<x>) {}" + CF_BOOLEAN = 16U, // "bool t = <x>;" + CF_GLOBAL_SPACE = 32U, // "struct", "const", "void" etc. + CF_DATATYPE = 64U, // "<x> value;" + CF_UNIFORM_TYPE = 128U, // "uniform <x> myUniform;" + CF_VARYING_TYPE = 256U, // "varying <x> myVarying;" + CF_PRECISION_MODIFIER = 512U, // "<x> vec4 a = vec4(0.0, 1.0, 2.0, 3.0);" + CF_INTERPOLATION_QUALIFIER = 1024U, // "varying <x> vec3 myColor;" + CF_UNIFORM_KEYWORD = 2048U, // "uniform" + CF_CONST_KEYWORD = 4096U, // "const" + CF_UNIFORM_QUALIFIER = 8192U, // "<x> uniform float t;" +}; + +const uint32_t KCF_DATATYPE = CF_BLOCK | CF_GLOBAL_SPACE | CF_DATATYPE | CF_FUNC_DECL_PARAM_TYPE | CF_UNIFORM_TYPE; +const uint32_t KCF_SAMPLER_DATATYPE = CF_FUNC_DECL_PARAM_TYPE | CF_UNIFORM_TYPE; + const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { - { TK_TRUE, "true" }, - { TK_FALSE, "false" }, - { TK_TYPE_VOID, "void" }, - { TK_TYPE_BOOL, "bool" }, - { TK_TYPE_BVEC2, "bvec2" }, - { TK_TYPE_BVEC3, "bvec3" }, - { TK_TYPE_BVEC4, "bvec4" }, - { TK_TYPE_INT, "int" }, - { TK_TYPE_IVEC2, "ivec2" }, - { TK_TYPE_IVEC3, "ivec3" }, - { TK_TYPE_IVEC4, "ivec4" }, - { TK_TYPE_UINT, "uint" }, - { TK_TYPE_UVEC2, "uvec2" }, - { TK_TYPE_UVEC3, "uvec3" }, - { TK_TYPE_UVEC4, "uvec4" }, - { TK_TYPE_FLOAT, "float" }, - { TK_TYPE_VEC2, "vec2" }, - { TK_TYPE_VEC3, "vec3" }, - { TK_TYPE_VEC4, "vec4" }, - { TK_TYPE_MAT2, "mat2" }, - { TK_TYPE_MAT3, "mat3" }, - { TK_TYPE_MAT4, "mat4" }, - { TK_TYPE_SAMPLER2D, "sampler2D" }, - { TK_TYPE_ISAMPLER2D, "isampler2D" }, - { TK_TYPE_USAMPLER2D, "usampler2D" }, - { TK_TYPE_SAMPLER2DARRAY, "sampler2DArray" }, - { TK_TYPE_ISAMPLER2DARRAY, "isampler2DArray" }, - { TK_TYPE_USAMPLER2DARRAY, "usampler2DArray" }, - { TK_TYPE_SAMPLER3D, "sampler3D" }, - { TK_TYPE_ISAMPLER3D, "isampler3D" }, - { TK_TYPE_USAMPLER3D, "usampler3D" }, - { TK_TYPE_SAMPLERCUBE, "samplerCube" }, - { TK_TYPE_SAMPLERCUBEARRAY, "samplerCubeArray" }, - { TK_INTERPOLATION_FLAT, "flat" }, - { TK_INTERPOLATION_SMOOTH, "smooth" }, - { TK_CONST, "const" }, - { TK_STRUCT, "struct" }, - { TK_PRECISION_LOW, "lowp" }, - { TK_PRECISION_MID, "mediump" }, - { TK_PRECISION_HIGH, "highp" }, - { TK_CF_IF, "if" }, - { TK_CF_ELSE, "else" }, - { TK_CF_FOR, "for" }, - { TK_CF_WHILE, "while" }, - { TK_CF_DO, "do" }, - { TK_CF_SWITCH, "switch" }, - { TK_CF_CASE, "case" }, - { TK_CF_DEFAULT, "default" }, - { TK_CF_BREAK, "break" }, - { TK_CF_CONTINUE, "continue" }, - { TK_CF_RETURN, "return" }, - { TK_CF_DISCARD, "discard" }, - { TK_UNIFORM, "uniform" }, - { TK_INSTANCE, "instance" }, - { TK_GLOBAL, "global" }, - { TK_VARYING, "varying" }, - { TK_ARG_IN, "in" }, - { TK_ARG_OUT, "out" }, - { TK_ARG_INOUT, "inout" }, - { TK_RENDER_MODE, "render_mode" }, - { TK_HINT_WHITE_TEXTURE, "hint_white" }, - { TK_HINT_BLACK_TEXTURE, "hint_black" }, - { TK_HINT_NORMAL_TEXTURE, "hint_normal" }, - { TK_HINT_ROUGHNESS_NORMAL_TEXTURE, "hint_roughness_normal" }, - { TK_HINT_ROUGHNESS_R, "hint_roughness_r" }, - { TK_HINT_ROUGHNESS_G, "hint_roughness_g" }, - { TK_HINT_ROUGHNESS_B, "hint_roughness_b" }, - { TK_HINT_ROUGHNESS_A, "hint_roughness_a" }, - { TK_HINT_ROUGHNESS_GRAY, "hint_roughness_gray" }, - { TK_HINT_ANISOTROPY_TEXTURE, "hint_anisotropy" }, - { TK_HINT_ALBEDO_TEXTURE, "hint_albedo" }, - { TK_HINT_BLACK_ALBEDO_TEXTURE, "hint_black_albedo" }, - { TK_HINT_COLOR, "hint_color" }, - { TK_HINT_RANGE, "hint_range" }, - { TK_HINT_INSTANCE_INDEX, "instance_index" }, - { TK_FILTER_NEAREST, "filter_nearest" }, - { TK_FILTER_LINEAR, "filter_linear" }, - { TK_FILTER_NEAREST_MIPMAP, "filter_nearest_mipmap" }, - { TK_FILTER_LINEAR_MIPMAP, "filter_linear_mipmap" }, - { TK_FILTER_NEAREST_MIPMAP_ANISOTROPIC, "filter_nearest_mipmap_anisotropic" }, - { TK_FILTER_LINEAR_MIPMAP_ANISOTROPIC, "filter_linear_mipmap_anisotropic" }, - { TK_REPEAT_ENABLE, "repeat_enable" }, - { TK_REPEAT_DISABLE, "repeat_disable" }, - { TK_SHADER_TYPE, "shader_type" }, - { TK_ERROR, nullptr } + { TK_TRUE, "true", CF_BLOCK | CF_IF_DECL | CF_BOOLEAN, {}, {} }, + { TK_FALSE, "false", CF_BLOCK | CF_IF_DECL | CF_BOOLEAN, {}, {} }, + + // data types + + { TK_TYPE_VOID, "void", CF_GLOBAL_SPACE, {}, {} }, + { TK_TYPE_BOOL, "bool", KCF_DATATYPE, {}, {} }, + { TK_TYPE_BVEC2, "bvec2", KCF_DATATYPE, {}, {} }, + { TK_TYPE_BVEC3, "bvec3", KCF_DATATYPE, {}, {} }, + { TK_TYPE_BVEC4, "bvec4", KCF_DATATYPE, {}, {} }, + { TK_TYPE_INT, "int", KCF_DATATYPE, {}, {} }, + { TK_TYPE_IVEC2, "ivec2", KCF_DATATYPE, {}, {} }, + { TK_TYPE_IVEC3, "ivec3", KCF_DATATYPE, {}, {} }, + { TK_TYPE_IVEC4, "ivec4", KCF_DATATYPE, {}, {} }, + { TK_TYPE_UINT, "uint", KCF_DATATYPE, {}, {} }, + { TK_TYPE_UVEC2, "uvec2", KCF_DATATYPE, {}, {} }, + { TK_TYPE_UVEC3, "uvec3", KCF_DATATYPE, {}, {} }, + { TK_TYPE_UVEC4, "uvec4", KCF_DATATYPE, {}, {} }, + { TK_TYPE_FLOAT, "float", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_VEC2, "vec2", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_VEC3, "vec3", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_VEC4, "vec4", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_MAT2, "mat2", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_MAT3, "mat3", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_MAT4, "mat4", KCF_DATATYPE | CF_VARYING_TYPE, {}, {} }, + { TK_TYPE_SAMPLER2D, "sampler2D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_ISAMPLER2D, "isampler2D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_USAMPLER2D, "usampler2D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_SAMPLER2DARRAY, "sampler2DArray", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_ISAMPLER2DARRAY, "isampler2DArray", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_USAMPLER2DARRAY, "usampler2DArray", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_SAMPLER3D, "sampler3D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_ISAMPLER3D, "isampler3D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_USAMPLER3D, "usampler3D", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_SAMPLERCUBE, "samplerCube", KCF_SAMPLER_DATATYPE, {}, {} }, + { TK_TYPE_SAMPLERCUBEARRAY, "samplerCubeArray", KCF_SAMPLER_DATATYPE, {}, {} }, + + // interpolation qualifiers + + { TK_INTERPOLATION_FLAT, "flat", CF_INTERPOLATION_QUALIFIER, {}, {} }, + { TK_INTERPOLATION_SMOOTH, "smooth", CF_INTERPOLATION_QUALIFIER, {}, {} }, + + // precision modifiers + + { TK_PRECISION_LOW, "lowp", CF_BLOCK | CF_PRECISION_MODIFIER, {}, {} }, + { TK_PRECISION_MID, "mediump", CF_BLOCK | CF_PRECISION_MODIFIER, {}, {} }, + { TK_PRECISION_HIGH, "highp", CF_BLOCK | CF_PRECISION_MODIFIER, {}, {} }, + + // global space keywords + + { TK_UNIFORM, "uniform", CF_GLOBAL_SPACE | CF_UNIFORM_KEYWORD, {}, {} }, + { TK_VARYING, "varying", CF_GLOBAL_SPACE, { "particles", "sky", "fog" }, {} }, + { TK_CONST, "const", CF_BLOCK | CF_GLOBAL_SPACE | CF_CONST_KEYWORD, {}, {} }, + { TK_STRUCT, "struct", CF_GLOBAL_SPACE, {}, {} }, + { TK_SHADER_TYPE, "shader_type", CF_GLOBAL_SPACE, {}, {} }, + { TK_RENDER_MODE, "render_mode", CF_GLOBAL_SPACE, {}, {} }, + + // uniform qualifiers + + { TK_INSTANCE, "instance", CF_GLOBAL_SPACE | CF_UNIFORM_QUALIFIER, {}, {} }, + { TK_GLOBAL, "global", CF_GLOBAL_SPACE | CF_UNIFORM_QUALIFIER, {}, {} }, + + // block keywords + + { TK_CF_IF, "if", CF_BLOCK, {}, {} }, + { TK_CF_ELSE, "else", CF_BLOCK, {}, {} }, + { TK_CF_FOR, "for", CF_BLOCK, {}, {} }, + { TK_CF_WHILE, "while", CF_BLOCK, {}, {} }, + { TK_CF_DO, "do", CF_BLOCK, {}, {} }, + { TK_CF_SWITCH, "switch", CF_BLOCK, {}, {} }, + { TK_CF_CASE, "case", CF_BLOCK, {}, {} }, + { TK_CF_DEFAULT, "default", CF_BLOCK, {}, {} }, + { TK_CF_BREAK, "break", CF_BLOCK, {}, {} }, + { TK_CF_CONTINUE, "continue", CF_BLOCK, {}, {} }, + { TK_CF_RETURN, "return", CF_BLOCK, {}, {} }, + { TK_CF_DISCARD, "discard", CF_BLOCK, { "particles", "sky", "fog" }, { "fragment" } }, + + // function specifier keywords + + { TK_ARG_IN, "in", CF_FUNC_DECL_PARAM_SPEC, {}, {} }, + { TK_ARG_OUT, "out", CF_FUNC_DECL_PARAM_SPEC, {}, {} }, + { TK_ARG_INOUT, "inout", CF_FUNC_DECL_PARAM_SPEC, {}, {} }, + + // hints + + { TK_HINT_RANGE, "hint_range", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_COLOR, "hint_color", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_INSTANCE_INDEX, "instance_index", CF_UNSPECIFIED, {}, {} }, + + // sampler hints + + { TK_HINT_ALBEDO_TEXTURE, "hint_albedo", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_BLACK_ALBEDO_TEXTURE, "hint_black_albedo", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_NORMAL_TEXTURE, "hint_normal", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_WHITE_TEXTURE, "hint_white", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_BLACK_TEXTURE, "hint_black", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ANISOTROPY_TEXTURE, "hint_anisotropy", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_R, "hint_roughness_r", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_G, "hint_roughness_g", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_B, "hint_roughness_b", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_A, "hint_roughness_a", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_NORMAL_TEXTURE, "hint_roughness_normal", CF_UNSPECIFIED, {}, {} }, + { TK_HINT_ROUGHNESS_GRAY, "hint_roughness_gray", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_NEAREST, "filter_nearest", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_LINEAR, "filter_linear", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_NEAREST_MIPMAP, "filter_nearest_mipmap", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_LINEAR_MIPMAP, "filter_linear_mipmap", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_NEAREST_MIPMAP_ANISOTROPIC, "filter_nearest_mipmap_anisotropic", CF_UNSPECIFIED, {}, {} }, + { TK_FILTER_LINEAR_MIPMAP_ANISOTROPIC, "filter_linear_mipmap_anisotropic", CF_UNSPECIFIED, {}, {} }, + { TK_REPEAT_ENABLE, "repeat_enable", CF_UNSPECIFIED, {}, {} }, + { TK_REPEAT_DISABLE, "repeat_disable", CF_UNSPECIFIED, {}, {} }, + + { TK_ERROR, nullptr, CF_UNSPECIFIED, {}, {} } }; ShaderLanguage::Token ShaderLanguage::_get_token() { @@ -752,6 +801,19 @@ ShaderLanguage::Token ShaderLanguage::_get_token() { #undef GETCHAR } +bool ShaderLanguage::_lookup_next(Token &r_tk) { + TkPos pre_pos = _get_tkpos(); + int line = pre_pos.tk_line; + _get_token(); + Token tk = _get_token(); + _set_tkpos(pre_pos); + if (tk.line == line) { + r_tk = tk; + return true; + } + return false; +} + String ShaderLanguage::token_debug(const String &p_code) { clear(); @@ -852,6 +914,13 @@ bool ShaderLanguage::is_token_precision(TokenType p_type) { p_type == TK_PRECISION_HIGH); } +bool ShaderLanguage::is_token_arg_qual(TokenType p_type) { + return ( + p_type == TK_ARG_IN || + p_type == TK_ARG_OUT || + p_type == TK_ARG_INOUT); +} + ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) { if (p_type == TK_PRECISION_LOW) { return PRECISION_LOWP; @@ -967,6 +1036,7 @@ void ShaderLanguage::clear() { completion_base_array = false; #ifdef DEBUG_ENABLED + keyword_completion_context = CF_GLOBAL_SPACE; used_constants.clear(); used_varyings.clear(); used_uniforms.clear(); @@ -2813,7 +2883,7 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI bool error = false; if (p_func->arguments[arg]->type == Node::TYPE_VARIABLE) { - const VariableNode *vn = (VariableNode *)p_func->arguments[arg]; + const VariableNode *vn = static_cast<VariableNode *>(p_func->arguments[arg]); bool is_const = false; ConstantNode::Value value; @@ -2825,7 +2895,7 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const FunctionI } } else { if (p_func->arguments[arg]->type == Node::TYPE_CONSTANT) { - ConstantNode *cn = (ConstantNode *)p_func->arguments[arg]; + const ConstantNode *cn = static_cast<ConstantNode *>(p_func->arguments[arg]); if (cn->get_datatype() == TYPE_INT && cn->values.size() == 1) { int value = cn->values[0].sint; @@ -3467,7 +3537,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C } value = Variant(array); } else { - value = Variant(Plane(p_value[0].sint, p_value[1].sint, p_value[2].sint, p_value[3].sint)); + value = Variant(Quaternion(p_value[0].sint, p_value[1].sint, p_value[2].sint, p_value[3].sint)); } break; case ShaderLanguage::TYPE_UINT: @@ -3517,7 +3587,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C } value = Variant(array); } else { - value = Variant(Plane(p_value[0].uint, p_value[1].uint, p_value[2].uint, p_value[3].uint)); + value = Variant(Quaternion(p_value[0].uint, p_value[1].uint, p_value[2].uint, p_value[3].uint)); } break; case ShaderLanguage::TYPE_FLOAT: @@ -3548,13 +3618,25 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C if (array_size > 0) { array_size *= 3; - PackedVector3Array array = PackedVector3Array(); - for (int i = 0; i < array_size; i += 3) { - array.push_back(Vector3(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real)); + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + PackedColorArray array = PackedColorArray(); + for (int i = 0; i < array_size; i += 3) { + array.push_back(Color(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real)); + } + value = Variant(array); + } else { + PackedVector3Array array = PackedVector3Array(); + for (int i = 0; i < array_size; i += 3) { + array.push_back(Vector3(p_value[i].real, p_value[i + 1].real, p_value[i + 2].real)); + } + value = Variant(array); } - value = Variant(array); } else { - value = Variant(Vector3(p_value[0].real, p_value[1].real, p_value[2].real)); + if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + value = Variant(Color(p_value[0].real, p_value[1].real, p_value[2].real)); + } else { + value = Variant(Vector3(p_value[0].real, p_value[1].real, p_value[2].real)); + } } break; case ShaderLanguage::TYPE_VEC4: @@ -3581,7 +3663,7 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C if (p_hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { value = Variant(Color(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); } else { - value = Variant(Plane(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); + value = Variant(Quaternion(p_value[0].real, p_value[1].real, p_value[2].real, p_value[3].real)); } } break; @@ -3760,9 +3842,19 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform break; case ShaderLanguage::TYPE_VEC3: if (p_uniform.array_size > 0) { - pi.type = Variant::PACKED_VECTOR3_ARRAY; + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + pi.hint = PROPERTY_HINT_COLOR_NO_ALPHA; + pi.type = Variant::PACKED_COLOR_ARRAY; + } else { + pi.type = Variant::PACKED_VECTOR3_ARRAY; + } } else { - pi.type = Variant::VECTOR3; + if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { + pi.hint = PROPERTY_HINT_COLOR_NO_ALPHA; + pi.type = Variant::COLOR; + } else { + pi.type = Variant::VECTOR3; + } } break; case ShaderLanguage::TYPE_VEC4: { @@ -3776,7 +3868,7 @@ PropertyInfo ShaderLanguage::uniform_to_property_info(const ShaderNode::Uniform if (p_uniform.hint == ShaderLanguage::ShaderNode::Uniform::HINT_COLOR) { pi.type = Variant::COLOR; } else { - pi.type = Variant::PLANE; + pi.type = Variant::QUATERNION; } } } break; @@ -4132,7 +4224,7 @@ bool ShaderLanguage::_validate_varying_assign(ShaderNode::Varying &p_varying, St bool ShaderLanguage::_check_node_constness(const Node *p_node) const { switch (p_node->type) { case Node::TYPE_OPERATOR: { - OperatorNode *op_node = (OperatorNode *)p_node; + const OperatorNode *op_node = static_cast<const OperatorNode *>(p_node); for (int i = int(op_node->op == OP_CALL); i < op_node->arguments.size(); i++) { if (!_check_node_constness(op_node->arguments[i])) { return false; @@ -4142,13 +4234,13 @@ bool ShaderLanguage::_check_node_constness(const Node *p_node) const { case Node::TYPE_CONSTANT: break; case Node::TYPE_VARIABLE: { - VariableNode *varn = (VariableNode *)p_node; + const VariableNode *varn = static_cast<const VariableNode *>(p_node); if (!varn->is_const) { return false; } } break; case Node::TYPE_ARRAY: { - ArrayNode *arrn = (ArrayNode *)p_node; + const ArrayNode *arrn = static_cast<const ArrayNode *>(p_node); if (!arrn->is_const) { return false; } @@ -4670,16 +4762,18 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons expr = _parse_array_constructor(p_block, p_function_info); } else { DataType datatype; - DataPrecision precision; - bool precision_defined = false; + DataPrecision precision = PRECISION_DEFAULT; if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - precision_defined = true; tk = _get_token(); } datatype = get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(datatype, precision) != OK) { + return nullptr; + } + tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { @@ -4697,7 +4791,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons OperatorNode *func = alloc_node<OperatorNode>(); func->op = OP_CONSTRUCT; - if (precision_defined) { + if (precision != PRECISION_DEFAULT) { func->return_precision_cache = precision; } @@ -5134,13 +5228,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } else if (tk.type == TK_PERIOD) { completion_class = TAG_ARRAY; - p_block->block_tag = SubClassTag::TAG_ARRAY; + if (p_block != nullptr) { + p_block->block_tag = SubClassTag::TAG_ARRAY; + } call_expression = _parse_and_reduce_expression(p_block, p_function_info); - p_block->block_tag = SubClassTag::TAG_GLOBAL; + if (p_block != nullptr) { + p_block->block_tag = SubClassTag::TAG_GLOBAL; + } if (!call_expression) { return nullptr; } - data_type = call_expression->get_datatype(); } else if (tk.type == TK_BRACKET_OPEN) { // indexing index_expression = _parse_and_reduce_expression(p_block, p_function_info); if (!index_expression) { @@ -5153,7 +5250,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (index_expression->type == Node::TYPE_CONSTANT) { - ConstantNode *cnode = (ConstantNode *)index_expression; + ConstantNode *cnode = static_cast<ConstantNode *>(index_expression); if (cnode) { if (!cnode->values.is_empty()) { int value = cnode->values[0].sint; @@ -5287,9 +5384,13 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons if (!expr->is_indexed() && expr->get_array_size() > 0) { completion_class = TAG_ARRAY; - p_block->block_tag = SubClassTag::TAG_ARRAY; + if (p_block != nullptr) { + 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 (p_block != nullptr) { + p_block->block_tag = SubClassTag::TAG_GLOBAL; + } if (!call_expression) { return nullptr; } @@ -5587,14 +5688,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons mn->assign_expression = assign_expression; } else if (tk.type == TK_PERIOD) { 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) { + if (p_block != nullptr) { + p_block->block_tag = SubClassTag::TAG_ARRAY; + } + mn->call_expression = _parse_and_reduce_expression(p_block, p_function_info); + if (p_block != nullptr) { + p_block->block_tag = SubClassTag::TAG_GLOBAL; + } + if (!mn->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) { @@ -5607,7 +5710,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } if (index_expression->type == Node::TYPE_CONSTANT) { - ConstantNode *cnode = (ConstantNode *)index_expression; + ConstantNode *cnode = static_cast<ConstantNode *>(index_expression); if (cnode) { if (!cnode->values.is_empty()) { int value = cnode->values[0].sint; @@ -6362,8 +6465,10 @@ ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_just_one, bool p_can_break, bool p_can_continue) { while (true) { TkPos pos = _get_tkpos(); - Token tk = _get_token(); +#ifdef DEBUG_ENABLED + Token next; +#endif // DEBUG_ENABLED if (p_block && p_block->block_type == BlockNode::BLOCK_TYPE_SWITCH) { if (tk.type != TK_CF_CASE && tk.type != TK_CF_DEFAULT && tk.type != TK_CURLY_BRACKET_CLOSE) { @@ -6396,6 +6501,16 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } #endif // DEBUG_ENABLED } +#ifdef DEBUG_ENABLED + uint32_t precision_flag = CF_PRECISION_MODIFIER; + + keyword_completion_context = CF_DATATYPE; + if (!is_token_precision(tk.type)) { + if (!is_struct) { + keyword_completion_context |= precision_flag; + } + } +#endif // DEBUG_ENABLED bool is_const = false; @@ -6417,10 +6532,26 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (!is_struct) { is_struct = shader->structs.has(tk.text); // check again. } - if (is_struct && precision != PRECISION_DEFAULT) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; + +#ifdef DEBUG_ENABLED + if (keyword_completion_context & precision_flag) { + keyword_completion_context ^= precision_flag; } +#endif // DEBUG_ENABLED + } + +#ifdef DEBUG_ENABLED + if (is_const && _lookup_next(next)) { + if (is_token_precision(next.type)) { + keyword_completion_context = CF_UNSPECIFIED; + } + if (is_token_datatype(next.type)) { + keyword_completion_context ^= CF_DATATYPE; + } + } +#endif // DEBUG_ENABLED + + if (precision != PRECISION_DEFAULT) { if (!is_token_nonvoid_datatype(tk.type)) { _set_error(RTR("Expected variable type after precision modifier.")); return ERR_PARSE_ERROR; @@ -6440,6 +6571,14 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED + int array_size = 0; bool fixed_array_size = false; bool first = true; @@ -6543,7 +6682,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun tk = _get_token(); } - +#ifdef DEBUG_ENABLED + if (var.type == DataType::TYPE_BOOL) { + keyword_completion_context = CF_BOOLEAN; + } +#endif // DEBUG_ENABLED if (var.array_size > 0 || unknown_size) { bool full_def = false; @@ -6591,10 +6734,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (is_token_precision(tk.type)) { precision2 = get_token_precision(tk.type); tk = _get_token(); - if (shader->structs.has(tk.text)) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } if (!is_token_nonvoid_datatype(tk.type)) { _set_error(RTR("Expected data type after precision modifier.")); return ERR_PARSE_ERROR; @@ -6615,6 +6754,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun type2 = get_token_datatype(tk.type); } + if (precision2 != PRECISION_DEFAULT && _validate_precision(type2, precision2) != OK) { + return ERR_PARSE_ERROR; + } + int array_size2 = 0; tk = _get_token(); @@ -6690,7 +6833,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } - if (is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { + if (is_const && n->type == Node::TYPE_OPERATOR && static_cast<OperatorNode *>(n)->op == OP_CALL) { _set_error(RTR("Expected a constant expression.")); return ERR_PARSE_ERROR; } @@ -6746,8 +6889,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (!n) { return ERR_PARSE_ERROR; } - if (is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { - OperatorNode *op = ((OperatorNode *)n); + if (is_const && n->type == Node::TYPE_OPERATOR && static_cast<OperatorNode *>(n)->op == OP_CALL) { + OperatorNode *op = static_cast<OperatorNode *>(n); for (int i = 1; i < op->arguments.size(); i++) { if (!_check_node_constness(op->arguments[i])) { _set_error(vformat(RTR("Expected constant expression for argument %d of function call after '='."), i - 1)); @@ -6790,8 +6933,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } } while (tk.type == TK_COMMA); //another variable - - p_block->statements.push_back((Node *)vdnode); +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_BLOCK; +#endif // DEBUG_ENABLED + p_block->statements.push_back(static_cast<Node *>(vdnode)); } else if (tk.type == TK_CURLY_BRACKET_OPEN) { //a sub block, just because.. BlockNode *block = alloc_node<BlockNode>(); @@ -6810,10 +6955,16 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun ControlFlowNode *cf = alloc_node<ControlFlowNode>(); cf->flow_op = FLOW_OP_IF; +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_IF_DECL; +#endif // DEBUG_ENABLED Node *n = _parse_and_reduce_expression(p_block, p_function_info); if (!n) { return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_BLOCK; +#endif // DEBUG_ENABLED if (n->get_datatype() != TYPE_BOOL) { _set_error(RTR("Expected a boolean expression.")); @@ -6913,7 +7064,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } else { Set<int> constants; for (int i = 0; i < switch_block->statements.size(); i++) { // Checks for duplicates. - ControlFlowNode *flow = (ControlFlowNode *)switch_block->statements[i]; + ControlFlowNode *flow = static_cast<ControlFlowNode *>(switch_block->statements[i]); if (flow) { if (flow->flow_op == FLOW_OP_CASE) { if (flow->expressions[0]->type == Node::TYPE_CONSTANT) { @@ -7151,10 +7302,17 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun init_block->parent_block = p_block; init_block->single_statement = true; cf->blocks.push_back(init_block); + +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_DATATYPE; +#endif // DEBUG_ENABLED Error err = _parse_block(init_block, p_function_info, true, false, false); if (err != OK) { return err; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED BlockNode *condition_block = alloc_node<BlockNode>(); condition_block->block_type = BlockNode::BLOCK_TYPE_FOR_CONDITION; @@ -7183,6 +7341,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun cf->blocks.push_back(block); p_block->statements.push_back(cf); +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_BLOCK; +#endif // DEBUG_ENABLED err = _parse_block(block, p_function_info, true, true, true); if (err != OK) { return err; @@ -7227,6 +7388,12 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun } else { _set_tkpos(pos); //rollback, wants expression +#ifdef DEBUG_ENABLED + if (b->parent_function->return_type == DataType::TYPE_BOOL) { + keyword_completion_context = CF_BOOLEAN; + } +#endif // DEBUG_ENABLED + Node *expr = _parse_and_reduce_expression(p_block, p_function_info); if (!expr) { return ERR_PARSE_ERROR; @@ -7243,6 +7410,12 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + if (b->parent_function->return_type == DataType::TYPE_BOOL) { + keyword_completion_context = CF_BLOCK; + } +#endif // DEBUG_ENABLED + flow->expressions.push_back(expr); } @@ -7418,6 +7591,25 @@ String ShaderLanguage::_get_qualifier_str(ArgumentQualifier p_qualifier) const { return ""; } +Error ShaderLanguage::_validate_precision(DataType p_type, DataPrecision p_precision) { + switch (p_type) { + case TYPE_STRUCT: { + _set_error(RTR("The precision modifier cannot be used on structs.")); + return FAILED; + } break; + case TYPE_BOOL: + case TYPE_BVEC2: + case TYPE_BVEC3: + case TYPE_BVEC4: { + _set_error(RTR("The precision modifier cannot be used on boolean types.")); + return FAILED; + } break; + default: + break; + } + return OK; +} + Error ShaderLanguage::_validate_datatype(DataType p_type) { if (RenderingServer::get_singleton()->is_low_end()) { bool invalid_type = false; @@ -7450,15 +7642,17 @@ Error ShaderLanguage::_validate_datatype(DataType p_type) { Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<ModeInfo> &p_render_modes, const Set<String> &p_shader_types) { Token tk = _get_token(); TkPos prev_pos; + Token next; if (tk.type != TK_SHADER_TYPE) { _set_error(vformat(RTR("Expected '%s' at the beginning of shader. Valid types are: %s."), "shader_type", _get_shader_type_list(p_shader_types))); return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED - StringName shader_type_identifier; _get_completable_identifier(nullptr, COMPLETION_SHADER_TYPE, shader_type_identifier); - if (shader_type_identifier == StringName()) { _set_error(vformat(RTR("Expected an identifier after '%s', indicating the type of shader. Valid types are: %s."), "shader_type", _get_shader_type_list(p_shader_types))); return ERR_PARSE_ERROR; @@ -7476,6 +7670,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_GLOBAL_SPACE; +#endif // DEBUG_ENABLED tk = _get_token(); int texture_uniforms = 0; @@ -7569,7 +7766,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct case TK_STRUCT: { ShaderNode::Struct st; DataType type; - +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED tk = _get_token(); if (tk.type == TK_IDENTIFIER) { st.name = tk.text; @@ -7592,15 +7791,19 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct int member_count = 0; Set<String> member_names; + while (true) { // variables list +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_DATATYPE | CF_PRECISION_MODIFIER; +#endif // DEBUG_ENABLED + tk = _get_token(); if (tk.type == TK_CURLY_BRACKET_CLOSE) { break; } StringName struct_name = ""; bool struct_dt = false; - bool use_precision = false; - DataPrecision precision = DataPrecision::PRECISION_DEFAULT; + DataPrecision precision = PRECISION_DEFAULT; if (tk.type == TK_STRUCT) { _set_error(RTR("Nested structs are not allowed.")); @@ -7609,8 +7812,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - use_precision = true; tk = _get_token(); +#ifdef DEBUG_ENABLED + keyword_completion_context ^= CF_PRECISION_MODIFIER; +#endif // DEBUG_ENABLED } if (shader->structs.has(tk.text)) { @@ -7621,10 +7826,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } #endif // DEBUG_ENABLED struct_dt = true; - if (use_precision) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } } if (!is_token_datatype(tk.type) && !struct_dt) { @@ -7633,10 +7834,17 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } else { type = struct_dt ? TYPE_STRUCT : get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + if (type == TYPE_VOID || is_sampler_type(type)) { _set_error(vformat(RTR("A '%s' data type is not allowed here."), get_datatype_name(type))); return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED bool first = true; bool fixed_array_size = false; @@ -7708,12 +7916,19 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct _set_error(RTR("Empty structs are not allowed.")); return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_expected_error(";"); return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_GLOBAL_SPACE; +#endif // DEBUG_ENABLED + shader->structs[st.name] = st; shader->vstructs.push_back(st); // struct's order is important! #ifdef DEBUG_ENABLED @@ -7723,6 +7938,14 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct #endif // DEBUG_ENABLED } break; case TK_GLOBAL: { +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNIFORM_KEYWORD; + if (_lookup_next(next)) { + if (next.type == TK_UNIFORM) { + keyword_completion_context ^= CF_UNIFORM_KEYWORD; + } + } +#endif // DEBUG_ENABLED tk = _get_token(); if (tk.type != TK_UNIFORM) { _set_expected_after_error("uniform", "global"); @@ -7732,6 +7955,14 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct }; [[fallthrough]]; case TK_INSTANCE: { +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNIFORM_KEYWORD; + if (_lookup_next(next)) { + if (next.type == TK_UNIFORM) { + keyword_completion_context ^= CF_UNIFORM_KEYWORD; + } + } +#endif // DEBUG_ENABLED if (uniform_scope == ShaderNode::Uniform::SCOPE_LOCAL) { tk = _get_token(); if (tk.type != TK_UNIFORM) { @@ -7745,15 +7976,15 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct case TK_UNIFORM: case TK_VARYING: { bool uniform = tk.type == TK_UNIFORM; - +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED if (!uniform) { if (shader_type_identifier == "particles" || shader_type_identifier == "sky" || shader_type_identifier == "fog") { _set_error(vformat(RTR("Varyings cannot be used in '%s' shaders."), shader_type_identifier)); return ERR_PARSE_ERROR; } } - - bool precision_defined = false; DataPrecision precision = PRECISION_DEFAULT; DataInterpolation interpolation = INTERPOLATION_SMOOTH; DataType type; @@ -7761,27 +7992,85 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct int array_size = 0; tk = _get_token(); +#ifdef DEBUG_ENABLED + bool temp_error = false; + uint32_t datatype_flag; + + if (!uniform) { + datatype_flag = CF_VARYING_TYPE; + keyword_completion_context = CF_INTERPOLATION_QUALIFIER | CF_PRECISION_MODIFIER | datatype_flag; + + if (_lookup_next(next)) { + if (is_token_interpolation(next.type)) { + keyword_completion_context ^= (CF_INTERPOLATION_QUALIFIER | datatype_flag); + } else if (is_token_precision(next.type)) { + keyword_completion_context ^= (CF_PRECISION_MODIFIER | datatype_flag); + } else if (is_token_datatype(next.type)) { + keyword_completion_context ^= datatype_flag; + } + } + } else { + datatype_flag = CF_UNIFORM_TYPE; + keyword_completion_context = CF_PRECISION_MODIFIER | datatype_flag; + + if (_lookup_next(next)) { + if (is_token_precision(next.type)) { + keyword_completion_context ^= (CF_PRECISION_MODIFIER | datatype_flag); + } else if (is_token_datatype(next.type)) { + keyword_completion_context ^= datatype_flag; + } + } + } +#endif // DEBUG_ENABLED + if (is_token_interpolation(tk.type)) { if (uniform) { _set_error(RTR("Interpolation qualifiers are not supported for uniforms.")); +#ifdef DEBUG_ENABLED + temp_error = true; +#else return ERR_PARSE_ERROR; +#endif // DEBUG_ENABLED } interpolation = get_token_interpolation(tk.type); tk = _get_token(); +#ifdef DEBUG_ENABLED + if (keyword_completion_context & CF_INTERPOLATION_QUALIFIER) { + keyword_completion_context ^= CF_INTERPOLATION_QUALIFIER; + } + if (_lookup_next(next)) { + if (is_token_precision(next.type)) { + keyword_completion_context ^= CF_PRECISION_MODIFIER; + } else if (is_token_datatype(next.type)) { + keyword_completion_context ^= datatype_flag; + } + } + if (temp_error) { + return ERR_PARSE_ERROR; + } +#endif // DEBUG_ENABLED } if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); - precision_defined = true; tk = _get_token(); +#ifdef DEBUG_ENABLED + if (keyword_completion_context & CF_INTERPOLATION_QUALIFIER) { + keyword_completion_context ^= CF_INTERPOLATION_QUALIFIER; + } + if (keyword_completion_context & CF_PRECISION_MODIFIER) { + keyword_completion_context ^= CF_PRECISION_MODIFIER; + } + if (_lookup_next(next)) { + if (is_token_datatype(next.type)) { + keyword_completion_context = CF_UNSPECIFIED; + } + } +#endif // DEBUG_ENABLED } if (shader->structs.has(tk.text)) { if (uniform) { - if (precision_defined) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } _set_error(vformat(RTR("The '%s' data type is not supported for uniforms."), "struct")); return ERR_PARSE_ERROR; } else { @@ -7797,6 +8086,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct type = get_token_datatype(tk.type); + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + if (type == TYPE_VOID) { _set_error(vformat(RTR("The '%s' data type is not allowed here."), "void")); return ERR_PARSE_ERROR; @@ -7807,6 +8100,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED tk = _get_token(); if (tk.type != TK_IDENTIFIER && tk.type != TK_BRACKET_OPEN) { @@ -7975,8 +8271,8 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } else if (tk.type == TK_HINT_BLACK_ALBEDO_TEXTURE) { uniform2.hint = ShaderNode::Uniform::HINT_BLACK_ALBEDO; } else if (tk.type == TK_HINT_COLOR) { - if (type != TYPE_VEC4) { - _set_error(vformat(RTR("Color hint is for '%s' only."), "vec4")); + if (type != TYPE_VEC3 && type != TYPE_VEC4) { + _set_error(vformat(RTR("Color hint is for '%s' or '%s' only."), "vec3", "vec4")); return ERR_PARSE_ERROR; } uniform2.hint = ShaderNode::Uniform::HINT_COLOR; @@ -8178,6 +8474,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_GLOBAL_SPACE; +#endif // DEBUG_ENABLED completion_type = COMPLETION_NONE; } else { // varying ShaderNode::Varying varying; @@ -8240,13 +8539,16 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (shader->structs.has(tk.text)) { - if (precision != PRECISION_DEFAULT) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } is_struct = true; struct_name = tk.text; } else { +#ifdef DEBUG_ENABLED + if (_lookup_next(next)) { + if (next.type == TK_UNIFORM) { + keyword_completion_context = CF_UNIFORM_QUALIFIER; + } + } +#endif // DEBUG_ENABLED if (!is_token_datatype(tk.type)) { _set_error(RTR("Expected constant, function, uniform or varying.")); return ERR_PARSE_ERROR; @@ -8267,9 +8569,18 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } else { type = get_token_datatype(tk.type); } + + if (precision != PRECISION_DEFAULT && _validate_precision(type, precision) != OK) { + return ERR_PARSE_ERROR; + } + prev_pos = _get_tkpos(); tk = _get_token(); +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED + bool unknown_size = false; bool fixed_array_size = false; @@ -8455,7 +8766,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - if (n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) { + if (n->type == Node::TYPE_OPERATOR && static_cast<OperatorNode *>(n)->op == OP_CALL) { _set_error(RTR("Expected constant expression.")); return ERR_PARSE_ERROR; } @@ -8506,13 +8817,24 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct constant.initializer = static_cast<ConstantNode *>(expr); } else { +#ifdef DEBUG_ENABLED + if (constant.type == DataType::TYPE_BOOL) { + keyword_completion_context = CF_BOOLEAN; + } +#endif // DEBUG_ENABLED + //variable created with assignment! must parse an expression Node *expr = _parse_and_reduce_expression(nullptr, constants); if (!expr) { return ERR_PARSE_ERROR; } - if (expr->type == Node::TYPE_OPERATOR && ((OperatorNode *)expr)->op == OP_CALL) { - OperatorNode *op = ((OperatorNode *)expr); +#ifdef DEBUG_ENABLED + if (constant.type == DataType::TYPE_BOOL) { + keyword_completion_context = CF_GLOBAL_SPACE; + } +#endif // DEBUG_ENABLED + if (expr->type == Node::TYPE_OPERATOR && static_cast<OperatorNode *>(expr)->op == OP_CALL) { + OperatorNode *op = static_cast<OperatorNode *>(expr); for (int i = 1; i < op->arguments.size(); i++) { if (!_check_node_constness(op->arguments[i])) { _set_error(vformat(RTR("Expected constant expression for argument %d of function call after '='."), i - 1)); @@ -8642,45 +8964,116 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct if (tk.type == TK_PARENTHESIS_CLOSE) { break; } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_CONST_KEYWORD | CF_FUNC_DECL_PARAM_SPEC | CF_PRECISION_MODIFIER | CF_FUNC_DECL_PARAM_TYPE; // eg. const in mediump float + + if (_lookup_next(next)) { + if (next.type == TK_CONST) { + keyword_completion_context = CF_UNSPECIFIED; + } else if (is_token_arg_qual(next.type)) { + keyword_completion_context = CF_CONST_KEYWORD; + } else if (is_token_precision(next.type)) { + keyword_completion_context = (CF_CONST_KEYWORD | CF_FUNC_DECL_PARAM_SPEC | CF_FUNC_DECL_PARAM_TYPE); + } else if (is_token_datatype(next.type)) { + keyword_completion_context = (CF_CONST_KEYWORD | CF_FUNC_DECL_PARAM_SPEC | CF_PRECISION_MODIFIER); + } + } +#endif // DEBUG_ENABLED - bool is_const = false; + bool param_is_const = false; if (tk.type == TK_CONST) { - is_const = true; + param_is_const = true; tk = _get_token(); - } +#ifdef DEBUG_ENABLED + if (keyword_completion_context & CF_CONST_KEYWORD) { + keyword_completion_context ^= CF_CONST_KEYWORD; + } - ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN; + if (_lookup_next(next)) { + if (is_token_arg_qual(next.type)) { + keyword_completion_context = CF_UNSPECIFIED; + } else if (is_token_precision(next.type)) { + keyword_completion_context = (CF_FUNC_DECL_PARAM_SPEC | CF_FUNC_DECL_PARAM_TYPE); + } else if (is_token_datatype(next.type)) { + keyword_completion_context = (CF_FUNC_DECL_PARAM_SPEC | CF_PRECISION_MODIFIER); + } + } +#endif // DEBUG_ENABLED + } - if (tk.type == TK_ARG_IN) { - qualifier = ARGUMENT_QUALIFIER_IN; - tk = _get_token(); - } else if (tk.type == TK_ARG_OUT) { - if (is_const) { - _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "out", "const")); - return ERR_PARSE_ERROR; + ArgumentQualifier param_qualifier = ARGUMENT_QUALIFIER_IN; + if (is_token_arg_qual(tk.type)) { + bool error = false; + switch (tk.type) { + case TK_ARG_IN: { + param_qualifier = ARGUMENT_QUALIFIER_IN; + } break; + case TK_ARG_OUT: { + if (param_is_const) { + _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "out", "const")); + error = true; + } + param_qualifier = ARGUMENT_QUALIFIER_OUT; + } break; + case TK_ARG_INOUT: { + if (param_is_const) { + _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "inout", "const")); + error = true; + } + param_qualifier = ARGUMENT_QUALIFIER_INOUT; + } break; + default: + error = true; + break; } - qualifier = ARGUMENT_QUALIFIER_OUT; tk = _get_token(); - } else if (tk.type == TK_ARG_INOUT) { - if (is_const) { - _set_error(vformat(RTR("The '%s' qualifier cannot be used within a function parameter declared with '%s'."), "inout", "const")); +#ifdef DEBUG_ENABLED + if (keyword_completion_context & CF_CONST_KEYWORD) { + keyword_completion_context ^= CF_CONST_KEYWORD; + } + if (keyword_completion_context & CF_FUNC_DECL_PARAM_SPEC) { + keyword_completion_context ^= CF_FUNC_DECL_PARAM_SPEC; + } + + if (_lookup_next(next)) { + if (is_token_precision(next.type)) { + keyword_completion_context = CF_FUNC_DECL_PARAM_TYPE; + } else if (is_token_datatype(next.type)) { + keyword_completion_context = CF_PRECISION_MODIFIER; + } + } +#endif // DEBUG_ENABLED + if (error) { return ERR_PARSE_ERROR; } - qualifier = ARGUMENT_QUALIFIER_INOUT; - tk = _get_token(); } - DataType ptype; - StringName pname; + DataType param_type; + StringName param_name; StringName param_struct_name; - DataPrecision pprecision = PRECISION_DEFAULT; - bool use_precision = false; + DataPrecision param_precision = PRECISION_DEFAULT; int arg_array_size = 0; if (is_token_precision(tk.type)) { - pprecision = get_token_precision(tk.type); + param_precision = get_token_precision(tk.type); tk = _get_token(); - use_precision = true; +#ifdef DEBUG_ENABLED + if (keyword_completion_context & CF_CONST_KEYWORD) { + keyword_completion_context ^= CF_CONST_KEYWORD; + } + if (keyword_completion_context & CF_FUNC_DECL_PARAM_SPEC) { + keyword_completion_context ^= CF_FUNC_DECL_PARAM_SPEC; + } + if (keyword_completion_context & CF_PRECISION_MODIFIER) { + keyword_completion_context ^= CF_PRECISION_MODIFIER; + } + + if (_lookup_next(next)) { + if (is_token_datatype(next.type)) { + keyword_completion_context = CF_UNSPECIFIED; + } + } +#endif // DEBUG_ENABLED } is_struct = false; @@ -8693,10 +9086,6 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct used_structs[param_struct_name].used = true; } #endif // DEBUG_ENABLED - if (use_precision) { - _set_error(RTR("The precision modifier cannot be used on structs.")); - return ERR_PARSE_ERROR; - } } if (!is_struct && !is_token_datatype(tk.type)) { @@ -8704,7 +9093,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - if (qualifier == ARGUMENT_QUALIFIER_OUT || qualifier == ARGUMENT_QUALIFIER_INOUT) { + if (param_qualifier == ARGUMENT_QUALIFIER_OUT || param_qualifier == ARGUMENT_QUALIFIER_INOUT) { if (is_sampler_type(get_token_datatype(tk.type))) { _set_error(RTR("Opaque types cannot be output parameters.")); return ERR_PARSE_ERROR; @@ -8712,18 +9101,24 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct } if (is_struct) { - ptype = TYPE_STRUCT; + param_type = TYPE_STRUCT; } else { - ptype = get_token_datatype(tk.type); - if (_validate_datatype(ptype) != OK) { + param_type = get_token_datatype(tk.type); + if (_validate_datatype(param_type) != OK) { return ERR_PARSE_ERROR; } - if (ptype == TYPE_VOID) { + if (param_type == TYPE_VOID) { _set_error(RTR("Void type not allowed as argument.")); return ERR_PARSE_ERROR; } } + if (param_precision != PRECISION_DEFAULT && _validate_precision(param_type, param_precision) != OK) { + return ERR_PARSE_ERROR; + } +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_UNSPECIFIED; +#endif // DEBUG_ENABLED tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { @@ -8738,32 +9133,32 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } - pname = tk.text; + param_name = tk.text; ShaderLanguage::IdentifierType itype; - if (_find_identifier(func_node->body, false, builtins, pname, (ShaderLanguage::DataType *)nullptr, &itype)) { + if (_find_identifier(func_node->body, false, builtins, param_name, (ShaderLanguage::DataType *)nullptr, &itype)) { if (itype != IDENTIFIER_FUNCTION) { - _set_redefinition_error(String(pname)); + _set_redefinition_error(String(param_name)); return ERR_PARSE_ERROR; } } - if (has_builtin(p_functions, pname)) { - _set_redefinition_error(String(pname)); + if (has_builtin(p_functions, param_name)) { + _set_redefinition_error(String(param_name)); return ERR_PARSE_ERROR; } FunctionNode::Argument arg; - arg.type = ptype; - arg.name = pname; + arg.type = param_type; + arg.name = param_name; arg.type_str = param_struct_name; - arg.precision = pprecision; - arg.qualifier = qualifier; + arg.precision = param_precision; + arg.qualifier = param_qualifier; arg.tex_argument_check = false; arg.tex_builtin_check = false; arg.tex_argument_filter = FILTER_DEFAULT; arg.tex_argument_repeat = REPEAT_DEFAULT; - arg.is_const = is_const; + arg.is_const = param_is_const; tk = _get_token(); if (tk.type == TK_BRACKET_OPEN) { @@ -8807,11 +9202,16 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct current_function = name; +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_BLOCK; +#endif // DEBUG_ENABLED Error err = _parse_block(func_node->body, builtins); if (err) { return err; } - +#ifdef DEBUG_ENABLED + keyword_completion_context = CF_GLOBAL_SPACE; +#endif // DEBUG_ENABLED if (func_node->return_type != DataType::TYPE_VOID) { BlockNode *block = func_node->body; if (_find_last_flow_op_in_block(block, FlowOperation::FLOW_OP_RETURN) != OK) { @@ -8849,7 +9249,7 @@ Error ShaderLanguage::_find_last_flow_op_in_op(ControlFlowNode *p_flow, FlowOper for (int i = p_flow->blocks.size() - 1; i >= 0; i--) { if (p_flow->blocks[i]->type == Node::TYPE_BLOCK) { - BlockNode *last_block = (BlockNode *)p_flow->blocks[i]; + BlockNode *last_block = static_cast<BlockNode *>(p_flow->blocks[i]); if (_find_last_flow_op_in_block(last_block, p_op) == OK) { found = true; break; @@ -8867,7 +9267,7 @@ Error ShaderLanguage::_find_last_flow_op_in_block(BlockNode *p_block, FlowOperat for (int i = p_block->statements.size() - 1; i >= 0; i--) { if (p_block->statements[i]->type == Node::TYPE_CONTROL_FLOW) { - ControlFlowNode *flow = (ControlFlowNode *)p_block->statements[i]; + ControlFlowNode *flow = static_cast<ControlFlowNode *>(p_block->statements[i]); if (flow->flow_op == p_op) { found = true; break; @@ -8878,7 +9278,7 @@ Error ShaderLanguage::_find_last_flow_op_in_block(BlockNode *p_block, FlowOperat } } } else if (p_block->statements[i]->type == Node::TYPE_BLOCK) { - BlockNode *block = (BlockNode *)p_block->statements[i]; + BlockNode *block = static_cast<BlockNode *>(p_block->statements[i]); if (_find_last_flow_op_in_block(block, p_op) == OK) { found = true; break; @@ -9034,7 +9434,7 @@ Error ShaderLanguage::compile(const String &p_code, const ShaderCompileInfo &p_i return OK; } -Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_info, List<ScriptCodeCompletionOption> *r_options, String &r_call_hint) { +Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_info, List<ScriptLanguage::CodeCompletionOption> *r_options, String &r_call_hint) { clear(); code = p_code; @@ -9046,6 +9446,28 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ shader = alloc_node<ShaderNode>(); _parse_shader(p_info.functions, p_info.render_modes, p_info.shader_types); +#ifdef DEBUG_ENABLED + // Adds context keywords. + if (keyword_completion_context != CF_UNSPECIFIED) { + int sz = sizeof(keyword_list) / sizeof(KeyWord); + for (int i = 0; i < sz; i++) { + if (keyword_list[i].flags == CF_UNSPECIFIED) { + break; // Ignore hint keywords (parsed below). + } + if (keyword_list[i].flags & keyword_completion_context) { + if (keyword_list[i].excluded_shader_types.has(shader_type_identifier)) { + continue; + } + if (!keyword_list[i].functions.is_empty() && !keyword_list[i].functions.has(current_function)) { + continue; + } + ScriptLanguage::CodeCompletionOption option(keyword_list[i].text, ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); + r_options->push_back(option); + } + } + } +#endif // DEBUG_ENABLED + switch (completion_type) { case COMPLETION_NONE: { //do nothing @@ -9053,7 +9475,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } break; case COMPLETION_SHADER_TYPE: { for (const String &shader_type : p_info.shader_types) { - ScriptCodeCompletionOption option(shader_type, ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option(shader_type, ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } return OK; @@ -9073,7 +9495,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (!found) { for (int j = 0; j < info.options.size(); j++) { - ScriptCodeCompletionOption option(String(info.name) + "_" + String(info.options[j]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option(String(info.name) + "_" + String(info.options[j]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } } @@ -9081,7 +9503,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ const String name = String(info.name); if (!shader->render_modes.has(name)) { - ScriptCodeCompletionOption option(name, ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option(name, ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } } @@ -9093,7 +9515,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (shader->structs.has(completion_struct)) { StructNode *node = shader->structs[completion_struct].shader_struct; for (int i = 0; i < node->members.size(); i++) { - ScriptCodeCompletionOption option(node->members[i]->name, ScriptCodeCompletionOption::KIND_MEMBER); + ScriptLanguage::CodeCompletionOption option(node->members[i]->name, ScriptLanguage::CODE_COMPLETION_KIND_MEMBER); r_options->push_back(option); } } @@ -9115,7 +9537,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (found) { continue; } - ScriptCodeCompletionOption option(E.key, ScriptCodeCompletionOption::KIND_FUNCTION); + ScriptLanguage::CodeCompletionOption option(E.key, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); r_options->push_back(option); } @@ -9124,7 +9546,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ case COMPLETION_IDENTIFIER: case COMPLETION_FUNCTION_CALL: { bool comp_ident = completion_type == COMPLETION_IDENTIFIER; - Map<String, ScriptCodeCompletionOption::Kind> matches; + Map<String, ScriptLanguage::CodeCompletionKind> matches; StringName skip_function; BlockNode *block = completion_block; @@ -9133,7 +9555,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (comp_ident) { for (const KeyValue<StringName, BlockNode::Variable> &E : block->variables) { if (E.value.line < completion_line) { - matches.insert(E.key, ScriptCodeCompletionOption::KIND_VARIABLE); + matches.insert(E.key, ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE); } } } @@ -9141,7 +9563,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (block->parent_function) { if (comp_ident) { for (int i = 0; i < block->parent_function->arguments.size(); i++) { - matches.insert(block->parent_function->arguments[i].name, ScriptCodeCompletionOption::KIND_VARIABLE); + matches.insert(block->parent_function->arguments[i].name, ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE); } } skip_function = block->parent_function->name; @@ -9152,9 +9574,9 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (comp_ident) { if (p_info.functions.has("global")) { for (const KeyValue<StringName, BuiltInInfo> &E : p_info.functions["global"].built_ins) { - ScriptCodeCompletionOption::Kind kind = ScriptCodeCompletionOption::KIND_MEMBER; + ScriptLanguage::CodeCompletionKind kind = ScriptLanguage::CODE_COMPLETION_KIND_MEMBER; if (E.value.constant) { - kind = ScriptCodeCompletionOption::KIND_CONSTANT; + kind = ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT; } matches.insert(E.key, kind); } @@ -9162,9 +9584,9 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (p_info.functions.has("constants")) { for (const KeyValue<StringName, BuiltInInfo> &E : p_info.functions["constants"].built_ins) { - ScriptCodeCompletionOption::Kind kind = ScriptCodeCompletionOption::KIND_MEMBER; + ScriptLanguage::CodeCompletionKind kind = ScriptLanguage::CODE_COMPLETION_KIND_MEMBER; if (E.value.constant) { - kind = ScriptCodeCompletionOption::KIND_CONSTANT; + kind = ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT; } matches.insert(E.key, kind); } @@ -9172,22 +9594,22 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (skip_function != StringName() && p_info.functions.has(skip_function)) { for (const KeyValue<StringName, BuiltInInfo> &E : p_info.functions[skip_function].built_ins) { - ScriptCodeCompletionOption::Kind kind = ScriptCodeCompletionOption::KIND_MEMBER; + ScriptLanguage::CodeCompletionKind kind = ScriptLanguage::CODE_COMPLETION_KIND_MEMBER; if (E.value.constant) { - kind = ScriptCodeCompletionOption::KIND_CONSTANT; + kind = ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT; } matches.insert(E.key, kind); } } for (const KeyValue<StringName, ShaderNode::Constant> &E : shader->constants) { - matches.insert(E.key, ScriptCodeCompletionOption::KIND_CONSTANT); + matches.insert(E.key, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT); } for (const KeyValue<StringName, ShaderNode::Varying> &E : shader->varyings) { - matches.insert(E.key, ScriptCodeCompletionOption::KIND_VARIABLE); + matches.insert(E.key, ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE); } for (const KeyValue<StringName, ShaderNode::Uniform> &E : shader->uniforms) { - matches.insert(E.key, ScriptCodeCompletionOption::KIND_MEMBER); + matches.insert(E.key, ScriptLanguage::CODE_COMPLETION_KIND_MEMBER); } } @@ -9195,7 +9617,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (!shader->functions[i].callable || shader->functions[i].name == skip_function) { continue; } - matches.insert(String(shader->functions[i].name), ScriptCodeCompletionOption::KIND_FUNCTION); + matches.insert(String(shader->functions[i].name), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); } int idx = 0; @@ -9203,7 +9625,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ if (stages && stages->has(skip_function)) { for (const KeyValue<StringName, StageFunctionInfo> &E : (*stages)[skip_function].stage_functions) { - matches.insert(String(E.key), ScriptCodeCompletionOption::KIND_FUNCTION); + matches.insert(String(E.key), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); } } @@ -9212,7 +9634,7 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ idx++; continue; } - matches.insert(String(builtin_func_defs[idx].name), ScriptCodeCompletionOption::KIND_FUNCTION); + matches.insert(String(builtin_func_defs[idx].name), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); idx++; } @@ -9226,15 +9648,15 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ continue; } if (builtin_func_defs[idx].tag == completion_class) { - matches.insert(String(builtin_func_defs[idx].name), ScriptCodeCompletionOption::KIND_FUNCTION); + matches.insert(String(builtin_func_defs[idx].name), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); } idx++; } } - for (const KeyValue<String, ScriptCodeCompletionOption::Kind> &E : matches) { - ScriptCodeCompletionOption option(E.key, E.value); - if (E.value == ScriptCodeCompletionOption::KIND_FUNCTION) { + for (const KeyValue<String, ScriptLanguage::CodeCompletionKind> &E : matches) { + ScriptLanguage::CodeCompletionOption option(E.key, E.value); + if (E.value == ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION) { option.insert_text += "("; } r_options->push_back(option); @@ -9483,18 +9905,18 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } for (int i = 0; i < limit; i++) { - r_options->push_back(ScriptCodeCompletionOption(String::chr(colv[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); - r_options->push_back(ScriptCodeCompletionOption(String::chr(coordv[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); - r_options->push_back(ScriptCodeCompletionOption(String::chr(coordt[i]), ScriptCodeCompletionOption::KIND_PLAIN_TEXT)); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(colv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordv[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); + r_options->push_back(ScriptLanguage::CodeCompletionOption(String::chr(coordt[i]), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT)); } } break; case COMPLETION_HINT: { - if (completion_base == DataType::TYPE_VEC4) { - ScriptCodeCompletionOption option("hint_color", ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + if (completion_base == DataType::TYPE_VEC3 || completion_base == DataType::TYPE_VEC4) { + ScriptLanguage::CodeCompletionOption option("hint_color", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } else if ((completion_base == DataType::TYPE_INT || completion_base == DataType::TYPE_FLOAT) && !completion_base_array) { - ScriptCodeCompletionOption option("hint_range", ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option("hint_range", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); if (completion_base == DataType::TYPE_INT) { option.insert_text = "hint_range(0, 100, 1)"; @@ -9530,12 +9952,12 @@ Error ShaderLanguage::complete(const String &p_code, const ShaderCompileInfo &p_ } for (int i = 0; i < options.size(); i++) { - ScriptCodeCompletionOption option(options[i], ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option(options[i], ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); r_options->push_back(option); } } if (!completion_base_array) { - ScriptCodeCompletionOption option("instance_index", ScriptCodeCompletionOption::KIND_PLAIN_TEXT); + ScriptLanguage::CodeCompletionOption option("instance_index", ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); option.insert_text = "instance_index(0)"; r_options->push_back(option); } |