-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
/
gdscript_parser.h
1602 lines (1412 loc) · 43.9 KB
/
gdscript_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************/
/* gdscript_parser.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDSCRIPT_PARSER_H
#define GDSCRIPT_PARSER_H
#include "gdscript_cache.h"
#include "gdscript_tokenizer.h"
#ifdef DEBUG_ENABLED
#include "gdscript_warning.h"
#endif
#include "core/io/resource.h"
#include "core/object/ref_counted.h"
#include "core/object/script_language.h"
#include "core/string/string_name.h"
#include "core/string/ustring.h"
#include "core/templates/hash_map.h"
#include "core/templates/list.h"
#include "core/templates/rb_map.h"
#include "core/templates/vector.h"
#include "core/variant/variant.h"
#ifdef DEBUG_ENABLED
#include "core/string/string_builder.h"
#endif
class GDScriptParser {
struct AnnotationInfo;
public:
// Forward-declare all parser nodes, to avoid ordering issues.
struct AnnotationNode;
struct ArrayNode;
struct AssertNode;
struct AssignableNode;
struct AssignmentNode;
struct AwaitNode;
struct BinaryOpNode;
struct BreakNode;
struct BreakpointNode;
struct CallNode;
struct CastNode;
struct ClassNode;
struct ConstantNode;
struct ContinueNode;
struct DictionaryNode;
struct EnumNode;
struct ExpressionNode;
struct ForNode;
struct FunctionNode;
struct GetNodeNode;
struct IdentifierNode;
struct IfNode;
struct LambdaNode;
struct LiteralNode;
struct MatchNode;
struct MatchBranchNode;
struct ParameterNode;
struct PassNode;
struct PatternNode;
struct PreloadNode;
struct ReturnNode;
struct SelfNode;
struct SignalNode;
struct SubscriptNode;
struct SuiteNode;
struct TernaryOpNode;
struct TypeNode;
struct TypeTestNode;
struct UnaryOpNode;
struct VariableNode;
struct WhileNode;
class DataType {
private:
// Private access so we can control memory management.
DataType *container_element_type = nullptr;
public:
enum Kind {
BUILTIN,
NATIVE,
SCRIPT,
CLASS, // GDScript.
ENUM, // Enumeration.
VARIANT, // Can be any type.
RESOLVING, // Currently resolving.
UNRESOLVED,
};
Kind kind = UNRESOLVED;
enum TypeSource {
UNDETECTED, // Can be any type.
INFERRED, // Has inferred type, but still dynamic.
ANNOTATED_EXPLICIT, // Has a specific type annotated.
ANNOTATED_INFERRED, // Has a static type but comes from the assigned value.
};
TypeSource type_source = UNDETECTED;
bool is_constant = false;
bool is_read_only = false;
bool is_meta_type = false;
bool is_pseudo_type = false; // For global names that can't be used standalone.
bool is_coroutine = false; // For function calls.
Variant::Type builtin_type = Variant::NIL;
StringName native_type;
StringName enum_type; // Enum name or the value name in an enum.
Ref<Script> script_type;
String script_path;
ClassNode *class_type = nullptr;
MethodInfo method_info; // For callable/signals.
HashMap<StringName, int64_t> enum_values; // For enums.
_FORCE_INLINE_ bool is_set() const { return kind != RESOLVING && kind != UNRESOLVED; }
_FORCE_INLINE_ bool is_resolving() const { return kind == RESOLVING; }
_FORCE_INLINE_ bool has_no_type() const { return type_source == UNDETECTED; }
_FORCE_INLINE_ bool is_variant() const { return kind == VARIANT || kind == RESOLVING || kind == UNRESOLVED; }
_FORCE_INLINE_ bool is_hard_type() const { return type_source > INFERRED; }
String to_string() const;
_FORCE_INLINE_ void set_container_element_type(const DataType &p_type) {
container_element_type = memnew(DataType(p_type));
}
_FORCE_INLINE_ DataType get_container_element_type() const {
ERR_FAIL_COND_V(container_element_type == nullptr, DataType());
return *container_element_type;
}
_FORCE_INLINE_ bool has_container_element_type() const {
return container_element_type != nullptr;
}
_FORCE_INLINE_ void unset_container_element_type() {
if (container_element_type) {
memdelete(container_element_type);
};
container_element_type = nullptr;
}
bool is_typed_container_type() const;
GDScriptParser::DataType get_typed_container_type() const;
bool operator==(const DataType &p_other) const {
if (type_source == UNDETECTED || p_other.type_source == UNDETECTED) {
return true; // Can be consireded equal for parsing purposes.
}
if (type_source == INFERRED || p_other.type_source == INFERRED) {
return true; // Can be consireded equal for parsing purposes.
}
if (kind != p_other.kind) {
return false;
}
switch (kind) {
case VARIANT:
return true; // All variants are the same.
case BUILTIN:
return builtin_type == p_other.builtin_type;
case NATIVE:
case ENUM: // Enums use native_type to identify the enum and its base class.
return native_type == p_other.native_type;
case SCRIPT:
return script_type == p_other.script_type;
case CLASS:
return class_type == p_other.class_type || class_type->fqcn == p_other.class_type->fqcn;
case RESOLVING:
case UNRESOLVED:
break;
}
return false;
}
bool operator!=(const DataType &p_other) const {
return !(this->operator==(p_other));
}
void operator=(const DataType &p_other) {
kind = p_other.kind;
type_source = p_other.type_source;
is_read_only = p_other.is_read_only;
is_constant = p_other.is_constant;
is_meta_type = p_other.is_meta_type;
is_pseudo_type = p_other.is_pseudo_type;
is_coroutine = p_other.is_coroutine;
builtin_type = p_other.builtin_type;
native_type = p_other.native_type;
enum_type = p_other.enum_type;
script_type = p_other.script_type;
script_path = p_other.script_path;
class_type = p_other.class_type;
method_info = p_other.method_info;
enum_values = p_other.enum_values;
unset_container_element_type();
if (p_other.has_container_element_type()) {
set_container_element_type(p_other.get_container_element_type());
}
}
DataType() = default;
DataType(const DataType &p_other) {
*this = p_other;
}
~DataType() {
unset_container_element_type();
}
};
struct ParserError {
// TODO: Do I really need a "type"?
// enum Type {
// NO_ERROR,
// EMPTY_FILE,
// CLASS_NAME_USED_TWICE,
// EXTENDS_USED_TWICE,
// EXPECTED_END_STATEMENT,
// };
// Type type = NO_ERROR;
String message;
int line = 0, column = 0;
};
#ifdef TOOLS_ENABLED
struct ClassDocData {
String brief;
String description;
Vector<Pair<String, String>> tutorials;
bool is_deprecated = false;
bool is_experimental = false;
};
struct MemberDocData {
String description;
bool is_deprecated = false;
bool is_experimental = false;
};
#endif // TOOLS_ENABLED
struct Node {
enum Type {
NONE,
ANNOTATION,
ARRAY,
ASSERT,
ASSIGNMENT,
AWAIT,
BINARY_OPERATOR,
BREAK,
BREAKPOINT,
CALL,
CAST,
CLASS,
CONSTANT,
CONTINUE,
DICTIONARY,
ENUM,
FOR,
FUNCTION,
GET_NODE,
IDENTIFIER,
IF,
LAMBDA,
LITERAL,
MATCH,
MATCH_BRANCH,
PARAMETER,
PASS,
PATTERN,
PRELOAD,
RETURN,
SELF,
SIGNAL,
SUBSCRIPT,
SUITE,
TERNARY_OPERATOR,
TYPE,
TYPE_TEST,
UNARY_OPERATOR,
VARIABLE,
WHILE,
};
Type type = NONE;
int start_line = 0, end_line = 0;
int start_column = 0, end_column = 0;
int leftmost_column = 0, rightmost_column = 0;
Node *next = nullptr;
List<AnnotationNode *> annotations;
#ifdef DEBUG_ENABLED
Vector<GDScriptWarning::Code> ignored_warnings;
#endif
DataType datatype;
virtual DataType get_datatype() const { return datatype; }
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
virtual bool is_expression() const { return false; }
virtual ~Node() {}
};
struct ExpressionNode : public Node {
// Base type for all expression kinds.
bool reduced = false;
bool is_constant = false;
Variant reduced_value;
virtual bool is_expression() const override { return true; }
virtual ~ExpressionNode() {}
protected:
ExpressionNode() {}
};
struct AnnotationNode : public Node {
StringName name;
Vector<ExpressionNode *> arguments;
Vector<Variant> resolved_arguments;
AnnotationInfo *info = nullptr;
PropertyInfo export_info;
bool is_resolved = false;
bool is_applied = false;
bool apply(GDScriptParser *p_this, Node *p_target);
bool applies_to(uint32_t p_target_kinds) const;
AnnotationNode() {
type = ANNOTATION;
}
};
struct ArrayNode : public ExpressionNode {
Vector<ExpressionNode *> elements;
ArrayNode() {
type = ARRAY;
}
};
struct AssertNode : public Node {
ExpressionNode *condition = nullptr;
ExpressionNode *message = nullptr;
AssertNode() {
type = ASSERT;
}
};
struct AssignableNode : public Node {
IdentifierNode *identifier = nullptr;
ExpressionNode *initializer = nullptr;
TypeNode *datatype_specifier = nullptr;
bool infer_datatype = false;
bool use_conversion_assign = false;
int usages = 0;
virtual ~AssignableNode() {}
protected:
AssignableNode() {}
};
struct AssignmentNode : public ExpressionNode {
// Assignment is not really an expression but it's easier to parse as if it were.
enum Operation {
OP_NONE,
OP_ADDITION,
OP_SUBTRACTION,
OP_MULTIPLICATION,
OP_DIVISION,
OP_MODULO,
OP_POWER,
OP_BIT_SHIFT_LEFT,
OP_BIT_SHIFT_RIGHT,
OP_BIT_AND,
OP_BIT_OR,
OP_BIT_XOR,
};
Operation operation = OP_NONE;
Variant::Operator variant_op = Variant::OP_MAX;
ExpressionNode *assignee = nullptr;
ExpressionNode *assigned_value = nullptr;
bool use_conversion_assign = false;
AssignmentNode() {
type = ASSIGNMENT;
}
};
struct AwaitNode : public ExpressionNode {
ExpressionNode *to_await = nullptr;
AwaitNode() {
type = AWAIT;
}
};
struct BinaryOpNode : public ExpressionNode {
enum OpType {
OP_ADDITION,
OP_SUBTRACTION,
OP_MULTIPLICATION,
OP_DIVISION,
OP_MODULO,
OP_POWER,
OP_BIT_LEFT_SHIFT,
OP_BIT_RIGHT_SHIFT,
OP_BIT_AND,
OP_BIT_OR,
OP_BIT_XOR,
OP_LOGIC_AND,
OP_LOGIC_OR,
OP_CONTENT_TEST,
OP_COMP_EQUAL,
OP_COMP_NOT_EQUAL,
OP_COMP_LESS,
OP_COMP_LESS_EQUAL,
OP_COMP_GREATER,
OP_COMP_GREATER_EQUAL,
};
OpType operation = OpType::OP_ADDITION;
Variant::Operator variant_op = Variant::OP_MAX;
ExpressionNode *left_operand = nullptr;
ExpressionNode *right_operand = nullptr;
BinaryOpNode() {
type = BINARY_OPERATOR;
}
};
struct BreakNode : public Node {
BreakNode() {
type = BREAK;
}
};
struct BreakpointNode : public Node {
BreakpointNode() {
type = BREAKPOINT;
}
};
struct CallNode : public ExpressionNode {
ExpressionNode *callee = nullptr;
Vector<ExpressionNode *> arguments;
StringName function_name;
bool is_super = false;
CallNode() {
type = CALL;
}
Type get_callee_type() const {
if (callee == nullptr) {
return Type::NONE;
} else {
return callee->type;
}
}
};
struct CastNode : public ExpressionNode {
ExpressionNode *operand = nullptr;
TypeNode *cast_type = nullptr;
CastNode() {
type = CAST;
}
};
struct EnumNode : public Node {
struct Value {
IdentifierNode *identifier = nullptr;
ExpressionNode *custom_value = nullptr;
EnumNode *parent_enum = nullptr;
int index = -1;
bool resolved = false;
int64_t value = 0;
int line = 0;
int leftmost_column = 0;
int rightmost_column = 0;
#ifdef TOOLS_ENABLED
MemberDocData doc_data;
#endif // TOOLS_ENABLED
};
IdentifierNode *identifier = nullptr;
Vector<Value> values;
Variant dictionary;
#ifdef TOOLS_ENABLED
MemberDocData doc_data;
#endif // TOOLS_ENABLED
EnumNode() {
type = ENUM;
}
};
struct ClassNode : public Node {
struct Member {
enum Type {
UNDEFINED,
CLASS,
CONSTANT,
FUNCTION,
SIGNAL,
VARIABLE,
ENUM,
ENUM_VALUE, // For unnamed enums.
GROUP, // For member grouping.
};
Type type = UNDEFINED;
union {
ClassNode *m_class = nullptr;
ConstantNode *constant;
FunctionNode *function;
SignalNode *signal;
VariableNode *variable;
EnumNode *m_enum;
AnnotationNode *annotation;
};
EnumNode::Value enum_value;
String get_name() const {
switch (type) {
case UNDEFINED:
return "<undefined member>";
case CLASS:
// All class-type members have an id.
return m_class->identifier->name;
case CONSTANT:
return constant->identifier->name;
case FUNCTION:
return function->identifier->name;
case SIGNAL:
return signal->identifier->name;
case VARIABLE:
return variable->identifier->name;
case ENUM:
// All enum-type members have an id.
return m_enum->identifier->name;
case ENUM_VALUE:
return enum_value.identifier->name;
case GROUP:
return annotation->export_info.name;
}
return "";
}
String get_type_name() const {
switch (type) {
case UNDEFINED:
return "???";
case CLASS:
return "class";
case CONSTANT:
return "constant";
case FUNCTION:
return "function";
case SIGNAL:
return "signal";
case VARIABLE:
return "variable";
case ENUM:
return "enum";
case ENUM_VALUE:
return "enum value";
case GROUP:
return "group";
}
return "";
}
int get_line() const {
switch (type) {
case CLASS:
return m_class->start_line;
case CONSTANT:
return constant->start_line;
case FUNCTION:
return function->start_line;
case VARIABLE:
return variable->start_line;
case ENUM_VALUE:
return enum_value.line;
case ENUM:
return m_enum->start_line;
case SIGNAL:
return signal->start_line;
case GROUP:
return annotation->start_line;
case UNDEFINED:
ERR_FAIL_V_MSG(-1, "Reaching undefined member type.");
}
ERR_FAIL_V_MSG(-1, "Reaching unhandled type.");
}
DataType get_datatype() const {
switch (type) {
case CLASS:
return m_class->get_datatype();
case CONSTANT:
return constant->get_datatype();
case FUNCTION:
return function->get_datatype();
case VARIABLE:
return variable->get_datatype();
case ENUM:
return m_enum->get_datatype();
case ENUM_VALUE:
return enum_value.identifier->get_datatype();
case SIGNAL:
return signal->get_datatype();
case GROUP:
return DataType();
case UNDEFINED:
return DataType();
}
ERR_FAIL_V_MSG(DataType(), "Reaching unhandled type.");
}
Node *get_source_node() const {
switch (type) {
case CLASS:
return m_class;
case CONSTANT:
return constant;
case FUNCTION:
return function;
case VARIABLE:
return variable;
case ENUM:
return m_enum;
case ENUM_VALUE:
return enum_value.identifier;
case SIGNAL:
return signal;
case GROUP:
return annotation;
case UNDEFINED:
return nullptr;
}
ERR_FAIL_V_MSG(nullptr, "Reaching unhandled type.");
}
Member() {}
Member(ClassNode *p_class) {
type = CLASS;
m_class = p_class;
}
Member(ConstantNode *p_constant) {
type = CONSTANT;
constant = p_constant;
}
Member(VariableNode *p_variable) {
type = VARIABLE;
variable = p_variable;
}
Member(SignalNode *p_signal) {
type = SIGNAL;
signal = p_signal;
}
Member(FunctionNode *p_function) {
type = FUNCTION;
function = p_function;
}
Member(EnumNode *p_enum) {
type = ENUM;
m_enum = p_enum;
}
Member(const EnumNode::Value &p_enum_value) {
type = ENUM_VALUE;
enum_value = p_enum_value;
}
Member(AnnotationNode *p_annotation) {
type = GROUP;
annotation = p_annotation;
}
};
IdentifierNode *identifier = nullptr;
String icon_path;
Vector<Member> members;
HashMap<StringName, int> members_indices;
ClassNode *outer = nullptr;
bool extends_used = false;
bool onready_used = false;
bool has_static_data = false;
bool annotated_static_unload = false;
String extends_path;
Vector<IdentifierNode *> extends; // List for indexing: extends A.B.C
DataType base_type;
String fqcn; // Fully-qualified class name. Identifies uniquely any class in the project.
#ifdef TOOLS_ENABLED
ClassDocData doc_data;
// EnumValue docs are parsed after itself, so we need a method to add/modify the doc property later.
void set_enum_value_doc_data(const StringName &p_name, const MemberDocData &p_doc_data) {
ERR_FAIL_INDEX(members_indices[p_name], members.size());
members.write[members_indices[p_name]].enum_value.doc_data = p_doc_data;
}
#endif // TOOLS_ENABLED
bool resolved_interface = false;
bool resolved_body = false;
Member get_member(const StringName &p_name) const {
return members[members_indices[p_name]];
}
bool has_member(const StringName &p_name) const {
return members_indices.has(p_name);
}
bool has_function(const StringName &p_name) const {
return has_member(p_name) && members[members_indices[p_name]].type == Member::FUNCTION;
}
template <class T>
void add_member(T *p_member_node) {
members_indices[p_member_node->identifier->name] = members.size();
members.push_back(Member(p_member_node));
}
void add_member(const EnumNode::Value &p_enum_value) {
members_indices[p_enum_value.identifier->name] = members.size();
members.push_back(Member(p_enum_value));
}
void add_member_group(AnnotationNode *p_annotation_node) {
// Avoid name conflict. See GH-78252.
StringName name = vformat("@group_%d_%s", members.size(), p_annotation_node->export_info.name);
members_indices[name] = members.size();
members.push_back(Member(p_annotation_node));
}
ClassNode() {
type = CLASS;
}
};
struct ConstantNode : public AssignableNode {
#ifdef TOOLS_ENABLED
MemberDocData doc_data;
#endif // TOOLS_ENABLED
ConstantNode() {
type = CONSTANT;
}
};
struct ContinueNode : public Node {
ContinueNode() {
type = CONTINUE;
}
};
struct DictionaryNode : public ExpressionNode {
struct Pair {
ExpressionNode *key = nullptr;
ExpressionNode *value = nullptr;
};
Vector<Pair> elements;
enum Style {
LUA_TABLE,
PYTHON_DICT,
};
Style style = PYTHON_DICT;
DictionaryNode() {
type = DICTIONARY;
}
};
struct ForNode : public Node {
IdentifierNode *variable = nullptr;
ExpressionNode *list = nullptr;
SuiteNode *loop = nullptr;
ForNode() {
type = FOR;
}
};
struct FunctionNode : public Node {
IdentifierNode *identifier = nullptr;
Vector<ParameterNode *> parameters;
HashMap<StringName, int> parameters_indices;
TypeNode *return_type = nullptr;
SuiteNode *body = nullptr;
bool is_static = false;
bool is_coroutine = false;
Variant rpc_config;
MethodInfo info;
LambdaNode *source_lambda = nullptr;
#ifdef TOOLS_ENABLED
Vector<Variant> default_arg_values;
MemberDocData doc_data;
#endif // TOOLS_ENABLED
bool resolved_signature = false;
bool resolved_body = false;
FunctionNode() {
type = FUNCTION;
}
};
struct GetNodeNode : public ExpressionNode {
String full_path;
#ifdef DEBUG_ENABLED
bool use_dollar = true;
#endif
GetNodeNode() {
type = GET_NODE;
}
};
struct IdentifierNode : public ExpressionNode {
StringName name;
#ifdef DEBUG_ENABLED
SuiteNode *suite = nullptr; // The block in which the identifier is used.
#endif
enum Source {
UNDEFINED_SOURCE,
FUNCTION_PARAMETER,
LOCAL_VARIABLE,
LOCAL_CONSTANT,
LOCAL_ITERATOR, // `for` loop iterator.
LOCAL_BIND, // Pattern bind.
MEMBER_VARIABLE,
MEMBER_CONSTANT,
MEMBER_FUNCTION,
MEMBER_SIGNAL,
MEMBER_CLASS,
INHERITED_VARIABLE,
STATIC_VARIABLE,
};
Source source = UNDEFINED_SOURCE;
union {
ParameterNode *parameter_source = nullptr;
ConstantNode *constant_source;
VariableNode *variable_source;
IdentifierNode *bind_source;
};
FunctionNode *source_function = nullptr;
int usages = 0; // Useful for binds/iterator variable.
IdentifierNode() {
type = IDENTIFIER;
}
};
struct IfNode : public Node {
ExpressionNode *condition = nullptr;
SuiteNode *true_block = nullptr;
SuiteNode *false_block = nullptr;
IfNode() {
type = IF;
}
};
struct LambdaNode : public ExpressionNode {
FunctionNode *function = nullptr;
FunctionNode *parent_function = nullptr;
Vector<IdentifierNode *> captures;
HashMap<StringName, int> captures_indices;
bool use_self = false;
bool has_name() const {
return function && function->identifier;
}
LambdaNode() {
type = LAMBDA;
}
};
struct LiteralNode : public ExpressionNode {
Variant value;
LiteralNode() {
type = LITERAL;
}
};
struct MatchNode : public Node {
ExpressionNode *test = nullptr;
Vector<MatchBranchNode *> branches;
MatchNode() {
type = MATCH;
}
};
struct MatchBranchNode : public Node {
Vector<PatternNode *> patterns;
SuiteNode *block = nullptr;
bool has_wildcard = false;
MatchBranchNode() {
type = MATCH_BRANCH;
}
};
struct ParameterNode : public AssignableNode {
ParameterNode() {
type = PARAMETER;
}
};
struct PassNode : public Node {
PassNode() {
type = PASS;
}
};
struct PatternNode : public Node {
enum Type {
PT_LITERAL,
PT_EXPRESSION,
PT_BIND,
PT_ARRAY,
PT_DICTIONARY,
PT_REST,
PT_WILDCARD,
};
Type pattern_type = PT_LITERAL;
union {
LiteralNode *literal = nullptr;
IdentifierNode *bind;
ExpressionNode *expression;
};
Vector<PatternNode *> array;
bool rest_used = false; // For array/dict patterns.
struct Pair {
ExpressionNode *key = nullptr;
PatternNode *value_pattern = nullptr;
};
Vector<Pair> dictionary;
HashMap<StringName, IdentifierNode *> binds;
bool has_bind(const StringName &p_name);
IdentifierNode *get_bind(const StringName &p_name);
PatternNode() {
type = PATTERN;
}
};
struct PreloadNode : public ExpressionNode {
ExpressionNode *path = nullptr;
String resolved_path;