-
-
Notifications
You must be signed in to change notification settings - Fork 25.2k
GDScript: Implement soft access restriction for members prefixed with _ and __ (as warning by default)
#98557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
05656ea
d117ccd
79f30e9
da0b687
76273f9
9e92c8d
15d6657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,8 @@ GDScriptParser::GDScriptParser() { | |
| register_annotation(MethodInfo("@static_unload"), AnnotationInfo::SCRIPT, &GDScriptParser::static_unload_annotation); | ||
| // Onready annotation. | ||
| register_annotation(MethodInfo("@onready"), AnnotationInfo::VARIABLE, &GDScriptParser::onready_annotation); | ||
|
|
||
| // register_annotation(MethodInfo("@virtual"), AnnotationInfo::FUNCTION, &GDScriptParser::virtual_annotation); | ||
|
Comment on lines
101
to
102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
| // Export annotations. | ||
| register_annotation(MethodInfo("@export"), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NONE, Variant::NIL>); | ||
| register_annotation(MethodInfo("@export_enum", PropertyInfo(Variant::STRING, "names")), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_ENUM, Variant::NIL>, varray(), true); | ||
|
|
@@ -4282,6 +4284,16 @@ bool GDScriptParser::onready_annotation(AnnotationNode *p_annotation, Node *p_ta | |
| current_class->onready_used = true; | ||
| return true; | ||
| } | ||
| // bool GDScriptParser::virtual_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class) { | ||
| // ERR_FAIL_COND_V_MSG(p_target->type != Node::FUNCTION, false, R"("@virtual" annotation can only be applied to class methods.)"); | ||
| // FunctionNode *method = static_cast<FunctionNode *>(p_target); | ||
| // if (method->is_virtual) { | ||
| // push_error(R"("@virtual" annotation can only be applied to a method once.)", p_annotation); | ||
| // return false; | ||
| // } | ||
| // method->is_virtual = true; | ||
| // return true; | ||
| // } | ||
|
Comment on lines
4287
to
4296
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
|
|
||
| static String _get_annotation_error_string(const StringName &p_annotation_name, const Vector<Variant::Type> &p_expected_types, const GDScriptParser::DataType &p_provided_type) { | ||
| Vector<String> types; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,8 +336,8 @@ class GDScriptParser { | |
| VARIABLE, | ||
| WHILE, | ||
| }; | ||
|
|
||
| Type type = NONE; | ||
|
|
||
|
Comment on lines
339
to
340
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reset this change |
||
| int start_line = 0, end_line = 0; | ||
| int start_column = 0, end_column = 0; | ||
| int leftmost_column = 0, rightmost_column = 0; | ||
|
|
@@ -796,6 +796,20 @@ class GDScriptParser { | |
| members.push_back(Member(p_annotation_node)); | ||
| } | ||
|
|
||
| Vector<StringName> get_super_class_fqcns() const { | ||
| Vector<StringName> ret; | ||
|
|
||
| const ClassNode *iterated_class = base_type.class_type; | ||
| while (iterated_class) { | ||
| if (iterated_class->datatype.kind == DataType::SCRIPT || iterated_class->datatype.kind == DataType::CLASS) { | ||
| ret.append(iterated_class->fqcn); | ||
| } | ||
| iterated_class = iterated_class->base_type.class_type; | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| ClassNode() { | ||
| type = CLASS; | ||
| } | ||
|
|
@@ -855,6 +869,7 @@ class GDScriptParser { | |
| SuiteNode *body = nullptr; | ||
| bool is_static = false; // For lambdas it's determined in the analyzer. | ||
| bool is_coroutine = false; | ||
| // bool is_virtual = false; | ||
| Variant rpc_config; | ||
| MethodInfo info; | ||
| LambdaNode *source_lambda = nullptr; | ||
|
|
@@ -902,6 +917,12 @@ class GDScriptParser { | |
| }; | ||
| Source source = UNDEFINED_SOURCE; | ||
|
|
||
| enum IdentifierAccess { | ||
| ACCESS_PUBLIC, | ||
| ACCESS_PRIVATE, | ||
| ACCESS_PROTECTED, | ||
| }; | ||
|
|
||
| union { | ||
| ParameterNode *parameter_source = nullptr; | ||
| IdentifierNode *bind_source; | ||
|
|
@@ -916,6 +937,17 @@ class GDScriptParser { | |
|
|
||
| int usages = 0; // Useful for binds/iterator variable. | ||
|
|
||
| IdentifierAccess get_access() const { | ||
| String str_name = String(name); | ||
| if (str_name.begins_with("__")) { | ||
| return ACCESS_PRIVATE; | ||
| } else if (str_name.begins_with("_")) { | ||
| return ACCESS_PROTECTED; | ||
| } else { | ||
| return ACCESS_PUBLIC; | ||
| } | ||
| } | ||
|
|
||
| IdentifierNode() { | ||
| type = IDENTIFIER; | ||
| } | ||
|
|
@@ -1509,6 +1541,7 @@ class GDScriptParser { | |
| bool icon_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); | ||
| bool static_unload_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); | ||
| bool onready_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); | ||
| // bool virtual_annotation(AnnotationNode *p_annotation, Node *p_target, ClassNode *p_class); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
| template <PropertyHint t_hint, Variant::Type t_type> | ||
| 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); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.