From 78d718904091dac394aca05e65ec71c4368674a8 Mon Sep 17 00:00:00 2001 From: Lazy-Rabbit-2001 <2733679597@qq.com> Date: Wed, 16 Oct 2024 23:17:19 +0800 Subject: [PATCH] finished transplatation --- modules/gdscript/editor/gdscript_docgen.cpp | 4 ++++ modules/gdscript/gdscript_analyzer.cpp | 6 +++++- modules/gdscript/gdscript_parser.cpp | 2 +- modules/gdscript/gdscript_parser.h | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/gdscript/editor/gdscript_docgen.cpp b/modules/gdscript/editor/gdscript_docgen.cpp index c5fa0b1e6f..c5a9f8774d 100644 --- a/modules/gdscript/editor/gdscript_docgen.cpp +++ b/modules/gdscript/editor/gdscript_docgen.cpp @@ -477,6 +477,10 @@ void GDScriptDocGen::_generate_docs(GDScript *p_script, const GDP::ClassNode *p_ case GDP::ClassNode::Member::VARIABLE: { const GDP::VariableNode *m_var = member.variable; + if (!m_var->exported && m_var->access_restriction != GDP::Node::ACCESS_RESTRICTION_PUBLIC) { + break; + } + const StringName &var_name = m_var->identifier->name; p_script->member_lines[var_name] = m_var->start_line; diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index c0f5939f59..81cfdf8c80 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -324,7 +324,7 @@ bool GDScriptAnalyzer::execute_access_protection(const GDScriptParser::ClassNode return false; } if (member_node->access_restriction == GDScriptParser::Node::ACCESS_RESTRICTION_PROTECTED && is_from_non_derived) { - push_error(vformat(R"(Could not access external %s "%s", because it is protected by class "%s".)", is_from_non_derived ? "external" : "super", member_type, p_member.get_name(), p_super_class->fqcn), p_source); + push_error(vformat(R"(Could not access external %s "%s", because it is protected by class "%s".)", member_type, p_member.get_name(), p_super_class->fqcn), p_source); return false; } } @@ -4108,6 +4108,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->reduced_value = member.constant->initializer->reduced_value; p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT; p_identifier->constant_source = member.constant; + execute_access_protection(member, parser->current_class, script_class, p_identifier); return; } @@ -4133,6 +4134,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->source = member.variable->is_static ? GDScriptParser::IdentifierNode::STATIC_VARIABLE : GDScriptParser::IdentifierNode::MEMBER_VARIABLE; p_identifier->variable_source = member.variable; member.variable->usages += 1; + execute_access_protection(member, parser->current_class, script_class, p_identifier); return; } } break; @@ -4143,6 +4145,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_SIGNAL; p_identifier->signal_source = member.signal; member.signal->usages += 1; + execute_access_protection(member, parser->current_class, script_class, p_identifier); return; } } break; @@ -4153,6 +4156,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_FUNCTION; p_identifier->function_source = member.function; p_identifier->function_source_is_static = member.function->is_static; + execute_access_protection(member, parser->current_class, script_class, p_identifier); return; } } break; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index b1be193818..bbc41d499a 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4229,7 +4229,7 @@ bool GDScriptParser::access_protected_annotation(AnnotationNode *p_annotation, N AssignableNode *member = static_cast(p_target); if (member->access_restriction == Node::ACCESS_RESTRICTION_PROTECTED) { - push_error(vformat(R"(@private" annotation can only be used once per private variable)"), p_annotation); + push_error(vformat(R"(@protected" annotation can only be used once per protected variable)"), p_annotation); return false; } diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index d6e7681c7c..fd861c2452 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -814,7 +814,7 @@ class GDScriptParser { } bool is_derived_from(const StringName &p_super_class_name) const { for (IdentifierNode *E : extends) { - if (identifier->name == p_super_class_name || p_super_class_name == identifier->name) { + if (E->name == p_super_class_name || p_super_class_name == E->name) { return true; } }