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/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. 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_ignoring_warnings = false;
  943. List<bool> multiline_stack;
  944. ClassNode *head = nullptr;
  945. Node *list = nullptr;
  946. List<ParserError> errors;
  947. #ifdef DEBUG_ENABLED
  948. List<GDScriptWarning> warnings;
  949. Set<String> ignored_warnings;
  950. Set<int> unsafe_lines;
  951. #endif
  952. GDScriptTokenizer tokenizer;
  953. GDScriptTokenizer::Token previous;
  954. GDScriptTokenizer::Token current;
  955. ClassNode *current_class = nullptr;
  956. FunctionNode *current_function = nullptr;
  957. SuiteNode *current_suite = nullptr;
  958. CompletionContext completion_context;
  959. CompletionCall completion_call;
  960. List<CompletionCall> completion_call_stack;
  961. bool passed_cursor = false;
  962. typedef bool (GDScriptParser::*AnnotationAction)(const AnnotationNode *p_annotation, Node *p_target);
  963. struct AnnotationInfo {
  964. enum TargetKind {
  965. NONE = 0,
  966. SCRIPT = 1 << 0,
  967. CLASS = 1 << 1,
  968. VARIABLE = 1 << 2,
  969. CONSTANT = 1 << 3,
  970. SIGNAL = 1 << 4,
  971. FUNCTION = 1 << 5,
  972. STATEMENT = 1 << 6,
  973. CLASS_LEVEL = CLASS | VARIABLE | FUNCTION,
  974. };
  975. uint32_t target_kind = 0; // Flags.
  976. AnnotationAction apply = nullptr;
  977. MethodInfo info;
  978. };
  979. HashMap<StringName, AnnotationInfo> valid_annotations;
  980. List<AnnotationNode *> annotation_stack;
  981. typedef ExpressionNode *(GDScriptParser::*ParseFunction)(ExpressionNode *p_previous_operand, bool p_can_assign);
  982. // Higher value means higher precedence (i.e. is evaluated first).
  983. enum Precedence {
  984. PREC_NONE,
  985. PREC_ASSIGNMENT,
  986. PREC_CAST,
  987. PREC_TERNARY,
  988. PREC_LOGIC_OR,
  989. PREC_LOGIC_AND,
  990. PREC_LOGIC_NOT,
  991. PREC_CONTENT_TEST,
  992. PREC_COMPARISON,
  993. PREC_BIT_OR,
  994. PREC_BIT_XOR,
  995. PREC_BIT_AND,
  996. PREC_BIT_SHIFT,
  997. PREC_SUBTRACTION,
  998. PREC_ADDITION,
  999. PREC_FACTOR,
  1000. PREC_SIGN,
  1001. PREC_BIT_NOT,
  1002. PREC_TYPE_TEST,
  1003. PREC_AWAIT,
  1004. PREC_CALL,
  1005. PREC_ATTRIBUTE,
  1006. PREC_SUBSCRIPT,
  1007. PREC_PRIMARY,
  1008. };
  1009. struct ParseRule {
  1010. ParseFunction prefix = nullptr;
  1011. ParseFunction infix = nullptr;
  1012. Precedence precedence = PREC_NONE;
  1013. };
  1014. static ParseRule *get_rule(GDScriptTokenizer::Token::Type p_token_type);
  1015. template <class T>
  1016. T *alloc_node() {
  1017. T *node = memnew(T);
  1018. node->next = list;
  1019. list = node;
  1020. // TODO: Properly set positions for all nodes.
  1021. node->start_line = previous.start_line;
  1022. node->end_line = previous.end_line;
  1023. node->start_column = previous.start_column;
  1024. node->end_column = previous.end_column;
  1025. node->leftmost_column = previous.leftmost_column;
  1026. node->rightmost_column = previous.rightmost_column;
  1027. return node;
  1028. }
  1029. void clear();
  1030. void push_error(const String &p_message, const Node *p_origin = nullptr);
  1031. #ifdef DEBUG_ENABLED
  1032. 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());
  1033. void push_warning(const Node *p_source, GDScriptWarning::Code p_code, const Vector<String> &p_symbols);
  1034. #endif
  1035. void make_completion_context(CompletionType p_type, Node *p_node, int p_argument = -1, bool p_force = false);
  1036. void make_completion_context(CompletionType p_type, Variant::Type p_builtin_type, bool p_force = false);
  1037. void push_completion_call(Node *p_call);
  1038. void pop_completion_call();
  1039. void set_last_completion_call_arg(int p_argument);
  1040. GDScriptTokenizer::Token advance();
  1041. bool match(GDScriptTokenizer::Token::Type p_token_type);
  1042. bool check(GDScriptTokenizer::Token::Type p_token_type);
  1043. bool consume(GDScriptTokenizer::Token::Type p_token_type, const String &p_error_message);
  1044. bool is_at_end();
  1045. bool is_statement_end();
  1046. void end_statement(const String &p_context);
  1047. void synchronize();
  1048. void push_multiline(bool p_state);
  1049. void pop_multiline();
  1050. // Main blocks.
  1051. void parse_program();
  1052. ClassNode *parse_class();
  1053. void parse_class_name();
  1054. void parse_extends();
  1055. void parse_class_body();
  1056. template <class T>
  1057. void parse_class_member(T *(GDScriptParser::*p_parse_function)(), AnnotationInfo::TargetKind p_target, const String &p_member_kind);
  1058. SignalNode *parse_signal();
  1059. EnumNode *parse_enum();
  1060. ParameterNode *parse_parameter();
  1061. FunctionNode *parse_function();
  1062. SuiteNode *parse_suite(const String &p_context, SuiteNode *p_suite = nullptr);
  1063. // Annotations
  1064. AnnotationNode *parse_annotation(uint32_t p_valid_targets);
  1065. 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);
  1066. bool validate_annotation_arguments(AnnotationNode *p_annotation);
  1067. void clear_unused_annotations();
  1068. bool tool_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1069. bool icon_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1070. bool onready_annotation(const AnnotationNode *p_annotation, Node *p_target);
  1071. template <PropertyHint t_hint, Variant::Type t_type>
  1072. bool export_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1073. bool warning_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1074. template <MultiplayerAPI::RPCMode t_mode>
  1075. bool network_annotations(const AnnotationNode *p_annotation, Node *p_target);
  1076. // Statements.
  1077. Node *parse_statement();
  1078. VariableNode *parse_variable();
  1079. VariableNode *parse_variable(bool p_allow_property);
  1080. VariableNode *parse_property(VariableNode *p_variable, bool p_need_indent);
  1081. void parse_property_getter(VariableNode *p_variable);
  1082. void parse_property_setter(VariableNode *p_variable);
  1083. ConstantNode *parse_constant();
  1084. AssertNode *parse_assert();
  1085. BreakNode *parse_break();
  1086. ContinueNode *parse_continue();
  1087. ForNode *parse_for();
  1088. IfNode *parse_if(const String &p_token = "if");
  1089. MatchNode *parse_match();
  1090. MatchBranchNode *parse_match_branch();
  1091. PatternNode *parse_match_pattern(PatternNode *p_root_pattern = nullptr);
  1092. WhileNode *parse_while();
  1093. // Expressions.
  1094. ExpressionNode *parse_expression(bool p_can_assign, bool p_stop_on_assign = false);
  1095. ExpressionNode *parse_precedence(Precedence p_precedence, bool p_can_assign, bool p_stop_on_assign = false);
  1096. ExpressionNode *parse_literal(ExpressionNode *p_previous_operand, bool p_can_assign);
  1097. LiteralNode *parse_literal();
  1098. ExpressionNode *parse_self(ExpressionNode *p_previous_operand, bool p_can_assign);
  1099. ExpressionNode *parse_identifier(ExpressionNode *p_previous_operand, bool p_can_assign);
  1100. IdentifierNode *parse_identifier();
  1101. ExpressionNode *parse_builtin_constant(ExpressionNode *p_previous_operand, bool p_can_assign);
  1102. ExpressionNode *parse_unary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1103. ExpressionNode *parse_binary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1104. ExpressionNode *parse_ternary_operator(ExpressionNode *p_previous_operand, bool p_can_assign);
  1105. ExpressionNode *parse_assignment(ExpressionNode *p_previous_operand, bool p_can_assign);
  1106. ExpressionNode *parse_array(ExpressionNode *p_previous_operand, bool p_can_assign);
  1107. ExpressionNode *parse_dictionary(ExpressionNode *p_previous_operand, bool p_can_assign);
  1108. ExpressionNode *parse_call(ExpressionNode *p_previous_operand, bool p_can_assign);
  1109. ExpressionNode *parse_get_node(ExpressionNode *p_previous_operand, bool p_can_assign);
  1110. ExpressionNode *parse_preload(ExpressionNode *p_previous_operand, bool p_can_assign);
  1111. ExpressionNode *parse_grouping(ExpressionNode *p_previous_operand, bool p_can_assign);
  1112. ExpressionNode *parse_cast(ExpressionNode *p_previous_operand, bool p_can_assign);
  1113. ExpressionNode *parse_await(ExpressionNode *p_previous_operand, bool p_can_assign);
  1114. ExpressionNode *parse_attribute(ExpressionNode *p_previous_operand, bool p_can_assign);
  1115. ExpressionNode *parse_subscript(ExpressionNode *p_previous_operand, bool p_can_assign);
  1116. ExpressionNode *parse_invalid_token(ExpressionNode *p_previous_operand, bool p_can_assign);
  1117. TypeNode *parse_type(bool p_allow_void = false);
  1118. public:
  1119. Error parse(const String &p_source_code, const String &p_script_path, bool p_for_completion);
  1120. ClassNode *get_tree() const { return head; }
  1121. bool is_tool() const { return _is_tool; }
  1122. static Variant::Type get_builtin_type(const StringName &p_type);
  1123. static GDScriptFunctions::Function get_builtin_function(const StringName &p_name);
  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