gdscript_parser.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /**************************************************************************/
  2. /* gdscript_parser.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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/map.h"
  33. #include "core/object.h"
  34. #include "core/script_language.h"
  35. #include "gdscript_functions.h"
  36. #include "gdscript_tokenizer.h"
  37. struct GDScriptDataType;
  38. struct GDScriptWarning;
  39. class GDScriptParser {
  40. public:
  41. struct ClassNode;
  42. struct DataType {
  43. enum {
  44. BUILTIN,
  45. NATIVE,
  46. SCRIPT,
  47. GDSCRIPT,
  48. CLASS,
  49. UNRESOLVED
  50. } kind;
  51. bool has_type;
  52. bool is_constant;
  53. bool is_meta_type; // Whether the value can be used as a type
  54. bool infer_type;
  55. bool may_yield; // For function calls
  56. Variant::Type builtin_type;
  57. StringName native_type;
  58. Ref<Script> script_type;
  59. ClassNode *class_type;
  60. String to_string() const;
  61. bool operator==(const DataType &other) const {
  62. if (!has_type || !other.has_type) {
  63. return true; // Can be considered equal for parsing purpose
  64. }
  65. if (kind != other.kind) {
  66. return false;
  67. }
  68. switch (kind) {
  69. case BUILTIN: {
  70. return builtin_type == other.builtin_type;
  71. } break;
  72. case NATIVE: {
  73. return native_type == other.native_type;
  74. } break;
  75. case GDSCRIPT:
  76. case SCRIPT: {
  77. return script_type == other.script_type;
  78. } break;
  79. case CLASS: {
  80. return class_type == other.class_type;
  81. } break;
  82. case UNRESOLVED: {
  83. } break;
  84. }
  85. return false;
  86. }
  87. DataType() :
  88. kind(UNRESOLVED),
  89. has_type(false),
  90. is_constant(false),
  91. is_meta_type(false),
  92. infer_type(false),
  93. may_yield(false),
  94. builtin_type(Variant::NIL),
  95. class_type(nullptr) {}
  96. };
  97. struct Node {
  98. enum Type {
  99. TYPE_CLASS,
  100. TYPE_FUNCTION,
  101. TYPE_BUILT_IN_FUNCTION,
  102. TYPE_BLOCK,
  103. TYPE_IDENTIFIER,
  104. TYPE_TYPE,
  105. TYPE_CONSTANT,
  106. TYPE_ARRAY,
  107. TYPE_DICTIONARY,
  108. TYPE_SELF,
  109. TYPE_OPERATOR,
  110. TYPE_CONTROL_FLOW,
  111. TYPE_LOCAL_VAR,
  112. TYPE_CAST,
  113. TYPE_ASSERT,
  114. TYPE_BREAKPOINT,
  115. TYPE_NEWLINE,
  116. };
  117. Node *next;
  118. int line;
  119. int column;
  120. Type type;
  121. virtual DataType get_datatype() const { return DataType(); }
  122. virtual void set_datatype(const DataType &p_datatype) {}
  123. virtual ~Node() {}
  124. };
  125. struct FunctionNode;
  126. struct BlockNode;
  127. struct ConstantNode;
  128. struct LocalVarNode;
  129. struct OperatorNode;
  130. struct ClassNode : public Node {
  131. bool tool;
  132. StringName name;
  133. bool extends_used;
  134. bool classname_used;
  135. StringName extends_file;
  136. Vector<StringName> extends_class;
  137. DataType base_type;
  138. String icon_path;
  139. struct Member {
  140. PropertyInfo _export;
  141. #ifdef TOOLS_ENABLED
  142. Variant default_value;
  143. #endif
  144. StringName identifier;
  145. DataType data_type;
  146. StringName setter;
  147. StringName getter;
  148. int line;
  149. Node *expression;
  150. OperatorNode *initial_assignment;
  151. MultiplayerAPI::RPCMode rpc_mode;
  152. int usages;
  153. };
  154. struct Constant {
  155. Node *expression;
  156. DataType type;
  157. };
  158. struct Signal {
  159. StringName name;
  160. Vector<StringName> arguments;
  161. int emissions;
  162. int line;
  163. };
  164. Vector<ClassNode *> subclasses;
  165. Vector<Member> variables;
  166. Map<StringName, Constant> constant_expressions;
  167. Vector<FunctionNode *> functions;
  168. Vector<FunctionNode *> static_functions;
  169. Vector<Signal> _signals;
  170. BlockNode *initializer;
  171. BlockNode *ready;
  172. ClassNode *owner;
  173. //Vector<Node*> initializers;
  174. int end_line;
  175. ClassNode() {
  176. tool = false;
  177. type = TYPE_CLASS;
  178. extends_used = false;
  179. classname_used = false;
  180. end_line = -1;
  181. owner = nullptr;
  182. }
  183. };
  184. struct FunctionNode : public Node {
  185. bool _static;
  186. MultiplayerAPI::RPCMode rpc_mode;
  187. bool has_yield;
  188. bool has_unreachable_code;
  189. StringName name;
  190. DataType return_type;
  191. Vector<StringName> arguments;
  192. Vector<DataType> argument_types;
  193. Vector<Node *> default_values;
  194. BlockNode *body;
  195. #ifdef DEBUG_ENABLED
  196. Vector<int> arguments_usage;
  197. #endif // DEBUG_ENABLED
  198. virtual DataType get_datatype() const { return return_type; }
  199. virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; }
  200. int get_required_argument_count() { return arguments.size() - default_values.size(); }
  201. FunctionNode() {
  202. type = TYPE_FUNCTION;
  203. _static = false;
  204. rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
  205. has_yield = false;
  206. has_unreachable_code = false;
  207. }
  208. };
  209. struct BlockNode : public Node {
  210. ClassNode *parent_class;
  211. BlockNode *parent_block;
  212. Vector<Node *> statements;
  213. Map<StringName, LocalVarNode *> variables;
  214. bool has_return = false;
  215. bool can_break = false;
  216. bool can_continue = false;
  217. Node *if_condition; //tiny hack to improve code completion on if () blocks
  218. //the following is useful for code completion
  219. List<BlockNode *> sub_blocks;
  220. int end_line;
  221. BlockNode() {
  222. if_condition = nullptr;
  223. type = TYPE_BLOCK;
  224. end_line = -1;
  225. parent_block = nullptr;
  226. parent_class = nullptr;
  227. }
  228. };
  229. struct TypeNode : public Node {
  230. Variant::Type vtype;
  231. TypeNode() { type = TYPE_TYPE; }
  232. };
  233. struct BuiltInFunctionNode : public Node {
  234. GDScriptFunctions::Function function;
  235. BuiltInFunctionNode() { type = TYPE_BUILT_IN_FUNCTION; }
  236. };
  237. struct IdentifierNode : public Node {
  238. StringName name;
  239. BlockNode *declared_block; // Simplify lookup by checking if it is declared locally
  240. DataType datatype;
  241. virtual DataType get_datatype() const { return datatype; }
  242. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  243. IdentifierNode() {
  244. type = TYPE_IDENTIFIER;
  245. declared_block = nullptr;
  246. }
  247. };
  248. struct LocalVarNode : public Node {
  249. StringName name;
  250. Node *assign;
  251. OperatorNode *assign_op;
  252. int assignments;
  253. int usages;
  254. DataType datatype;
  255. virtual DataType get_datatype() const { return datatype; }
  256. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  257. LocalVarNode() {
  258. type = TYPE_LOCAL_VAR;
  259. assign = nullptr;
  260. assign_op = nullptr;
  261. assignments = 0;
  262. usages = 0;
  263. }
  264. };
  265. struct ConstantNode : public Node {
  266. Variant value;
  267. DataType datatype;
  268. virtual DataType get_datatype() const { return datatype; }
  269. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  270. ConstantNode() { type = TYPE_CONSTANT; }
  271. };
  272. struct ArrayNode : public Node {
  273. Vector<Node *> elements;
  274. DataType datatype;
  275. virtual DataType get_datatype() const { return datatype; }
  276. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  277. ArrayNode() {
  278. type = TYPE_ARRAY;
  279. datatype.has_type = true;
  280. datatype.kind = DataType::BUILTIN;
  281. datatype.builtin_type = Variant::ARRAY;
  282. }
  283. };
  284. struct DictionaryNode : public Node {
  285. struct Pair {
  286. Node *key;
  287. Node *value;
  288. };
  289. Vector<Pair> elements;
  290. DataType datatype;
  291. virtual DataType get_datatype() const { return datatype; }
  292. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  293. DictionaryNode() {
  294. type = TYPE_DICTIONARY;
  295. datatype.has_type = true;
  296. datatype.kind = DataType::BUILTIN;
  297. datatype.builtin_type = Variant::DICTIONARY;
  298. }
  299. };
  300. struct SelfNode : public Node {
  301. SelfNode() { type = TYPE_SELF; }
  302. };
  303. struct OperatorNode : public Node {
  304. enum Operator {
  305. //call/constructor operator
  306. OP_CALL,
  307. OP_PARENT_CALL,
  308. OP_YIELD,
  309. OP_IS,
  310. OP_IS_BUILTIN,
  311. //indexing operator
  312. OP_INDEX,
  313. OP_INDEX_NAMED,
  314. //unary operators
  315. OP_NEG,
  316. OP_POS,
  317. OP_NOT,
  318. OP_BIT_INVERT,
  319. //binary operators (in precedence order)
  320. OP_IN,
  321. OP_EQUAL,
  322. OP_NOT_EQUAL,
  323. OP_LESS,
  324. OP_LESS_EQUAL,
  325. OP_GREATER,
  326. OP_GREATER_EQUAL,
  327. OP_AND,
  328. OP_OR,
  329. OP_ADD,
  330. OP_SUB,
  331. OP_MUL,
  332. OP_DIV,
  333. OP_MOD,
  334. OP_SHIFT_LEFT,
  335. OP_SHIFT_RIGHT,
  336. OP_INIT_ASSIGN,
  337. OP_ASSIGN,
  338. OP_ASSIGN_ADD,
  339. OP_ASSIGN_SUB,
  340. OP_ASSIGN_MUL,
  341. OP_ASSIGN_DIV,
  342. OP_ASSIGN_MOD,
  343. OP_ASSIGN_SHIFT_LEFT,
  344. OP_ASSIGN_SHIFT_RIGHT,
  345. OP_ASSIGN_BIT_AND,
  346. OP_ASSIGN_BIT_OR,
  347. OP_ASSIGN_BIT_XOR,
  348. OP_BIT_AND,
  349. OP_BIT_OR,
  350. OP_BIT_XOR,
  351. //ternary operators
  352. OP_TERNARY_IF,
  353. OP_TERNARY_ELSE,
  354. };
  355. Operator op;
  356. Vector<Node *> arguments;
  357. DataType datatype;
  358. virtual DataType get_datatype() const { return datatype; }
  359. virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
  360. OperatorNode() { type = TYPE_OPERATOR; }
  361. };
  362. struct PatternNode : public Node {
  363. enum PatternType {
  364. PT_CONSTANT,
  365. PT_BIND,
  366. PT_DICTIONARY,
  367. PT_ARRAY,
  368. PT_IGNORE_REST,
  369. PT_WILDCARD
  370. };
  371. PatternType pt_type;
  372. Node *constant;
  373. StringName bind;
  374. Map<ConstantNode *, PatternNode *> dictionary;
  375. Vector<PatternNode *> array;
  376. };
  377. struct PatternBranchNode : public Node {
  378. Vector<PatternNode *> patterns;
  379. BlockNode *body;
  380. };
  381. struct MatchNode : public Node {
  382. Node *val_to_match;
  383. Vector<PatternBranchNode *> branches;
  384. struct CompiledPatternBranch {
  385. Node *compiled_pattern;
  386. BlockNode *body;
  387. };
  388. Vector<CompiledPatternBranch> compiled_pattern_branches;
  389. };
  390. struct ControlFlowNode : public Node {
  391. enum CFType {
  392. CF_IF,
  393. CF_FOR,
  394. CF_WHILE,
  395. CF_BREAK,
  396. CF_CONTINUE,
  397. CF_RETURN,
  398. CF_MATCH
  399. };
  400. CFType cf_type;
  401. Vector<Node *> arguments;
  402. BlockNode *body;
  403. BlockNode *body_else;
  404. MatchNode *match;
  405. ControlFlowNode *_else; //used for if
  406. ControlFlowNode() {
  407. type = TYPE_CONTROL_FLOW;
  408. cf_type = CF_IF;
  409. body = nullptr;
  410. body_else = nullptr;
  411. }
  412. };
  413. struct CastNode : public Node {
  414. Node *source_node;
  415. DataType cast_type;
  416. DataType return_type;
  417. virtual DataType get_datatype() const { return return_type; }
  418. virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; }
  419. CastNode() { type = TYPE_CAST; }
  420. };
  421. struct AssertNode : public Node {
  422. Node *condition;
  423. Node *message;
  424. AssertNode() :
  425. condition(nullptr),
  426. message(nullptr) {
  427. type = TYPE_ASSERT;
  428. }
  429. };
  430. struct BreakpointNode : public Node {
  431. BreakpointNode() { type = TYPE_BREAKPOINT; }
  432. };
  433. struct NewLineNode : public Node {
  434. NewLineNode() { type = TYPE_NEWLINE; }
  435. };
  436. struct Expression {
  437. bool is_op;
  438. union {
  439. OperatorNode::Operator op;
  440. Node *node;
  441. };
  442. };
  443. enum CompletionType {
  444. COMPLETION_NONE,
  445. COMPLETION_BUILT_IN_TYPE_CONSTANT,
  446. COMPLETION_GET_NODE,
  447. COMPLETION_FUNCTION,
  448. COMPLETION_IDENTIFIER,
  449. COMPLETION_EXTENDS,
  450. COMPLETION_PARENT_FUNCTION,
  451. COMPLETION_METHOD,
  452. COMPLETION_CALL_ARGUMENTS,
  453. COMPLETION_RESOURCE_PATH,
  454. COMPLETION_INDEX,
  455. COMPLETION_VIRTUAL_FUNC,
  456. COMPLETION_YIELD,
  457. COMPLETION_ASSIGN,
  458. COMPLETION_TYPE_HINT,
  459. COMPLETION_TYPE_HINT_INDEX,
  460. };
  461. private:
  462. GDScriptTokenizer *tokenizer;
  463. Node *head;
  464. Node *list;
  465. template <class T>
  466. T *alloc_node();
  467. bool validating;
  468. bool for_completion;
  469. int parenthesis;
  470. bool error_set;
  471. String error;
  472. int error_line;
  473. int error_column;
  474. bool check_types;
  475. bool dependencies_only;
  476. List<String> dependencies;
  477. #ifdef DEBUG_ENABLED
  478. Set<int> *safe_lines;
  479. #endif // DEBUG_ENABLED
  480. #ifdef DEBUG_ENABLED
  481. List<GDScriptWarning> warnings;
  482. #endif // DEBUG_ENABLED
  483. int pending_newline;
  484. struct IndentLevel {
  485. int indent;
  486. int tabs;
  487. bool is_mixed(IndentLevel other) {
  488. return (
  489. (indent == other.indent && tabs != other.tabs) ||
  490. (indent > other.indent && tabs < other.tabs) ||
  491. (indent < other.indent && tabs > other.tabs));
  492. }
  493. IndentLevel() :
  494. indent(0),
  495. tabs(0) {}
  496. IndentLevel(int p_indent, int p_tabs) :
  497. indent(p_indent),
  498. tabs(p_tabs) {}
  499. };
  500. List<IndentLevel> indent_level;
  501. String base_path;
  502. String self_path;
  503. ClassNode *current_class;
  504. FunctionNode *current_function;
  505. BlockNode *current_block;
  506. bool _get_completable_identifier(CompletionType p_type, StringName &identifier);
  507. void _make_completable_call(int p_arg);
  508. CompletionType completion_type;
  509. StringName completion_cursor;
  510. Variant::Type completion_built_in_constant;
  511. Node *completion_node;
  512. ClassNode *completion_class;
  513. FunctionNode *completion_function;
  514. BlockNode *completion_block;
  515. int completion_line;
  516. int completion_argument;
  517. bool completion_found;
  518. bool completion_ident_is_call;
  519. PropertyInfo current_export;
  520. MultiplayerAPI::RPCMode rpc_mode;
  521. void _set_error(const String &p_error, int p_line = -1, int p_column = -1);
  522. #ifdef DEBUG_ENABLED
  523. void _add_warning(int p_code, int p_line = -1, const String &p_symbol1 = String(), const String &p_symbol2 = String(), const String &p_symbol3 = String(), const String &p_symbol4 = String());
  524. void _add_warning(int p_code, int p_line, const Vector<String> &p_symbols);
  525. #endif // DEBUG_ENABLED
  526. bool _recover_from_completion();
  527. bool _parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete = false, bool p_parsing_constant = false);
  528. bool _enter_indent_block(BlockNode *p_block = nullptr);
  529. bool _parse_newline();
  530. Node *_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign = false, bool p_parsing_constant = false);
  531. Node *_reduce_expression(Node *p_node, bool p_to_const = false);
  532. Node *_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const = false, bool p_allow_assign = false);
  533. bool _reduce_export_var_type(Variant &p_value, int p_line = 0);
  534. const Variant *_try_to_find_constant_value_for_expression(const Node *p_expr) const;
  535. PatternNode *_parse_pattern(bool p_static);
  536. void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static);
  537. void _transform_match_statment(MatchNode *p_match_statement);
  538. void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings);
  539. void _parse_block(BlockNode *p_block, bool p_static);
  540. void _parse_extends(ClassNode *p_class);
  541. void _parse_class(ClassNode *p_class);
  542. bool _end_statement();
  543. void _set_end_statement_error(String p_name);
  544. void _determine_inheritance(ClassNode *p_class, bool p_recursive = true);
  545. bool _parse_type(DataType &r_type, bool p_can_be_void = false);
  546. DataType _resolve_type(const DataType &p_source, int p_line);
  547. DataType _type_from_variant(const Variant &p_value) const;
  548. DataType _type_from_property(const PropertyInfo &p_property, bool p_nil_is_variant = true) const;
  549. DataType _type_from_gdtype(const GDScriptDataType &p_gdtype) const;
  550. DataType _get_operation_type(const Variant::Operator p_op, const DataType &p_a, const DataType &p_b, bool &r_valid) const;
  551. Variant::Operator _get_variant_operation(const OperatorNode::Operator &p_op) const;
  552. bool _get_function_signature(DataType &p_base_type, const StringName &p_function, DataType &r_return_type, List<DataType> &r_arg_types, int &r_default_arg_count, bool &r_static, bool &r_vararg) const;
  553. bool _get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type, bool *r_is_const = nullptr) const;
  554. bool _is_type_compatible(const DataType &p_container, const DataType &p_expression, bool p_allow_implicit_conversion = false) const;
  555. Node *_get_default_value_for_type(const DataType &p_type, int p_line = -1);
  556. DataType _reduce_node_type(Node *p_node);
  557. DataType _reduce_function_call_type(const OperatorNode *p_call);
  558. DataType _reduce_identifier_type(const DataType *p_base_type, const StringName &p_identifier, int p_line, bool p_is_indexing);
  559. void _check_class_level_types(ClassNode *p_class);
  560. void _check_class_blocks_types(ClassNode *p_class);
  561. void _check_function_types(FunctionNode *p_function);
  562. void _check_block_types(BlockNode *p_block);
  563. _FORCE_INLINE_ void _mark_line_as_safe(int p_line) const {
  564. #ifdef DEBUG_ENABLED
  565. if (safe_lines) {
  566. safe_lines->insert(p_line);
  567. }
  568. #endif // DEBUG_ENABLED
  569. }
  570. _FORCE_INLINE_ void _mark_line_as_unsafe(int p_line) const {
  571. #ifdef DEBUG_ENABLED
  572. if (safe_lines) {
  573. safe_lines->erase(p_line);
  574. }
  575. #endif // DEBUG_ENABLED
  576. }
  577. Error _parse(const String &p_base_path);
  578. public:
  579. bool has_error() const;
  580. String get_error() const;
  581. int get_error_line() const;
  582. int get_error_column() const;
  583. #ifdef DEBUG_ENABLED
  584. const List<GDScriptWarning> &get_warnings() const { return warnings; }
  585. #endif // DEBUG_ENABLED
  586. Error parse(const String &p_code, const String &p_base_path = "", bool p_just_validate = false, const String &p_self_path = "", bool p_for_completion = false, Set<int> *r_safe_lines = nullptr, bool p_dependencies_only = false);
  587. Error parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path = "", const String &p_self_path = "");
  588. bool is_tool_script() const;
  589. const Node *get_parse_tree() const;
  590. //completion info
  591. CompletionType get_completion_type();
  592. StringName get_completion_cursor();
  593. int get_completion_line();
  594. Variant::Type get_completion_built_in_constant();
  595. Node *get_completion_node();
  596. ClassNode *get_completion_class();
  597. BlockNode *get_completion_block();
  598. FunctionNode *get_completion_function();
  599. int get_completion_argument_index();
  600. int get_completion_identifier_is_function();
  601. const List<String> &get_dependencies() const { return dependencies; }
  602. void clear();
  603. GDScriptParser();
  604. ~GDScriptParser();
  605. };
  606. #endif // GDSCRIPT_PARSER_H