gdscript_parser.h 36 KB

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