@@ -80,7 +80,7 @@ bool GDScriptEditorTranslationParserPlugin::_is_constant_string(const GDScriptPa
80
80
void GDScriptEditorTranslationParserPlugin::_traverse_class (const GDScriptParser::ClassNode *p_class) {
81
81
for (int i = 0 ; i < p_class->members .size (); i++) {
82
82
const GDScriptParser::ClassNode::Member &m = p_class->members [i];
83
- // There are 7 types of Member, but only class, function and variable can contain translatable strings.
83
+ // Other member types can't contain translatable strings.
84
84
switch (m.type ) {
85
85
case GDScriptParser::ClassNode::Member::CLASS:
86
86
_traverse_class (m.m_class );
@@ -89,7 +89,11 @@ void GDScriptEditorTranslationParserPlugin::_traverse_class(const GDScriptParser
89
89
_traverse_function (m.function );
90
90
break ;
91
91
case GDScriptParser::ClassNode::Member::VARIABLE:
92
- _read_variable (m.variable );
92
+ _assess_expression (m.variable ->initializer );
93
+ if (m.variable ->property == GDScriptParser::VariableNode::PROP_INLINE) {
94
+ _traverse_function (m.variable ->setter );
95
+ _traverse_function (m.variable ->getter );
96
+ }
93
97
break ;
94
98
default :
95
99
break ;
@@ -98,11 +102,14 @@ void GDScriptEditorTranslationParserPlugin::_traverse_class(const GDScriptParser
98
102
}
99
103
100
104
void GDScriptEditorTranslationParserPlugin::_traverse_function (const GDScriptParser::FunctionNode *p_func) {
101
- _traverse_block (p_func->body );
102
- }
105
+ if (!p_func) {
106
+ return ;
107
+ }
103
108
104
- void GDScriptEditorTranslationParserPlugin::_read_variable (const GDScriptParser::VariableNode *p_var) {
105
- _assess_expression (p_var->initializer );
109
+ for (int i = 0 ; i < p_func->parameters .size (); i++) {
110
+ _assess_expression (p_func->parameters [i]->initializer );
111
+ }
112
+ _traverse_block (p_func->body );
106
113
}
107
114
108
115
void GDScriptEditorTranslationParserPlugin::_traverse_block (const GDScriptParser::SuiteNode *p_suite) {
@@ -114,53 +121,51 @@ void GDScriptEditorTranslationParserPlugin::_traverse_block(const GDScriptParser
114
121
for (int i = 0 ; i < statements.size (); i++) {
115
122
const GDScriptParser::Node *statement = statements[i];
116
123
117
- // Statements with Node type constant, break, continue, pass, breakpoint are skipped because they can't contain translatable strings.
124
+ // BREAK, BREAKPOINT, CONSTANT, CONTINUE, and PASS are skipped because they can't contain translatable strings.
118
125
switch (statement->type ) {
119
- case GDScriptParser::Node::VARIABLE:
120
- _assess_expression (static_cast <const GDScriptParser::VariableNode *>(statement)->initializer );
121
- break ;
126
+ case GDScriptParser::Node::ASSERT: {
127
+ const GDScriptParser::AssertNode *assert_node = static_cast <const GDScriptParser::AssertNode *>(statement);
128
+ _assess_expression (assert_node->condition );
129
+ _assess_expression (assert_node->message );
130
+ } break ;
131
+ case GDScriptParser::Node::ASSIGNMENT: {
132
+ _assess_assignment (static_cast <const GDScriptParser::AssignmentNode *>(statement));
133
+ } break ;
134
+ case GDScriptParser::Node::FOR: {
135
+ const GDScriptParser::ForNode *for_node = static_cast <const GDScriptParser::ForNode *>(statement);
136
+ _assess_expression (for_node->list );
137
+ _traverse_block (for_node->loop );
138
+ } break ;
122
139
case GDScriptParser::Node::IF: {
123
140
const GDScriptParser::IfNode *if_node = static_cast <const GDScriptParser::IfNode *>(statement);
124
141
_assess_expression (if_node->condition );
125
- // FIXME : if the elif logic is changed in GDScriptParser, then this probably will have to change as well. See GDScriptParser::TreePrinter::print_if().
126
142
_traverse_block (if_node->true_block );
127
143
_traverse_block (if_node->false_block );
128
- break ;
129
- }
130
- case GDScriptParser::Node::FOR: {
131
- const GDScriptParser::ForNode *for_node = static_cast <const GDScriptParser::ForNode *>(statement);
132
- _assess_expression (for_node->list );
133
- _traverse_block (for_node->loop );
134
- break ;
135
- }
136
- case GDScriptParser::Node::WHILE: {
137
- const GDScriptParser::WhileNode *while_node = static_cast <const GDScriptParser::WhileNode *>(statement);
138
- _assess_expression (while_node->condition );
139
- _traverse_block (while_node->loop );
140
- break ;
141
- }
144
+ } break ;
142
145
case GDScriptParser::Node::MATCH: {
143
146
const GDScriptParser::MatchNode *match_node = static_cast <const GDScriptParser::MatchNode *>(statement);
144
147
_assess_expression (match_node->test );
145
148
for (int j = 0 ; j < match_node->branches .size (); j++) {
149
+ _traverse_block (match_node->branches [j]->guard_body );
146
150
_traverse_block (match_node->branches [j]->block );
147
151
}
148
- break ;
149
- }
150
- case GDScriptParser::Node::RETURN:
152
+ } break ;
153
+ case GDScriptParser::Node::RETURN: {
151
154
_assess_expression (static_cast <const GDScriptParser::ReturnNode *>(statement)->return_value );
152
- break ;
153
- case GDScriptParser::Node::ASSERT:
154
- _assess_expression ((static_cast <const GDScriptParser::AssertNode *>(statement))->condition );
155
- break ;
156
- case GDScriptParser::Node::ASSIGNMENT:
157
- _assess_assignment (static_cast <const GDScriptParser::AssignmentNode *>(statement));
158
- break ;
159
- default :
155
+ } break ;
156
+ case GDScriptParser::Node::VARIABLE: {
157
+ _assess_expression (static_cast <const GDScriptParser::VariableNode *>(statement)->initializer );
158
+ } break ;
159
+ case GDScriptParser::Node::WHILE: {
160
+ const GDScriptParser::WhileNode *while_node = static_cast <const GDScriptParser::WhileNode *>(statement);
161
+ _assess_expression (while_node->condition );
162
+ _traverse_block (while_node->loop );
163
+ } break ;
164
+ default : {
160
165
if (statement->is_expression ()) {
161
166
_assess_expression (static_cast <const GDScriptParser::ExpressionNode *>(statement));
162
167
}
163
- break ;
168
+ } break ;
164
169
}
165
170
}
166
171
}
@@ -172,49 +177,66 @@ void GDScriptEditorTranslationParserPlugin::_assess_expression(const GDScriptPar
172
177
return ;
173
178
}
174
179
175
- // ExpressionNode of type await, cast, get_node, identifier, literal, preload, self, subscript, unary are ignored as they can't be CallNode
176
- // containing translation strings.
180
+ // GET_NODE, IDENTIFIER, LITERAL, PRELOAD, SELF, and TYPE are skipped because they can't contain translatable strings.
177
181
switch (p_expression->type ) {
178
182
case GDScriptParser::Node::ARRAY: {
179
183
const GDScriptParser::ArrayNode *array_node = static_cast <const GDScriptParser::ArrayNode *>(p_expression);
180
184
for (int i = 0 ; i < array_node->elements .size (); i++) {
181
185
_assess_expression (array_node->elements [i]);
182
186
}
183
- break ;
184
- }
185
- case GDScriptParser::Node::ASSIGNMENT:
187
+ } break ;
188
+ case GDScriptParser::Node::ASSIGNMENT: {
186
189
_assess_assignment (static_cast <const GDScriptParser::AssignmentNode *>(p_expression));
187
- break ;
190
+ } break ;
191
+ case GDScriptParser::Node::AWAIT: {
192
+ _assess_expression (static_cast <const GDScriptParser::AwaitNode *>(p_expression)->to_await );
193
+ } break ;
188
194
case GDScriptParser::Node::BINARY_OPERATOR: {
189
195
const GDScriptParser::BinaryOpNode *binary_op_node = static_cast <const GDScriptParser::BinaryOpNode *>(p_expression);
190
196
_assess_expression (binary_op_node->left_operand );
191
197
_assess_expression (binary_op_node->right_operand );
192
- break ;
193
- }
198
+ } break ;
194
199
case GDScriptParser::Node::CALL: {
195
200
const GDScriptParser::CallNode *call_node = static_cast <const GDScriptParser::CallNode *>(p_expression);
196
201
_extract_from_call (call_node);
197
202
for (int i = 0 ; i < call_node->arguments .size (); i++) {
198
203
_assess_expression (call_node->arguments [i]);
199
204
}
200
205
} break ;
206
+ case GDScriptParser::Node::CAST: {
207
+ _assess_expression (static_cast <const GDScriptParser::CastNode *>(p_expression)->operand );
208
+ } break ;
201
209
case GDScriptParser::Node::DICTIONARY: {
202
210
const GDScriptParser::DictionaryNode *dict_node = static_cast <const GDScriptParser::DictionaryNode *>(p_expression);
203
211
for (int i = 0 ; i < dict_node->elements .size (); i++) {
204
212
_assess_expression (dict_node->elements [i].key );
205
213
_assess_expression (dict_node->elements [i].value );
206
214
}
207
- break ;
208
- }
215
+ } break ;
216
+ case GDScriptParser::Node::LAMBDA: {
217
+ _traverse_function (static_cast <const GDScriptParser::LambdaNode *>(p_expression)->function );
218
+ } break ;
219
+ case GDScriptParser::Node::SUBSCRIPT: {
220
+ const GDScriptParser::SubscriptNode *subscript_node = static_cast <const GDScriptParser::SubscriptNode *>(p_expression);
221
+ _assess_expression (subscript_node->base );
222
+ if (!subscript_node->is_attribute ) {
223
+ _assess_expression (subscript_node->index );
224
+ }
225
+ } break ;
209
226
case GDScriptParser::Node::TERNARY_OPERATOR: {
210
227
const GDScriptParser::TernaryOpNode *ternary_op_node = static_cast <const GDScriptParser::TernaryOpNode *>(p_expression);
211
228
_assess_expression (ternary_op_node->condition );
212
229
_assess_expression (ternary_op_node->true_expr );
213
230
_assess_expression (ternary_op_node->false_expr );
214
- break ;
215
- }
216
- default :
217
- break ;
231
+ } break ;
232
+ case GDScriptParser::Node::TYPE_TEST: {
233
+ _assess_expression (static_cast <const GDScriptParser::TypeTestNode *>(p_expression)->operand );
234
+ } break ;
235
+ case GDScriptParser::Node::UNARY_OPERATOR: {
236
+ _assess_expression (static_cast <const GDScriptParser::UnaryOpNode *>(p_expression)->operand );
237
+ } break ;
238
+ default : {
239
+ } break ;
218
240
}
219
241
}
220
242
0 commit comments