Merge pull request #85487 from vnen/gdscript-static-register-annotations
GDScript: Make annotations register statically in parser
This commit is contained in:
commit
a6f806f8da
|
@ -73,8 +73,11 @@ Variant::Type GDScriptParser::get_builtin_type(const StringName &p_type) {
|
||||||
HashMap<String, String> GDScriptParser::theme_color_names;
|
HashMap<String, String> GDScriptParser::theme_color_names;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
HashMap<StringName, GDScriptParser::AnnotationInfo> GDScriptParser::valid_annotations;
|
||||||
|
|
||||||
void GDScriptParser::cleanup() {
|
void GDScriptParser::cleanup() {
|
||||||
builtin_types.clear();
|
builtin_types.clear();
|
||||||
|
valid_annotations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptParser::get_annotation_list(List<MethodInfo> *r_annotations) const {
|
void GDScriptParser::get_annotation_list(List<MethodInfo> *r_annotations) const {
|
||||||
|
@ -89,7 +92,7 @@ bool GDScriptParser::annotation_exists(const String &p_annotation_name) const {
|
||||||
|
|
||||||
GDScriptParser::GDScriptParser() {
|
GDScriptParser::GDScriptParser() {
|
||||||
// Register valid annotations.
|
// Register valid annotations.
|
||||||
// TODO: Should this be static?
|
if (unlikely(valid_annotations.is_empty())) {
|
||||||
register_annotation(MethodInfo("@tool"), AnnotationInfo::SCRIPT, &GDScriptParser::tool_annotation);
|
register_annotation(MethodInfo("@tool"), AnnotationInfo::SCRIPT, &GDScriptParser::tool_annotation);
|
||||||
register_annotation(MethodInfo("@icon", PropertyInfo(Variant::STRING, "icon_path")), AnnotationInfo::SCRIPT, &GDScriptParser::icon_annotation);
|
register_annotation(MethodInfo("@icon", PropertyInfo(Variant::STRING, "icon_path")), AnnotationInfo::SCRIPT, &GDScriptParser::icon_annotation);
|
||||||
register_annotation(MethodInfo("@static_unload"), AnnotationInfo::SCRIPT, &GDScriptParser::static_unload_annotation);
|
register_annotation(MethodInfo("@static_unload"), AnnotationInfo::SCRIPT, &GDScriptParser::static_unload_annotation);
|
||||||
|
@ -124,6 +127,7 @@ GDScriptParser::GDScriptParser() {
|
||||||
register_annotation(MethodInfo("@warning_ignore", PropertyInfo(Variant::STRING, "warning")), AnnotationInfo::CLASS | AnnotationInfo::VARIABLE | AnnotationInfo::SIGNAL | AnnotationInfo::CONSTANT | AnnotationInfo::FUNCTION | AnnotationInfo::STATEMENT, &GDScriptParser::warning_annotations, varray(), true);
|
register_annotation(MethodInfo("@warning_ignore", PropertyInfo(Variant::STRING, "warning")), AnnotationInfo::CLASS | AnnotationInfo::VARIABLE | AnnotationInfo::SIGNAL | AnnotationInfo::CONSTANT | AnnotationInfo::FUNCTION | AnnotationInfo::STATEMENT, &GDScriptParser::warning_annotations, varray(), true);
|
||||||
// Networking.
|
// Networking.
|
||||||
register_annotation(MethodInfo("@rpc", PropertyInfo(Variant::STRING, "mode"), PropertyInfo(Variant::STRING, "sync"), PropertyInfo(Variant::STRING, "transfer_mode"), PropertyInfo(Variant::INT, "transfer_channel")), AnnotationInfo::FUNCTION, &GDScriptParser::rpc_annotation, varray("authority", "call_remote", "unreliable", 0));
|
register_annotation(MethodInfo("@rpc", PropertyInfo(Variant::STRING, "mode"), PropertyInfo(Variant::STRING, "sync"), PropertyInfo(Variant::STRING, "transfer_mode"), PropertyInfo(Variant::INT, "transfer_channel")), AnnotationInfo::FUNCTION, &GDScriptParser::rpc_annotation, varray("authority", "call_remote", "unreliable", 0));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
is_ignoring_warnings = !(bool)GLOBAL_GET("debug/gdscript/warnings/enable");
|
is_ignoring_warnings = !(bool)GLOBAL_GET("debug/gdscript/warnings/enable");
|
||||||
|
|
|
@ -1370,7 +1370,7 @@ private:
|
||||||
AnnotationAction apply = nullptr;
|
AnnotationAction apply = nullptr;
|
||||||
MethodInfo info;
|
MethodInfo info;
|
||||||
};
|
};
|
||||||
HashMap<StringName, AnnotationInfo> valid_annotations;
|
static HashMap<StringName, AnnotationInfo> valid_annotations;
|
||||||
List<AnnotationNode *> annotation_stack;
|
List<AnnotationNode *> annotation_stack;
|
||||||
|
|
||||||
typedef ExpressionNode *(GDScriptParser::*ParseFunction)(ExpressionNode *p_previous_operand, bool p_can_assign);
|
typedef ExpressionNode *(GDScriptParser::*ParseFunction)(ExpressionNode *p_previous_operand, bool p_can_assign);
|
||||||
|
@ -1470,7 +1470,7 @@ private:
|
||||||
SuiteNode *parse_suite(const String &p_context, SuiteNode *p_suite = nullptr, bool p_for_lambda = false);
|
SuiteNode *parse_suite(const String &p_context, SuiteNode *p_suite = nullptr, bool p_for_lambda = false);
|
||||||
// Annotations
|
// Annotations
|
||||||
AnnotationNode *parse_annotation(uint32_t p_valid_targets);
|
AnnotationNode *parse_annotation(uint32_t p_valid_targets);
|
||||||
bool register_annotation(const MethodInfo &p_info, uint32_t p_target_kinds, AnnotationAction p_apply, const Vector<Variant> &p_default_arguments = Vector<Variant>(), bool p_is_vararg = false);
|
static bool register_annotation(const MethodInfo &p_info, uint32_t p_target_kinds, AnnotationAction p_apply, const Vector<Variant> &p_default_arguments = Vector<Variant>(), bool p_is_vararg = false);
|
||||||
bool validate_annotation_arguments(AnnotationNode *p_annotation);
|
bool validate_annotation_arguments(AnnotationNode *p_annotation);
|
||||||
void clear_unused_annotations();
|
void clear_unused_annotations();
|
||||||
bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class);
|
bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class);
|
||||||
|
|
Loading…
Reference in New Issue