gdscript_parser.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. /*************************************************************************/
  2. /* gdscript_parser.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GDSCRIPT_PARSER_H
  31. #define GDSCRIPT_PARSER_H
  32. #include "core/hash_map.h"
  33. #include "core/io/multiplayer_api.h"
  34. #include "core/list.h"
  35. #include "core/map.h"
  36. #include "core/reference.h"
  37. #include "core/resource.h"
  38. #include "core/script_language.h"
  39. #include "core/string_name.h"
  40. #include "core/ustring.h"
  41. #include "core/variant.h"
  42. #include "core/vector.h"
  43. #include "gdscript_cache.h"
  44. #include "gdscript_functions.h"
  45. #include "gdscript_tokenizer.h"
  46. #ifdef DEBUG_ENABLED
  47. #include "core/string_builder.h"
  48. #include "gdscript_warning.h"
  49. #endif // DEBUG_ENABLED
  50. class GDScriptParser {
  51. struct AnnotationInfo;
  52. public:
  53. // Forward-declare all parser nodes, to avoid ordering issues.
  54. struct AnnotationNode;
  55. struct ArrayNode;
  56. struct AssertNode;
  57. struct AssignmentNode;
  58. struct AwaitNode;
  59. struct BinaryOpNode;
  60. struct BreakNode;
  61. struct BreakpointNode;
  62. struct CallNode;
  63. struct CastNode;
  64. struct ClassNode;
  65. struct ConstantNode;
  66. struct ContinueNode;
  67. struct DictionaryNode;
  68. struct EnumNode;
  69. struct ExpressionNode;
  70. struct ForNode;
  71. struct FunctionNode;
  72. struct GetNodeNode;
  73. struct IdentifierNode;
  74. struct IfNode;
  75. struct LiteralNode;
  76. struct MatchNode;
  77. struct MatchBranchNode;
  78. struct ParameterNode;
  79. struct PassNode;
  80. struct PatternNode;
  81. struct PreloadNode;
  82. struct ReturnNode;
  83. struct SelfNode;
  84. struct SignalNode;
  85. struct SubscriptNode;
  86. struct SuiteNode;
  87. struct TernaryOpNode;
  88. struct TypeNode;
  89. struct UnaryOpNode;
  90. struct VariableNode;
  91. struct WhileNode;
  92. struct DataType {
  93. enum Kind {
  94. BUILTIN,
  95. NATIVE,
  96. SCRIPT,
  97. CLASS, // GDScript.
  98. ENUM, // Full enumeration.
  99. ENUM_VALUE, // Value from enumeration.
  100. VARIANT, // Can be any type.
  101. UNRESOLVED,
  102. // TODO: Enum
  103. };
  104. Kind kind = UNRESOLVED;
  105. enum TypeSource {
  106. UNDETECTED, // Can be any type.
  107. INFERRED, // Has inferred type, but still dynamic.
  108. ANNOTATED_EXPLICIT, // Has a specific type annotated.
  109. ANNOTATED_INFERRED, // Has a static type but comes from the assigned value.
  110. };
  111. TypeSource type_source = UNDETECTED;
  112. bool is_constant = false;
  113. bool is_meta_type = false;
  114. bool is_coroutine = false; // For function calls.
  115. Variant::Type builtin_type = Variant::NIL;
  116. StringName native_type;
  117. StringName enum_type; // Enum name or the value name in an enum.
  118. Ref<Script> script_type;
  119. String script_path;
  120. ClassNode *class_type = nullptr;
  121. MethodInfo method_info; // For callable/signals.
  122. HashMap<StringName, int> enum_values; // For enums.
  123. _FORCE_INLINE_ bool is_set() const { return kind != UNRESOLVED; }
  124. _FORCE_INLINE_ bool has_no_type() const { return type_source == UNDETECTED; }
  125. _FORCE_INLINE_ bool is_variant() const { return kind == VARIANT || kind == UNRESOLVED; }
  126. _FORCE_INLINE_ bool is_hard_type() const { return type_source > INFERRED; }
  127. String to_string() const;
  128. bool operator==(const DataType &p_other) const {
  129. if (type_source == UNDETECTED || p_other.type_source == UNDETECTED) {
  130. return true; // Can be consireded equal for parsing purposes.
  131. }
  132. if (type_source == INFERRED || p_other.type_source == INFERRED) {
  133. return true; // Can be consireded equal for parsing purposes.
  134. }
  135. if (kind != p_other.kind) {
  136. return false;
  137. }
  138. switch (kind) {
  139. case VARIANT:
  140. return true; // All variants are the same.
  141. case BUILTIN:
  142. return builtin_type == p_other.builtin_type;
  143. case NATIVE:
  144. case ENUM:
  145. return native_type == p_other.native_type;
  146. case ENUM_VALUE:
  147. return native_type == p_other.native_type && enum_type == p_other.enum_type;
  148. case SCRIPT:
  149. return script_type == p_other.script_type;
  150. case CLASS:
  151. return class_type == p_other.class_type;
  152. case UNRESOLVED:
  153. break;
  154. }
  155. return false;
  156. }
  157. bool operator!=(const DataType &p_other) const {
  158. return !(this->operator==(p_other));
  159. }
  160. };
  161. struct ParserError {
  162. // TODO: Do I really need a "type"?
  163. // enum Type {
  164. // NO_ERROR,
  165. // EMPTY_FILE,
  166. // CLASS_NAME_USED_TWICE,
  167. // EXTENDS_USED_TWICE,
  168. // EXPECTED_END_STATEMENT,
  169. // };
  170. // Type type = NO_ERROR;
  171. String message;
  172. int line = 0, column = 0;
  173. };
  174. struct Node {
  175. enum Type {
  176. NONE,
  177. ANNOTATION,
  178. ARRAY,
  179. ASSERT,
  180. ASSIGNMENT,
  181. AWAIT,
  182. BINARY_OPERATOR,
  183. BREAK,
  184. BREAKPOINT,
  185. CALL,
  186. CAST,
  187. CLASS,
  188. CONSTANT,
  189. CONTINUE,
  190. DICTIONARY,
  191. ENUM,
  192. FOR,
  193. FUNCTION,
  194. GET_NODE,
  195. IDENTIFIER,
  196. IF,
  197. LITERAL,
  198. MATCH,
  199. MATCH_BRANCH,
  200. PARAMETER,
  201. PASS,
  202. PATTERN,
  203. PRELOAD,
  204. RETURN,
  205. SELF,
  206. SIGNAL,
  207. SUBSCRIPT,
  208. SUITE,
  209. TERNARY_OPERATOR,
  210. TYPE,
  211. UNARY_OPERATOR,
  212. VARIABLE,
  213. WHILE,
  214. };
  215. Type type = NONE;
  216. int start_line = 0, end_line = 0;
  217. int start_column = 0, end_column = 0;
  218. int leftmost_column = 0, rightmost_column = 0;
  219. Node *next = nullptr;
  220. List<AnnotationNode *> annotations;
  221. DataType datatype;
  222. virtual DataType get_datatype() const { return datatype; }
  223. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  224. virtual bool is_expression() const { return false; }
  225. virtual ~Node() {}
  226. };
  227. struct ExpressionNode : public Node {
  228. // Base type for all expression kinds.
  229. bool reduced = false;
  230. bool is_constant = false;
  231. Variant reduced_value;
  232. virtual bool is_expression() const { return true; }
  233. virtual ~ExpressionNode() {}
  234. protected:
  235. ExpressionNode() {}
  236. };
  237. struct AnnotationNode : public Node {
  238. StringName name;
  239. Vector<ExpressionNode *> arguments;
  240. Vector<Variant> resolved_arguments;
  241. AnnotationInfo *info = nullptr;
  242. bool apply(GDScriptParser *p_this, Node *p_target) const;
  243. bool applies_to(uint32_t p_target_kinds) const;
  244. AnnotationNode() {
  245. type = ANNOTATION;
  246. }
  247. };
  248. struct ArrayNode : public ExpressionNode {
  249. Vector<ExpressionNode *> elements;
  250. ArrayNode() {
  251. type = ARRAY;
  252. }
  253. };
  254. struct AssertNode : public Node {
  255. ExpressionNode *condition = nullptr;
  256. LiteralNode *message = nullptr;
  257. AssertNode() {
  258. type = ASSERT;
  259. }
  260. };
  261. struct AssignmentNode : public ExpressionNode {
  262. // Assignment is not really an expression but it's easier to parse as if it were.
  263. enum Operation {
  264. OP_NONE,
  265. OP_ADDITION,
  266. OP_SUBTRACTION,
  267. OP_MULTIPLICATION,
  268. OP_DIVISION,
  269. OP_MODULO,
  270. OP_BIT_SHIFT_LEFT,
  271. OP_BIT_SHIFT_RIGHT,
  272. OP_BIT_AND,
  273. OP_BIT_OR,
  274. OP_BIT_XOR,
  275. };
  276. Operation operation = OP_NONE;
  277. Variant::Operator variant_op = Variant::OP_MAX;
  278. ExpressionNode *assignee = nullptr;
  279. ExpressionNode *assigned_value = nullptr;
  280. AssignmentNode() {
  281. type = ASSIGNMENT;
  282. }
  283. };
  284. struct AwaitNode : public ExpressionNode {
  285. ExpressionNode *to_await = nullptr;
  286. AwaitNode() {
  287. type = AWAIT;
  288. }
  289. };
  290. struct BinaryOpNode : public ExpressionNode {
  291. enum OpType {
  292. OP_ADDITION,
  293. OP_SUBTRACTION,
  294. OP_MULTIPLICATION,
  295. OP_DIVISION,
  296. OP_MODULO,
  297. OP_BIT_LEFT_SHIFT,
  298. OP_BIT_RIGHT_SHIFT,
  299. OP_BIT_AND,
  300. OP_BIT_OR,
  301. OP_BIT_XOR,
  302. OP_LOGIC_AND,
  303. OP_LOGIC_OR,
  304. OP_TYPE_TEST,
  305. OP_CONTENT_TEST,
  306. OP_COMP_EQUAL,
  307. OP_COMP_NOT_EQUAL,
  308. OP_COMP_LESS,
  309. OP_COMP_LESS_EQUAL,
  310. OP_COMP_GREATER,
  311. OP_COMP_GREATER_EQUAL,
  312. };
  313. OpType operation;
  314. Variant::Operator variant_op = Variant::OP_MAX;
  315. ExpressionNode *left_operand = nullptr;
  316. ExpressionNode *right_operand = nullptr;
  317. BinaryOpNode() {
  318. type = BINARY_OPERATOR;
  319. }
  320. };
  321. struct BreakNode : public Node {
  322. BreakNode() {
  323. type = BREAK;
  324. }
  325. };
  326. struct BreakpointNode : public Node {
  327. BreakpointNode() {
  328. type = BREAKPOINT;
  329. }
  330. };
  331. struct CallNode : public ExpressionNode {
  332. ExpressionNode *callee = nullptr;
  333. Vector<ExpressionNode *> arguments;
  334. StringName function_name;
  335. bool is_super = false;
  336. CallNode() {
  337. type = CALL;
  338. }
  339. Type get_callee_type() const {
  340. if (callee == nullptr) {
  341. return Type::NONE;
  342. } else {
  343. return callee->type;
  344. }
  345. }
  346. };
  347. struct CastNode : public ExpressionNode {
  348. ExpressionNode *operand = nullptr;
  349. TypeNode *cast_type = nullptr;
  350. CastNode() {
  351. type = CAST;
  352. }
  353. };
  354. struct EnumNode : public Node {
  355. struct Value {
  356. IdentifierNode *identifier = nullptr;
  357. ExpressionNode *custom_value = nullptr;
  358. EnumNode *parent_enum = nullptr;
  359. int index = -1;
  360. bool resolved = false;
  361. int value = 0;
  362. int line = 0;
  363. int leftmost_column = 0;
  364. int rightmost_column = 0;
  365. };
  366. IdentifierNode *identifier = nullptr;
  367. Vector<Value> values;
  368. EnumNode() {
  369. type = ENUM;
  370. }
  371. };
  372. struct ClassNode : public Node {
  373. struct Member {
  374. enum Type {
  375. UNDEFINED,
  376. CLASS,
  377. CONSTANT,
  378. FUNCTION,
  379. SIGNAL,
  380. VARIABLE,
  381. ENUM,
  382. ENUM_VALUE, // For unnamed enums.
  383. };
  384. Type type = UNDEFINED;
  385. union {
  386. ClassNode *m_class = nullptr;
  387. ConstantNode *constant;
  388. FunctionNode *function;
  389. SignalNode *signal;
  390. VariableNode *variable;
  391. EnumNode *m_enum;
  392. };
  393. EnumNode::Value enum_value;
  394. String get_type_name() const {
  395. switch (type) {
  396. case UNDEFINED:
  397. return "???";
  398. case CLASS:
  399. return "class";
  400. case CONSTANT:
  401. return "constant";
  402. case FUNCTION:
  403. return "function";
  404. case SIGNAL:
  405. return "signal";
  406. case VARIABLE:
  407. return "variable";
  408. case ENUM:
  409. return "enum";
  410. case ENUM_VALUE:
  411. return "enum value";
  412. }
  413. return "";
  414. }
  415. int get_line() const {
  416. switch (type) {
  417. case CLASS:
  418. return m_class->start_line;
  419. case CONSTANT:
  420. return constant->start_line;
  421. case FUNCTION:
  422. return function->start_line;
  423. case VARIABLE:
  424. return variable->start_line;
  425. case ENUM_VALUE:
  426. return enum_value.line;
  427. case ENUM:
  428. return m_enum->start_line;
  429. case SIGNAL:
  430. return signal->start_line;
  431. case UNDEFINED:
  432. ERR_FAIL_V_MSG(-1, "Reaching undefined member type.");
  433. }
  434. ERR_FAIL_V_MSG(-1, "Reaching unhandled type.");
  435. }
  436. DataType get_datatype() const {
  437. switch (type) {
  438. case CLASS:
  439. return m_class->get_datatype();
  440. case CONSTANT:
  441. return constant->get_datatype();
  442. case FUNCTION:
  443. return function->get_datatype();
  444. case VARIABLE:
  445. return variable->get_datatype();
  446. case ENUM:
  447. return m_enum->get_datatype();
  448. case ENUM_VALUE: {
  449. // Always integer.
  450. DataType type;
  451. type.type_source = DataType::ANNOTATED_EXPLICIT;
  452. type.kind = DataType::BUILTIN;
  453. type.builtin_type = Variant::INT;
  454. return type;
  455. }
  456. case SIGNAL: {
  457. DataType type;
  458. type.type_source = DataType::ANNOTATED_EXPLICIT;
  459. type.kind = DataType::BUILTIN;
  460. type.builtin_type = Variant::SIGNAL;
  461. // TODO: Add parameter info.
  462. return type;
  463. }
  464. case UNDEFINED:
  465. return DataType();
  466. }
  467. ERR_FAIL_V_MSG(DataType(), "Reaching unhandled type.");
  468. }
  469. Member() {}
  470. Member(ClassNode *p_class) {
  471. type = CLASS;
  472. m_class = p_class;
  473. }
  474. Member(ConstantNode *p_constant) {
  475. type = CONSTANT;
  476. constant = p_constant;
  477. }
  478. Member(VariableNode *p_variable) {
  479. type = VARIABLE;
  480. variable = p_variable;
  481. }
  482. Member(SignalNode *p_signal) {
  483. type = SIGNAL;
  484. signal = p_signal;
  485. }
  486. Member(FunctionNode *p_function) {
  487. type = FUNCTION;
  488. function = p_function;
  489. }
  490. Member(EnumNode *p_enum) {
  491. type = ENUM;
  492. m_enum = p_enum;
  493. }
  494. Member(const EnumNode::Value &p_enum_value) {
  495. type = ENUM_VALUE;
  496. enum_value = p_enum_value;
  497. }
  498. };
  499. IdentifierNode *identifier = nullptr;
  500. String icon_path;
  501. Vector<Member> members;
  502. HashMap<StringName, int> members_indices;
  503. ClassNode *outer = nullptr;
  504. bool extends_used = false;
  505. bool onready_used = false;
  506. String extends_path;
  507. Vector<StringName> extends; // List for indexing: extends A.B.C
  508. DataType base_type;
  509. String fqcn; // Fully-qualified class name. Identifies uniquely any class in the project.
  510. bool resolved_interface = false;
  511. bool resolved_body = false;
  512. Member get_member(const StringName &p_name) const {
  513. return members[members_indices[p_name]];
  514. }
  515. bool has_member(const StringName &p_name) const {
  516. return members_indices.has(p_name);
  517. }
  518. bool has_function(const StringName &p_name) const {
  519. return has_member(p_name) && members[members_indices[p_name]].type == Member::FUNCTION;
  520. }
  521. template <class T>
  522. void add_member(T *p_member_node) {
  523. members_indices[p_member_node->identifier->name] = members.size();
  524. members.push_back(Member(p_member_node));
  525. }
  526. void add_member(const EnumNode::Value &p_enum_value) {
  527. members_indices[p_enum_value.identifier->name] = members.size();
  528. members.push_back(Member(p_enum_value));
  529. }
  530. ClassNode() {
  531. type = CLASS;
  532. }
  533. };
  534. struct ConstantNode : public Node {
  535. IdentifierNode *identifier = nullptr;
  536. ExpressionNode *initializer = nullptr;
  537. TypeNode *datatype_specifier = nullptr;
  538. bool infer_datatype = false;
  539. int usages = 0;
  540. ConstantNode() {
  541. type = CONSTANT;
  542. }
  543. };
  544. struct ContinueNode : public Node {
  545. bool is_for_match = false;
  546. ContinueNode() {
  547. type = CONTINUE;
  548. }
  549. };
  550. struct DictionaryNode : public ExpressionNode {
  551. struct Pair {
  552. ExpressionNode *key = nullptr;
  553. ExpressionNode *value = nullptr;
  554. };
  555. Vector<Pair> elements;
  556. enum Style {
  557. LUA_TABLE,
  558. PYTHON_DICT,
  559. };
  560. Style style = PYTHON_DICT;
  561. DictionaryNode() {
  562. type = DICTIONARY;
  563. }
  564. };
  565. struct ForNode : public Node {
  566. IdentifierNode *variable = nullptr;
  567. ExpressionNode *list = nullptr;
  568. SuiteNode *loop = nullptr;
  569. ForNode() {
  570. type = FOR;
  571. }
  572. };
  573. struct FunctionNode : public Node {
  574. IdentifierNode *identifier = nullptr;
  575. Vector<ParameterNode *> parameters;
  576. HashMap<StringName, int> parameters_indices;
  577. TypeNode *return_type = nullptr;
  578. SuiteNode *body = nullptr;
  579. bool is_static = false;
  580. bool is_coroutine = false;
  581. MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
  582. MethodInfo info;
  583. bool resolved_signature = false;
  584. bool resolved_body = false;
  585. FunctionNode() {
  586. type = FUNCTION;
  587. }
  588. };
  589. struct GetNodeNode : public ExpressionNode {
  590. LiteralNode *string = nullptr;
  591. Vector<IdentifierNode *> chain;
  592. GetNodeNode() {
  593. type = GET_NODE;
  594. }
  595. };
  596. struct IdentifierNode : public ExpressionNode {
  597. StringName name;
  598. enum Source {
  599. UNDEFINED_SOURCE,
  600. FUNCTION_PARAMETER,
  601. LOCAL_CONSTANT,
  602. LOCAL_VARIABLE,
  603. LOCAL_ITERATOR, // `for` loop iterator.
  604. LOCAL_BIND, // Pattern bind.
  605. MEMBER_VARIABLE,
  606. MEMBER_CONSTANT,
  607. };
  608. Source source = UNDEFINED_SOURCE;
  609. union {
  610. ParameterNode *parameter_source = nullptr;
  611. ConstantNode *constant_source;
  612. VariableNode *variable_source;
  613. IdentifierNode *bind_source;
  614. };
  615. int usages = 0; // Useful for binds/iterator variable.
  616. IdentifierNode() {
  617. type = IDENTIFIER;
  618. }
  619. };
  620. struct IfNode : public Node {
  621. ExpressionNode *condition = nullptr;
  622. SuiteNode *true_block = nullptr;
  623. SuiteNode *false_block = nullptr;
  624. IfNode() {
  625. type = IF;
  626. }
  627. };
  628. struct LiteralNode : public ExpressionNode {
  629. Variant value;
  630. LiteralNode() {
  631. type = LITERAL;
  632. }
  633. };
  634. struct MatchNode : public Node {
  635. ExpressionNode *test = nullptr;
  636. Vector<MatchBranchNode *> branches;
  637. MatchNode() {
  638. type = MATCH;
  639. }
  640. };
  641. struct MatchBranchNode : public Node {
  642. Vector<PatternNode *> patterns;
  643. SuiteNode *block;
  644. bool has_wildcard = false;
  645. MatchBranchNode() {
  646. type = MATCH_BRANCH;
  647. }
  648. };
  649. struct ParameterNode : public Node {
  650. IdentifierNode *identifier = nullptr;
  651. ExpressionNode *default_value = nullptr;
  652. TypeNode *datatype_specifier = nullptr;
  653. bool infer_datatype = false;
  654. int usages = 0;
  655. ParameterNode() {
  656. type = PARAMETER;
  657. }
  658. };
  659. struct PassNode : public Node {
  660. PassNode() {
  661. type = PASS;
  662. }
  663. };
  664. struct PatternNode : public Node {
  665. enum Type {
  666. PT_LITERAL,
  667. PT_EXPRESSION,
  668. PT_BIND,
  669. PT_ARRAY,
  670. PT_DICTIONARY,
  671. PT_REST,
  672. PT_WILDCARD,
  673. };
  674. Type pattern_type = PT_LITERAL;
  675. union {
  676. LiteralNode *literal = nullptr;
  677. IdentifierNode *bind;
  678. ExpressionNode *expression;
  679. };
  680. Vector<PatternNode *> array;
  681. bool rest_used = false; // For array/dict patterns.
  682. struct Pair {
  683. ExpressionNode *key = nullptr;
  684. PatternNode *value_pattern = nullptr;
  685. };
  686. Vector<Pair> dictionary;
  687. HashMap<StringName, IdentifierNode *> binds;
  688. bool has_bind(const StringName &p_name);
  689. IdentifierNode *get_bind(const StringName &p_name);
  690. PatternNode() {
  691. type = PATTERN;
  692. }
  693. };
  694. struct PreloadNode : public ExpressionNode {
  695. ExpressionNode *path = nullptr;
  696. String resolved_path;
  697. Ref<Resource> resource;
  698. PreloadNode() {
  699. type = PRELOAD;
  700. }
  701. };
  702. struct ReturnNode : public Node {
  703. ExpressionNode *return_value = nullptr;
  704. ReturnNode() {
  705. type = RETURN;
  706. }
  707. };
  708. struct SelfNode : public ExpressionNode {
  709. ClassNode *current_class = nullptr;
  710. SelfNode() {
  711. type = SELF;
  712. }
  713. };
  714. struct SignalNode : public Node {
  715. IdentifierNode *identifier = nullptr;
  716. Vector<ParameterNode *> parameters;
  717. HashMap<StringName, int> parameters_indices;
  718. SignalNode() {
  719. type = SIGNAL;
  720. }
  721. };
  722. struct SubscriptNode : public ExpressionNode {
  723. ExpressionNode *base = nullptr;
  724. union {
  725. ExpressionNode *index = nullptr;
  726. IdentifierNode *attribute;
  727. };
  728. bool is_attribute = false;
  729. SubscriptNode() {
  730. type = SUBSCRIPT;
  731. }
  732. };
  733. struct SuiteNode : public Node {
  734. SuiteNode *parent_block = nullptr;
  735. Vector<Node *> statements;
  736. struct Local {
  737. enum Type {
  738. UNDEFINED,
  739. CONSTANT,
  740. VARIABLE,
  741. PARAMETER,
  742. FOR_VARIABLE,
  743. PATTERN_BIND,
  744. };
  745. Type type = UNDEFINED;
  746. union {
  747. ConstantNode *constant = nullptr;
  748. VariableNode *variable;
  749. ParameterNode *parameter;
  750. IdentifierNode *bind;
  751. };
  752. StringName name;
  753. int start_line = 0, end_line = 0;
  754. int start_column = 0, end_column = 0;
  755. int leftmost_column = 0, rightmost_column = 0;
  756. DataType get_datatype() const;
  757. String get_name() const;
  758. Local() {}
  759. Local(ConstantNode *p_constant) {
  760. type = CONSTANT;
  761. constant = p_constant;
  762. name = p_constant->identifier->name;
  763. start_line = p_constant->start_line;
  764. end_line = p_constant->end_line;
  765. start_column = p_constant->start_column;
  766. end_column = p_constant->end_column;
  767. leftmost_column = p_constant->leftmost_column;
  768. rightmost_column = p_constant->rightmost_column;
  769. }
  770. Local(VariableNode *p_variable) {
  771. type = VARIABLE;
  772. variable = p_variable;
  773. name = p_variable->identifier->name;
  774. start_line = p_variable->start_line;
  775. end_line = p_variable->end_line;
  776. start_column = p_variable->start_column;
  777. end_column = p_variable->end_column;
  778. leftmost_column = p_variable->leftmost_column;
  779. rightmost_column = p_variable->rightmost_column;
  780. }
  781. Local(ParameterNode *p_parameter) {
  782. type = PARAMETER;
  783. parameter = p_parameter;
  784. name = p_parameter->identifier->name;
  785. start_line = p_parameter->start_line;
  786. end_line = p_parameter->end_line;
  787. start_column = p_parameter->start_column;
  788. end_column = p_parameter->end_column;
  789. leftmost_column = p_parameter->leftmost_column;
  790. rightmost_column = p_parameter->rightmost_column;
  791. }
  792. Local(IdentifierNode *p_identifier) {
  793. type = FOR_VARIABLE;
  794. bind = p_identifier;
  795. name = p_identifier->name;
  796. start_line = p_identifier->start_line;
  797. end_line = p_identifier->end_line;
  798. start_column = p_identifier->start_column;
  799. end_column = p_identifier->end_column;
  800. leftmost_column = p_identifier->leftmost_column;
  801. rightmost_column = p_identifier->rightmost_column;
  802. }
  803. };
  804. Local empty;
  805. Vector<Local> locals;
  806. HashMap<StringName, int> locals_indices;
  807. FunctionNode *parent_function = nullptr;
  808. ForNode *parent_for = nullptr;
  809. IfNode *parent_if = nullptr;
  810. bool has_return = false;
  811. bool has_continue = false;
  812. bool has_unreachable_code = false; // Just so warnings aren't given more than once per block.
  813. bool has_local(const StringName &p_name) const;
  814. const Local &get_local(const StringName &p_name) const;
  815. template <class T>
  816. void add_local(T *p_local) {
  817. locals_indices[p_local->identifier->name] = locals.size();
  818. locals.push_back(Local(p_local));
  819. }
  820. void add_local(const Local &p_local) {
  821. locals_indices[p_local.name] = locals.size();
  822. locals.push_back(p_local);
  823. }
  824. SuiteNode() {
  825. type = SUITE;
  826. }
  827. };
  828. struct TernaryOpNode : public ExpressionNode {
  829. // Only one ternary operation exists, so no abstraction here.
  830. ExpressionNode *condition = nullptr;
  831. ExpressionNode *true_expr = nullptr;
  832. ExpressionNode *false_expr = nullptr;
  833. TernaryOpNode() {
  834. type = TERNARY_OPERATOR;
  835. }
  836. };
  837. struct TypeNode : public Node {
  838. Vector<IdentifierNode *> type_chain;
  839. TypeNode() {
  840. type = TYPE;
  841. }
  842. };
  843. struct UnaryOpNode : public ExpressionNode {
  844. enum OpType {
  845. OP_POSITIVE,
  846. OP_NEGATIVE,
  847. OP_COMPLEMENT,
  848. OP_LOGIC_NOT,
  849. };
  850. OpType operation;
  851. Variant::Operator variant_op = Variant::OP_MAX;
  852. ExpressionNode *operand = nullptr;
  853. UnaryOpNode() {
  854. type = UNARY_OPERATOR;
  855. }
  856. };
  857. struct VariableNode : public Node {
  858. enum PropertyStyle {
  859. PROP_NONE,
  860. PROP_INLINE,
  861. PROP_SETGET,
  862. };
  863. IdentifierNode *identifier = nullptr;
  864. ExpressionNode *initializer = nullptr;
  865. TypeNode *datatype_specifier = nullptr;
  866. bool infer_datatype = false;
  867. PropertyStyle property = PROP_NONE;
  868. union {
  869. SuiteNode *setter = nullptr;
  870. IdentifierNode *setter_pointer;
  871. };
  872. IdentifierNode *setter_parameter = nullptr;
  873. union {
  874. SuiteNode *getter = nullptr;
  875. IdentifierNode *getter_pointer;
  876. };
  877. bool exported = false;
  878. bool onready = false;
  879. PropertyInfo export_info;
  880. MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
  881. int assignments = 0;
  882. int usages = 0;
  883. VariableNode() {
  884. type = VARIABLE;
  885. }
  886. };
  887. struct WhileNode : public Node {
  888. ExpressionNode *condition = nullptr;
  889. SuiteNode *loop = nullptr;
  890. WhileNode() {
  891. type = WHILE;
  892. }
  893. };
  894. enum CompletionType {
  895. COMPLETION_NONE,
  896. COMPLETION_ANNOTATION, // Annotation (following @).
  897. COMPLETION_ANNOTATION_ARGUMENTS, // Annotation arguments hint.
  898. COMPLETION_ASSIGN, // Assignment based on type (e.g. enum values).
  899. COMPLETION_ATTRIBUTE, // After id.| to look for members.
  900. COMPLETION_ATTRIBUTE_METHOD, // After id.| to look for methods.
  901. COMPLETION_BUILT_IN_TYPE_CONSTANT, // Constants inside a built-in type (e.g. Color.blue).
  902. COMPLETION_CALL_ARGUMENTS, // Complete with nodes, input actions, enum values (or usual expressions).
  903. // TODO: COMPLETION_DECLARATION, // Potential declaration (var, const, func).
  904. COMPLETION_GET_NODE, // Get node with $ notation.
  905. COMPLETION_IDENTIFIER, // List available identifiers in scope.
  906. COMPLETION_INHERIT_TYPE, // Type after extends. Exclude non-viable types (built-ins, enums, void). Includes subtypes using the argument index.
  907. COMPLETION_METHOD, // List available methods in scope.
  908. COMPLETION_OVERRIDE_METHOD, // Override implementation, also for native virtuals.
  909. COMPLETION_PROPERTY_DECLARATION, // Property declaration (get, set).
  910. COMPLETION_PROPERTY_DECLARATION_OR_TYPE, // Property declaration (get, set) or a type hint.
  911. COMPLETION_PROPERTY_METHOD, // Property setter or getter (list available methods).
  912. COMPLETION_RESOURCE_PATH, // For load/preload.
  913. COMPLETION_SUBSCRIPT, // Inside id[|].
  914. COMPLETION_SUPER_METHOD, // After super.
  915. COMPLETION_TYPE_ATTRIBUTE, // Attribute in type name (Type.|).
  916. COMPLETION_TYPE_NAME, // Name of type (after :).
  917. COMPLETION_TYPE_NAME_OR_VOID, // Same as TYPE_NAME, but allows void (in function return type).
  918. };
  919. struct CompletionContext {
  920. CompletionType type = COMPLETION_NONE;
  921. ClassNode *current_class = nullptr;
  922. FunctionNode *current_function = nullptr;
  923. SuiteNode *current_suite = nullptr;
  924. int current_line = -1;
  925. int current_argument = -1;
  926. Variant::Type builtin_type = Variant::VARIANT_MAX;
  927. Node *node = nullptr;
  928. Object *base = nullptr;
  929. List<Ref<GDScriptParserRef>> dependent_parsers;
  930. };
  931. struct CompletionCall {
  932. Node *call = nullptr;
  933. int argument = -1;
  934. };
  935. private:
  936. friend class GDScriptAnalyzer;
  937. bool _is_tool = false;
  938. String script_path;
  939. bool for_completion = false;
  940. bool panic_mode = false;
  941. bool can_break = false;
  942. bool can_continue = false;
  943. bool is_continue_match = false; // Whether a `continue` will act on a `match`.
  944. bool is_ignoring_warnings = false;
  945. List<bool> multiline_stack;
  946. ClassNode *head = nullptr;
  947. Node *list = nullptr;
  948. List<ParserError> errors;
  949. #ifdef DEBUG_ENABLED
  950. List<GDScriptWarning> warnings;
  951. Set<String> ignored_warnings;
  952. Set<int> unsafe_lines;
  953. #endif
  954. GDScriptTokenizer tokenizer;
  955. GDScriptTokenizer::Token previous;
  956. GDScriptTokenizer::Token current;
  957. ClassNode *current_class = nullptr;
  958. FunctionNode *current_function = nullptr;
  959. SuiteNode *current_suite = nullptr;
  960. CompletionContext completion_context;
  961. CompletionCall completion_call;
  962. List<CompletionCall> completion_call_stack;
  963. bool passed_cursor = false;
  964. typedef bool (GDScriptParser::*AnnotationAction)(const AnnotationNode *p_annotation, Node *p_target);
  965. struct AnnotationInfo {
  966. enum TargetKind {
  967. NONE = 0,
  968. SCRIPT = 1 << 0,
  969. CLASS = 1 << 1,
  970. VARIABLE = 1 << 2,
  971. CONSTANT = 1 << 3,
  972. SIGNAL = 1 << 4,
  973. FUNCTION = 1 << 5,
  974. STATEMENT = 1 << 6,
  975. CLASS_LEVEL = CLASS | VARIABLE | FUNCTION,
  976. };
  977. uint32_t target_kind = 0; // Flags.
  978. AnnotationAction apply = nullptr;
  979. MethodInfo info;
  980. };
  981. HashMap<StringName, AnnotationInfo> valid_annotations;
  982. List<AnnotationNode *> annotation_stack;
  983. typedef ExpressionNode *(GDScriptParser::*ParseFunction)(ExpressionNode *p_previous_operand, bool p_can_assign);
  984. // Higher value means higher precedence (i.e. is evaluated first).
  985. enum Precedence {
  986. PREC_NONE,
  987. PREC_ASSIGNMENT,
  988. PREC_CAST,
  989. PREC_TERNARY,
  990. PREC_LOGIC_OR,
  991. PREC_LOGIC_AND,
  992. PREC_LOGIC_NOT,
  993. PREC_CONTENT_TEST,
  994. PREC_COMPARISON,
  995. PREC_BIT_OR,
  996. PREC_BIT_XOR,
  997. PREC_BIT_AND,
  998. PREC_BIT_SHIFT,
  999. PREC_SUBTRACTION,
  1000. PREC_ADDITION,
  1001. PREC_FACTOR,
  1002. PREC_SIGN,
  1003. PREC_BIT_NOT,
  1004. PREC_TYPE_TEST,
  1005. PREC_AWAIT,
  1006. PREC_CALL,
  1007. PREC_ATTRIBUTE,
  1008. PREC_SUBSCRIPT,
  1009. PREC_PRIMARY,
  1010. };
  1011. struct ParseRule {
  1012. ParseFunction prefix = nullptr;
  1013. ParseFunction infix = nullptr;
  1014. Precedence precedence = PREC_NONE;
  1015. };
  1016. static ParseRule *get_rule(GDScriptTokenizer::Token::Type p_token_type);
  1017. template <class T>
  1018. T *alloc_node() {
  1019. T *node = memnew(T);
  1020. node->next = list;
  1021. list = node;
  1022. // TODO: Properly set positions for all nodes.
  1023. node->start_line = previous.start_line;
  1024. node->end_line = previous.end_line;
  1025. node->start_column = previous.start_column;
  1026. node->end_column = previous.end_column;
  1027. node->leftmost_column = previous.leftmost_column;
  1028. node->rightmost_column = previous.rightmost_column;
  1029. return node;
  1030. }
  1031. void clear();
  1032. void push_error(const String &p_message, const Node *p_origin = nullptr);
  1033. #ifdef DEBUG_ENABLED
  1034. void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const String &p_symbol1 = String(), const String &p_symbol2 = String(), const String &p_symbol3 = String(), const String &p_symbol4 = String());
  1035. void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const Vector<String> &p_symbols);
  1036. #endif
  1037. void make_completion_context(CompletionType p_type, Node *p_node, int p_argument = -1, bool p_force = false);
  1038. void make_completion_context(CompletionType p_type, Variant::Type p_builtin_type, bool p_force = false);
  1039. void push_completion_call(Node *p_call);
  1040. void pop_completion_call();
  1041. void set_last_completion_call_arg(int p_argument);
  1042. GDScriptTokenizer::Token advance();
  1043. bool match(GDScriptTokenizer::Token::Type p_token_type);
  1044. bool check(GDScriptTokenizer::Token::Type p_token_type);
  1045. bool consume(GDScriptTokenizer::Token::Type p_token_type, const String &p_error_message);
  1046. bool is_at_end();
  1047. bool is_statement_end();
  1048. void end_statement(const String &p_context);
  1049. void synchronize();
  1050. void push_multiline(bool p_state);
  1051. void pop_multiline();
  1052. // Main blocks.
  1053. void parse_program();
  1054. ClassNode *parse_class();
  1055. void parse_class_name();
  1056. void parse_extends();
  1057. void parse_class_body();
  1058. template <class T>
  1059. void parse_class_member(T *(GDScriptParser::*p_parse_function)(), AnnotationInfo::TargetKind p_target, const String &p_member_kind);
  1060. SignalNode *parse_signal();
  1061. EnumNode *parse_enum();
  1062. ParameterNode *parse_parameter();
  1063. FunctionNode *parse_function();
  1064. SuiteNode *parse_suite(const String &p_context, SuiteNode *p_suite = nullptr);
  1065. // Annotations
  1066. AnnotationNode *parse_annotation(uint32_t p_valid_targets);
  1067. bool register_annotation(const MethodInfo &p_info, uint32_t p_target_kinds, AnnotationAction p_apply, int p_optional_arguments = 0, bool p_is_vararg = false);
  1068. bool validate_annotation_arguments(AnnotationNode *p_annotation);
  1069. void clear_unused_annotations();
  1070. bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1071. bool icon_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1072. bool onready_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1073. template <PropertyHint t_hint, Variant::Type t_type>
  1074. bool export_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1075. bool warning_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1076. template <MultiplayerAPI::RPCMode t_mode>
  1077. bool network_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1078. // Statements.
  1079. Node *parse_statement();
  1080. VariableNode *parse_variable();
  1081. VariableNode *parse_variable(bool p_allow_property);
  1082. VariableNode *parse_property(VariableNode *p_variable, bool p_need_indent);
  1083. void parse_property_getter(VariableNode *p_variable);
  1084. void parse_property_setter(VariableNode *p_variable);
  1085. ConstantNode *parse_constant();
  1086. AssertNode *parse_assert();
  1087. BreakNode *parse_break();
  1088. ContinueNode *parse_continue();
  1089. ForNode *parse_for();
  1090. IfNode *parse_if(const String &p_token = "if");
  1091. MatchNode *parse_match();
  1092. MatchBranchNode *parse_match_branch();
  1093. PatternNode *parse_match_pattern(PatternNode *p_root_pattern = nullptr);
  1094. WhileNode *parse_while();
  1095. // Expressions.
  1096. ExpressionNode *parse_expression(bool p_can_assign, bool p_stop_on_assign = false);
  1097. ExpressionNode *parse_precedence(Precedence p_precedence, bool p_can_assign, bool p_stop_on_assign = false);
  1098. ExpressionNode *parse_literal(ExpressionNode *p_previous_operand, bool p_can_assign);
  1099. LiteralNode *parse_literal();
  1100. ExpressionNode *parse_self(ExpressionNode *p_previous_operand, bool p_can_assign);
  1101. ExpressionNode *parse_identifier(ExpressionNode *p_previous_operand, bool p_can_assign);
  1102. IdentifierNode *parse_identifier();
  1103. ExpressionNode *parse_builtin_constant(ExpressionNode *p_previous_operand, bool p_can_assign);
  1104. ExpressionNode *parse_unary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1105. ExpressionNode *parse_binary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1106. ExpressionNode *parse_ternary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1107. ExpressionNode *parse_assignment(ExpressionNode *p_previous_operand, bool p_can_assign);
  1108. ExpressionNode *parse_array(ExpressionNode *p_previous_operand, bool p_can_assign);
  1109. ExpressionNode *parse_dictionary(ExpressionNode *p_previous_operand, bool p_can_assign);
  1110. ExpressionNode *parse_call(ExpressionNode *p_previous_operand, bool p_can_assign);
  1111. ExpressionNode *parse_get_node(ExpressionNode *p_previous_operand, bool p_can_assign);
  1112. ExpressionNode *parse_preload(ExpressionNode *p_previous_operand, bool p_can_assign);
  1113. ExpressionNode *parse_grouping(ExpressionNode *p_previous_operand, bool p_can_assign);
  1114. ExpressionNode *parse_cast(ExpressionNode *p_previous_operand, bool p_can_assign);
  1115. ExpressionNode *parse_await(ExpressionNode *p_previous_operand, bool p_can_assign);
  1116. ExpressionNode *parse_attribute(ExpressionNode *p_previous_operand, bool p_can_assign);
  1117. ExpressionNode *parse_subscript(ExpressionNode *p_previous_operand, bool p_can_assign);
  1118. ExpressionNode *parse_invalid_token(ExpressionNode *p_previous_operand, bool p_can_assign);
  1119. TypeNode *parse_type(bool p_allow_void = false);
  1120. public:
  1121. Error parse(const String &p_source_code, const String &p_script_path, bool p_for_completion);
  1122. ClassNode *get_tree() const { return head; }
  1123. bool is_tool() const { return _is_tool; }
  1124. static Variant::Type get_builtin_type(const StringName &p_type);
  1125. static GDScriptFunctions::Function get_builtin_function(const StringName &p_name);
  1126. CompletionContext get_completion_context() const { return completion_context; }
  1127. CompletionCall get_completion_call() const { return completion_call; }
  1128. void get_annotation_list(List<MethodInfo> *r_annotations) const;
  1129. const List<ParserError> &get_errors() const { return errors; }
  1130. const List<String> get_dependencies() const {
  1131. // TODO: Keep track of deps.
  1132. return List<String>();
  1133. }
  1134. #ifdef DEBUG_ENABLED
  1135. const List<GDScriptWarning> &get_warnings() const { return warnings; }
  1136. const Set<int> &get_unsafe_lines() const { return unsafe_lines; }
  1137. int get_last_line_number() const { return current.end_line; }
  1138. #endif
  1139. GDScriptParser();
  1140. ~GDScriptParser();
  1141. #ifdef DEBUG_ENABLED
  1142. class TreePrinter {
  1143. int indent_level = 0;
  1144. String indent;
  1145. StringBuilder printed;
  1146. bool pending_indent = false;
  1147. void increase_indent();
  1148. void decrease_indent();
  1149. void push_line(const String &p_line = String());
  1150. void push_text(const String &p_text);
  1151. void print_annotation(AnnotationNode *p_annotation);
  1152. void print_array(ArrayNode *p_array);
  1153. void print_assert(AssertNode *p_assert);
  1154. void print_assignment(AssignmentNode *p_assignment);
  1155. void print_await(AwaitNode *p_await);
  1156. void print_binary_op(BinaryOpNode *p_binary_op);
  1157. void print_call(CallNode *p_call);
  1158. void print_cast(CastNode *p_cast);
  1159. void print_class(ClassNode *p_class);
  1160. void print_constant(ConstantNode *p_constant);
  1161. void print_dictionary(DictionaryNode *p_dictionary);
  1162. void print_expression(ExpressionNode *p_expression);
  1163. void print_enum(EnumNode *p_enum);
  1164. void print_for(ForNode *p_for);
  1165. void print_function(FunctionNode *p_function);
  1166. void print_get_node(GetNodeNode *p_get_node);
  1167. void print_if(IfNode *p_if, bool p_is_elif = false);
  1168. void print_identifier(IdentifierNode *p_identifier);
  1169. void print_literal(LiteralNode *p_literal);
  1170. void print_match(MatchNode *p_match);
  1171. void print_match_branch(MatchBranchNode *p_match_branch);
  1172. void print_match_pattern(PatternNode *p_match_pattern);
  1173. void print_parameter(ParameterNode *p_parameter);
  1174. void print_preload(PreloadNode *p_preload);
  1175. void print_return(ReturnNode *p_return);
  1176. void print_self(SelfNode *p_self);
  1177. void print_signal(SignalNode *p_signal);
  1178. void print_statement(Node *p_statement);
  1179. void print_subscript(SubscriptNode *p_subscript);
  1180. void print_suite(SuiteNode *p_suite);
  1181. void print_type(TypeNode *p_type);
  1182. void print_ternary_op(TernaryOpNode *p_ternary_op);
  1183. void print_unary_op(UnaryOpNode *p_unary_op);
  1184. void print_variable(VariableNode *p_variable);
  1185. void print_while(WhileNode *p_while);
  1186. public:
  1187. void print_tree(const GDScriptParser &p_parser);
  1188. };
  1189. #endif // DEBUG_ENABLED
  1190. static void cleanup();
  1191. };
  1192. #endif // GDSCRIPT_PARSER_H