You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Make annotations register statically in parser
So it only register the annotations once per run instead of doing it every time a script is parsed.
This commit is contained in:
@@ -73,8 +73,11 @@ Variant::Type GDScriptParser::get_builtin_type(const StringName &p_type) {
|
||||
HashMap<String, String> GDScriptParser::theme_color_names;
|
||||
#endif
|
||||
|
||||
HashMap<StringName, GDScriptParser::AnnotationInfo> GDScriptParser::valid_annotations;
|
||||
|
||||
void GDScriptParser::cleanup() {
|
||||
builtin_types.clear();
|
||||
valid_annotations.clear();
|
||||
}
|
||||
|
||||
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() {
|
||||
// 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("@icon", PropertyInfo(Variant::STRING, "icon_path")), AnnotationInfo::SCRIPT, &GDScriptParser::icon_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);
|
||||
// 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));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
is_ignoring_warnings = !(bool)GLOBAL_GET("debug/gdscript/warnings/enable");
|
||||
|
||||
@@ -1358,7 +1358,7 @@ private:
|
||||
AnnotationAction apply = nullptr;
|
||||
MethodInfo info;
|
||||
};
|
||||
HashMap<StringName, AnnotationInfo> valid_annotations;
|
||||
static HashMap<StringName, AnnotationInfo> valid_annotations;
|
||||
List<AnnotationNode *> annotation_stack;
|
||||
|
||||
typedef ExpressionNode *(GDScriptParser::*ParseFunction)(ExpressionNode *p_previous_operand, bool p_can_assign);
|
||||
@@ -1458,7 +1458,7 @@ private:
|
||||
SuiteNode *parse_suite(const String &p_context, SuiteNode *p_suite = nullptr, bool p_for_lambda = false);
|
||||
// Annotations
|
||||
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);
|
||||
void clear_unused_annotations();
|
||||
bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class);
|
||||
|
||||
Reference in New Issue
Block a user