gdscript_parser.h 36 KB

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