diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 54bb152f7f0..a4b6f461002 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4064,7 +4064,7 @@ bool GDScriptParser::validate_annotation_arguments(AnnotationNode *p_annotation) return true; } -bool GDScriptParser::tool_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::tool_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { #ifdef DEBUG_ENABLED if (_is_tool) { push_error(R"("@tool" annotation can only be used once.)", p_annotation); @@ -4075,7 +4075,7 @@ bool GDScriptParser::tool_annotation(const AnnotationNode *p_annotation, Node *p return true; } -bool GDScriptParser::icon_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::icon_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_target->type != Node::CLASS, false, R"("@icon" annotation can only be applied to classes.)"); ERR_FAIL_COND_V(p_annotation->resolved_arguments.is_empty(), false); @@ -4106,7 +4106,7 @@ bool GDScriptParser::icon_annotation(const AnnotationNode *p_annotation, Node *p return true; } -bool GDScriptParser::onready_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::onready_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_target->type != Node::VARIABLE, false, R"("@onready" annotation can only be applied to class variables.)"); if (current_class && !ClassDB::is_parent_class(current_class->get_datatype().native_type, SNAME("Node"))) { @@ -4239,7 +4239,7 @@ static StringName _find_narrowest_native_or_global_class(const GDScriptParser::D } template -bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::export_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_target->type != Node::VARIABLE, false, vformat(R"("%s" annotation can only be applied to variables.)", p_annotation->name)); ERR_FAIL_NULL_V(p_class, false); @@ -4478,7 +4478,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node // For `@export_storage` and `@export_custom`, there is no need to check the variable type, argument values, // or handle array exports in a special way, so they are implemented as separate methods. -bool GDScriptParser::export_storage_annotation(const AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) { +bool GDScriptParser::export_storage_annotation(AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_node->type != Node::VARIABLE, false, vformat(R"("%s" annotation can only be applied to variables.)", p_annotation->name)); VariableNode *variable = static_cast(p_node); @@ -4500,7 +4500,7 @@ bool GDScriptParser::export_storage_annotation(const AnnotationNode *p_annotatio return true; } -bool GDScriptParser::export_custom_annotation(const AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) { +bool GDScriptParser::export_custom_annotation(AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_node->type != Node::VARIABLE, false, vformat(R"("%s" annotation can only be applied to variables.)", p_annotation->name)); ERR_FAIL_COND_V_MSG(p_annotation->resolved_arguments.size() < 2, false, R"(Annotation "@export_custom" requires 2 arguments.)"); @@ -4529,31 +4529,29 @@ bool GDScriptParser::export_custom_annotation(const AnnotationNode *p_annotation } template -bool GDScriptParser::export_group_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { - AnnotationNode *annotation = const_cast(p_annotation); - - if (annotation->resolved_arguments.is_empty()) { +bool GDScriptParser::export_group_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { + if (p_annotation->resolved_arguments.is_empty()) { return false; } - annotation->export_info.name = annotation->resolved_arguments[0]; + p_annotation->export_info.name = p_annotation->resolved_arguments[0]; switch (t_usage) { case PROPERTY_USAGE_CATEGORY: { - annotation->export_info.usage = t_usage; + p_annotation->export_info.usage = t_usage; } break; case PROPERTY_USAGE_GROUP: { - annotation->export_info.usage = t_usage; - if (annotation->resolved_arguments.size() == 2) { - annotation->export_info.hint_string = annotation->resolved_arguments[1]; + p_annotation->export_info.usage = t_usage; + if (p_annotation->resolved_arguments.size() == 2) { + p_annotation->export_info.hint_string = p_annotation->resolved_arguments[1]; } } break; case PROPERTY_USAGE_SUBGROUP: { - annotation->export_info.usage = t_usage; - if (annotation->resolved_arguments.size() == 2) { - annotation->export_info.hint_string = annotation->resolved_arguments[1]; + p_annotation->export_info.usage = t_usage; + if (p_annotation->resolved_arguments.size() == 2) { + p_annotation->export_info.hint_string = p_annotation->resolved_arguments[1]; } } break; } @@ -4561,7 +4559,7 @@ bool GDScriptParser::export_group_annotations(const AnnotationNode *p_annotation return true; } -bool GDScriptParser::warning_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::warning_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { #ifndef DEBUG_ENABLED // Only available in debug builds. return true; @@ -4636,7 +4634,7 @@ bool GDScriptParser::warning_annotations(const AnnotationNode *p_annotation, Nod #endif // DEBUG_ENABLED } -bool GDScriptParser::rpc_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::rpc_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_target->type != Node::FUNCTION, false, vformat(R"("%s" annotation can only be applied to functions.)", p_annotation->name)); FunctionNode *function = static_cast(p_target); @@ -4697,7 +4695,7 @@ bool GDScriptParser::rpc_annotation(const AnnotationNode *p_annotation, Node *p_ return true; } -bool GDScriptParser::static_unload_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { +bool GDScriptParser::static_unload_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { ERR_FAIL_COND_V_MSG(p_target->type != Node::CLASS, false, vformat(R"("%s" annotation can only be applied to classes.)", p_annotation->name)); ClassNode *class_node = static_cast(p_target); if (class_node->annotated_static_unload) { diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 60ee4776566..eb03d6a0d49 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1371,7 +1371,7 @@ private: bool in_lambda = false; bool lambda_ended = false; // Marker for when a lambda ends, to apply an end of statement if needed. - typedef bool (GDScriptParser::*AnnotationAction)(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + typedef bool (GDScriptParser::*AnnotationAction)(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); struct AnnotationInfo { enum TargetKind { NONE = 0, @@ -1493,18 +1493,18 @@ private: static bool register_annotation(const MethodInfo &p_info, uint32_t p_target_kinds, AnnotationAction p_apply, const Vector &p_default_arguments = Vector(), bool p_is_vararg = false); bool validate_annotation_arguments(AnnotationNode *p_annotation); void clear_unused_annotations(); - bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool icon_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool onready_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool tool_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool icon_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool onready_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); template - bool export_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool export_storage_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool export_custom_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool export_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool export_storage_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool export_custom_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); template - bool export_group_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool warning_annotations(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool rpc_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); - bool static_unload_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool export_group_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool warning_annotations(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool rpc_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); + bool static_unload_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); // Statements. Node *parse_statement(); VariableNode *parse_variable(bool p_is_static);