gdscript_parser.h 35 KB

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