| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | /*  gdscript_parser.h                                                    */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | #ifndef GDSCRIPT_PARSER_H
 | 
					
						
							|  |  |  | #define GDSCRIPT_PARSER_H
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/map.h"
 | 
					
						
							|  |  |  | #include "core/object.h"
 | 
					
						
							|  |  |  | #include "core/script_language.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | #include "gdscript_functions.h"
 | 
					
						
							|  |  |  | #include "gdscript_tokenizer.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | struct GDScriptDataType; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | struct GDScriptWarning; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | class GDScriptParser { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 	struct ClassNode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct DataType { | 
					
						
							|  |  |  | 		enum { | 
					
						
							|  |  |  | 			BUILTIN, | 
					
						
							|  |  |  | 			NATIVE, | 
					
						
							|  |  |  | 			SCRIPT, | 
					
						
							|  |  |  | 			GDSCRIPT, | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			CLASS, | 
					
						
							|  |  |  | 			UNRESOLVED | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 		} kind; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool has_type; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		bool is_constant; | 
					
						
							|  |  |  | 		bool is_meta_type; // Whether the value can be used as a type
 | 
					
						
							| 
									
										
										
										
											2018-06-19 02:55:52 -03:00
										 |  |  | 		bool infer_type; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 		bool may_yield; // For function calls
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Variant::Type builtin_type; | 
					
						
							|  |  |  | 		StringName native_type; | 
					
						
							|  |  |  | 		Ref<Script> script_type; | 
					
						
							|  |  |  | 		ClassNode *class_type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:57 -03:00
										 |  |  | 		String to_string() const; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		bool operator==(const DataType &other) const { | 
					
						
							|  |  |  | 			if (!has_type || !other.has_type) { | 
					
						
							|  |  |  | 				return true; // Can be considered equal for parsing purpose
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (kind != other.kind) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			switch (kind) { | 
					
						
							|  |  |  | 				case BUILTIN: { | 
					
						
							|  |  |  | 					return builtin_type == other.builtin_type; | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case NATIVE: { | 
					
						
							|  |  |  | 					return native_type == other.native_type; | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDSCRIPT: | 
					
						
							|  |  |  | 				case SCRIPT: { | 
					
						
							|  |  |  | 					return script_type == other.script_type; | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case CLASS: { | 
					
						
							|  |  |  | 					return class_type == other.class_type; | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2018-09-26 13:13:56 +02:00
										 |  |  | 				case UNRESOLVED: { | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		DataType() : | 
					
						
							| 
									
										
										
										
											2019-01-30 02:12:41 +01:00
										 |  |  | 				kind(UNRESOLVED), | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 				has_type(false), | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 				is_constant(false), | 
					
						
							|  |  |  | 				is_meta_type(false), | 
					
						
							| 
									
										
										
										
											2018-06-19 02:55:52 -03:00
										 |  |  | 				infer_type(false), | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 				may_yield(false), | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 				builtin_type(Variant::NIL), | 
					
						
							|  |  |  | 				class_type(NULL) {} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	struct Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enum Type { | 
					
						
							|  |  |  | 			TYPE_CLASS, | 
					
						
							|  |  |  | 			TYPE_FUNCTION, | 
					
						
							|  |  |  | 			TYPE_BUILT_IN_FUNCTION, | 
					
						
							|  |  |  | 			TYPE_BLOCK, | 
					
						
							|  |  |  | 			TYPE_IDENTIFIER, | 
					
						
							|  |  |  | 			TYPE_TYPE, | 
					
						
							|  |  |  | 			TYPE_CONSTANT, | 
					
						
							|  |  |  | 			TYPE_ARRAY, | 
					
						
							|  |  |  | 			TYPE_DICTIONARY, | 
					
						
							|  |  |  | 			TYPE_SELF, | 
					
						
							|  |  |  | 			TYPE_OPERATOR, | 
					
						
							|  |  |  | 			TYPE_CONTROL_FLOW, | 
					
						
							|  |  |  | 			TYPE_LOCAL_VAR, | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 			TYPE_CAST, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			TYPE_ASSERT, | 
					
						
							| 
									
										
										
										
											2015-12-29 12:11:21 -03:00
										 |  |  | 			TYPE_BREAKPOINT, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			TYPE_NEWLINE, | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Node *next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		int line; | 
					
						
							|  |  |  | 		int column; | 
					
						
							|  |  |  | 		Type type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 		virtual DataType get_datatype() const { return DataType(); } | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		virtual void set_datatype(const DataType &p_datatype) {} | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		virtual ~Node() {} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct FunctionNode; | 
					
						
							|  |  |  | 	struct BlockNode; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:52 -03:00
										 |  |  | 	struct ConstantNode; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 	struct LocalVarNode; | 
					
						
							|  |  |  | 	struct OperatorNode; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct ClassNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool tool; | 
					
						
							|  |  |  | 		StringName name; | 
					
						
							|  |  |  | 		bool extends_used; | 
					
						
							| 
									
										
										
										
											2019-04-13 17:26:58 +02:00
										 |  |  | 		bool classname_used; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		StringName extends_file; | 
					
						
							|  |  |  | 		Vector<StringName> extends_class; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:52 -03:00
										 |  |  | 		DataType base_type; | 
					
						
							| 
									
										
										
										
											2018-07-28 22:36:43 -05:00
										 |  |  | 		String icon_path; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		struct Member { | 
					
						
							|  |  |  | 			PropertyInfo _export; | 
					
						
							|  |  |  | #ifdef TOOLS_ENABLED
 | 
					
						
							|  |  |  | 			Variant default_value; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			StringName identifier; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 			DataType data_type; | 
					
						
							| 
									
										
										
										
											2014-10-27 22:54:32 -03:00
										 |  |  | 			StringName setter; | 
					
						
							|  |  |  | 			StringName getter; | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 			int line; | 
					
						
							|  |  |  | 			Node *expression; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			OperatorNode *initial_assignment; | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 			MultiplayerAPI::RPCMode rpc_mode; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 			int usages; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2019-01-30 02:12:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		struct Constant { | 
					
						
							|  |  |  | 			Node *expression; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 			DataType type; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:29:23 -03:00
										 |  |  | 		struct Signal { | 
					
						
							|  |  |  | 			StringName name; | 
					
						
							|  |  |  | 			Vector<StringName> arguments; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 			int emissions; | 
					
						
							|  |  |  | 			int line; | 
					
						
							| 
									
										
										
										
											2015-06-24 13:29:23 -03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<ClassNode *> subclasses; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Vector<Member> variables; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		Map<StringName, Constant> constant_expressions; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<FunctionNode *> functions; | 
					
						
							|  |  |  | 		Vector<FunctionNode *> static_functions; | 
					
						
							| 
									
										
										
										
											2015-06-24 13:29:23 -03:00
										 |  |  | 		Vector<Signal> _signals; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		BlockNode *initializer; | 
					
						
							| 
									
										
										
										
											2015-12-28 19:31:52 -03:00
										 |  |  | 		BlockNode *ready; | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 		ClassNode *owner; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		//Vector<Node*> initializers;
 | 
					
						
							|  |  |  | 		int end_line; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ClassNode() { | 
					
						
							|  |  |  | 			tool = false; | 
					
						
							|  |  |  | 			type = TYPE_CLASS; | 
					
						
							|  |  |  | 			extends_used = false; | 
					
						
							| 
									
										
										
										
											2019-04-13 17:26:58 +02:00
										 |  |  | 			classname_used = false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			end_line = -1; | 
					
						
							|  |  |  | 			owner = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct FunctionNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool _static; | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 		MultiplayerAPI::RPCMode rpc_mode; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		bool has_yield; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 		bool has_unreachable_code; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		StringName name; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType return_type; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Vector<StringName> arguments; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		Vector<DataType> argument_types; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<Node *> default_values; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		BlockNode *body; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 		Vector<int> arguments_usage; | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		virtual DataType get_datatype() const { return return_type; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; } | 
					
						
							| 
									
										
										
										
											2019-01-16 01:38:37 -02:00
										 |  |  | 		int get_required_argument_count() { return arguments.size() - default_values.size(); } | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		FunctionNode() { | 
					
						
							|  |  |  | 			type = TYPE_FUNCTION; | 
					
						
							|  |  |  | 			_static = false; | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 			rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			has_yield = false; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 			has_unreachable_code = false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct BlockNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-17 10:45:02 -03:00
										 |  |  | 		ClassNode *parent_class; | 
					
						
							|  |  |  | 		BlockNode *parent_block; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		List<Node *> statements; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		Map<StringName, LocalVarNode *> variables; | 
					
						
							|  |  |  | 		bool has_return; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 00:34:32 -03:00
										 |  |  | 		Node *if_condition; //tiny hack to improve code completion on if () blocks
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		//the following is useful for code completion
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		List<BlockNode *> sub_blocks; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		int end_line; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		BlockNode() { | 
					
						
							| 
									
										
										
										
											2017-08-25 00:34:32 -03:00
										 |  |  | 			if_condition = NULL; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			type = TYPE_BLOCK; | 
					
						
							|  |  |  | 			end_line = -1; | 
					
						
							|  |  |  | 			parent_block = NULL; | 
					
						
							|  |  |  | 			parent_class = NULL; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			has_return = false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct TypeNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Variant::Type vtype; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		TypeNode() { type = TYPE_TYPE; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 	struct BuiltInFunctionNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | 		GDScriptFunctions::Function function; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		BuiltInFunctionNode() { type = TYPE_BUILT_IN_FUNCTION; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct IdentifierNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		StringName name; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		BlockNode *declared_block; // Simplify lookup by checking if it is declared locally
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		IdentifierNode() { | 
					
						
							|  |  |  | 			type = TYPE_IDENTIFIER; | 
					
						
							|  |  |  | 			declared_block = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct LocalVarNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		StringName name; | 
					
						
							|  |  |  | 		Node *assign; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		OperatorNode *assign_op; | 
					
						
							|  |  |  | 		int assignments; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 		int usages; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		LocalVarNode() { | 
					
						
							|  |  |  | 			type = TYPE_LOCAL_VAR; | 
					
						
							|  |  |  | 			assign = NULL; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 			assign_op = NULL; | 
					
						
							|  |  |  | 			assignments = 0; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | 			usages = 0; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ConstantNode : public Node { | 
					
						
							|  |  |  | 		Variant value; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ConstantNode() { type = TYPE_CONSTANT; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct ArrayNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<Node *> elements; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							|  |  |  | 		ArrayNode() { | 
					
						
							|  |  |  | 			type = TYPE_ARRAY; | 
					
						
							|  |  |  | 			datatype.has_type = true; | 
					
						
							|  |  |  | 			datatype.kind = DataType::BUILTIN; | 
					
						
							|  |  |  | 			datatype.builtin_type = Variant::ARRAY; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct DictionaryNode : public Node { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		struct Pair { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Node *key; | 
					
						
							|  |  |  | 			Node *value; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Pair> elements; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							|  |  |  | 		DictionaryNode() { | 
					
						
							|  |  |  | 			type = TYPE_DICTIONARY; | 
					
						
							|  |  |  | 			datatype.has_type = true; | 
					
						
							|  |  |  | 			datatype.kind = DataType::BUILTIN; | 
					
						
							|  |  |  | 			datatype.builtin_type = Variant::DICTIONARY; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct SelfNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		SelfNode() { type = TYPE_SELF; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct OperatorNode : public Node { | 
					
						
							|  |  |  | 		enum Operator { | 
					
						
							|  |  |  | 			//call/constructor operator
 | 
					
						
							|  |  |  | 			OP_CALL, | 
					
						
							|  |  |  | 			OP_PARENT_CALL, | 
					
						
							| 
									
										
										
										
											2014-09-15 11:33:30 -03:00
										 |  |  | 			OP_YIELD, | 
					
						
							| 
									
										
										
										
											2017-05-26 19:45:39 +02:00
										 |  |  | 			OP_IS, | 
					
						
							| 
									
										
										
										
											2018-08-26 13:31:23 -03:00
										 |  |  | 			OP_IS_BUILTIN, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			//indexing operator
 | 
					
						
							|  |  |  | 			OP_INDEX, | 
					
						
							|  |  |  | 			OP_INDEX_NAMED, | 
					
						
							|  |  |  | 			//unary operators
 | 
					
						
							|  |  |  | 			OP_NEG, | 
					
						
							| 
									
										
										
										
											2016-10-12 18:43:59 -03:00
										 |  |  | 			OP_POS, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			OP_NOT, | 
					
						
							|  |  |  | 			OP_BIT_INVERT, | 
					
						
							|  |  |  | 			//binary operators (in precedence order)
 | 
					
						
							|  |  |  | 			OP_IN, | 
					
						
							|  |  |  | 			OP_EQUAL, | 
					
						
							|  |  |  | 			OP_NOT_EQUAL, | 
					
						
							|  |  |  | 			OP_LESS, | 
					
						
							|  |  |  | 			OP_LESS_EQUAL, | 
					
						
							|  |  |  | 			OP_GREATER, | 
					
						
							|  |  |  | 			OP_GREATER_EQUAL, | 
					
						
							|  |  |  | 			OP_AND, | 
					
						
							|  |  |  | 			OP_OR, | 
					
						
							|  |  |  | 			OP_ADD, | 
					
						
							|  |  |  | 			OP_SUB, | 
					
						
							|  |  |  | 			OP_MUL, | 
					
						
							|  |  |  | 			OP_DIV, | 
					
						
							|  |  |  | 			OP_MOD, | 
					
						
							|  |  |  | 			OP_SHIFT_LEFT, | 
					
						
							|  |  |  | 			OP_SHIFT_RIGHT, | 
					
						
							| 
									
										
										
										
											2014-11-02 11:31:01 -03:00
										 |  |  | 			OP_INIT_ASSIGN, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			OP_ASSIGN, | 
					
						
							|  |  |  | 			OP_ASSIGN_ADD, | 
					
						
							|  |  |  | 			OP_ASSIGN_SUB, | 
					
						
							|  |  |  | 			OP_ASSIGN_MUL, | 
					
						
							|  |  |  | 			OP_ASSIGN_DIV, | 
					
						
							|  |  |  | 			OP_ASSIGN_MOD, | 
					
						
							|  |  |  | 			OP_ASSIGN_SHIFT_LEFT, | 
					
						
							|  |  |  | 			OP_ASSIGN_SHIFT_RIGHT, | 
					
						
							|  |  |  | 			OP_ASSIGN_BIT_AND, | 
					
						
							|  |  |  | 			OP_ASSIGN_BIT_OR, | 
					
						
							|  |  |  | 			OP_ASSIGN_BIT_XOR, | 
					
						
							|  |  |  | 			OP_BIT_AND, | 
					
						
							|  |  |  | 			OP_BIT_OR, | 
					
						
							| 
									
										
										
										
											2014-09-15 11:33:30 -03:00
										 |  |  | 			OP_BIT_XOR, | 
					
						
							| 
									
										
										
										
											2016-08-25 21:18:35 +03:00
										 |  |  | 			//ternary operators
 | 
					
						
							|  |  |  | 			OP_TERNARY_IF, | 
					
						
							|  |  |  | 			OP_TERNARY_ELSE, | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Operator op; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<Node *> arguments; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType datatype; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return datatype; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; } | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		OperatorNode() { type = TYPE_OPERATOR; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 	struct PatternNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 		enum PatternType { | 
					
						
							|  |  |  | 			PT_CONSTANT, | 
					
						
							|  |  |  | 			PT_BIND, | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 			PT_DICTIONARY, | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 			PT_ARRAY, | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 			PT_IGNORE_REST, | 
					
						
							|  |  |  | 			PT_WILDCARD | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 		PatternType pt_type; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 		Node *constant; | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 		StringName bind; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Map<ConstantNode *, PatternNode *> dictionary; | 
					
						
							|  |  |  | 		Vector<PatternNode *> array; | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 	struct PatternBranchNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<PatternNode *> patterns; | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 		BlockNode *body; | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 	struct MatchNode : public Node { | 
					
						
							|  |  |  | 		Node *val_to_match; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<PatternBranchNode *> branches; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-16 13:20:28 +02:00
										 |  |  | 		struct CompiledPatternBranch { | 
					
						
							|  |  |  | 			Node *compiled_pattern; | 
					
						
							|  |  |  | 			BlockNode *body; | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-16 13:20:28 +02:00
										 |  |  | 		Vector<CompiledPatternBranch> compiled_pattern_branches; | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct ControlFlowNode : public Node { | 
					
						
							|  |  |  | 		enum CFType { | 
					
						
							|  |  |  | 			CF_IF, | 
					
						
							|  |  |  | 			CF_FOR, | 
					
						
							|  |  |  | 			CF_WHILE, | 
					
						
							|  |  |  | 			CF_BREAK, | 
					
						
							|  |  |  | 			CF_CONTINUE, | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 			CF_RETURN, | 
					
						
							|  |  |  | 			CF_MATCH | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		CFType cf_type; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector<Node *> arguments; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		BlockNode *body; | 
					
						
							|  |  |  | 		BlockNode *body_else; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-05 18:48:38 +02:00
										 |  |  | 		MatchNode *match; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		ControlFlowNode *_else; //used for if
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ControlFlowNode() { | 
					
						
							|  |  |  | 			type = TYPE_CONTROL_FLOW; | 
					
						
							|  |  |  | 			cf_type = CF_IF; | 
					
						
							|  |  |  | 			body = NULL; | 
					
						
							|  |  |  | 			body_else = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 	struct CastNode : public Node { | 
					
						
							|  |  |  | 		Node *source_node; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:53 -03:00
										 |  |  | 		DataType cast_type; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		DataType return_type; | 
					
						
							|  |  |  | 		virtual DataType get_datatype() const { return return_type; } | 
					
						
							|  |  |  | 		virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; } | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 		CastNode() { type = TYPE_CAST; } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	struct AssertNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Node *condition; | 
					
						
							| 
									
										
										
										
											2019-08-06 13:28:22 +02:00
										 |  |  | 		Node *message; | 
					
						
							|  |  |  | 		AssertNode() : | 
					
						
							|  |  |  | 				condition(0), | 
					
						
							|  |  |  | 				message(0) { | 
					
						
							|  |  |  | 			type = TYPE_ASSERT; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-09-15 11:33:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 12:11:21 -03:00
										 |  |  | 	struct BreakpointNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		BreakpointNode() { type = TYPE_BREAKPOINT; } | 
					
						
							| 
									
										
										
										
											2015-12-29 12:11:21 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	struct NewLineNode : public Node { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		NewLineNode() { type = TYPE_NEWLINE; } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct Expression { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool is_op; | 
					
						
							|  |  |  | 		union { | 
					
						
							|  |  |  | 			OperatorNode::Operator op; | 
					
						
							|  |  |  | 			Node *node; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 	enum CompletionType { | 
					
						
							|  |  |  | 		COMPLETION_NONE, | 
					
						
							|  |  |  | 		COMPLETION_BUILT_IN_TYPE_CONSTANT, | 
					
						
							| 
									
										
										
										
											2017-01-08 02:04:53 -03:00
										 |  |  | 		COMPLETION_GET_NODE, | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 		COMPLETION_FUNCTION, | 
					
						
							|  |  |  | 		COMPLETION_IDENTIFIER, | 
					
						
							|  |  |  | 		COMPLETION_PARENT_FUNCTION, | 
					
						
							|  |  |  | 		COMPLETION_METHOD, | 
					
						
							|  |  |  | 		COMPLETION_CALL_ARGUMENTS, | 
					
						
							| 
									
										
										
										
											2017-05-08 22:39:27 +03:00
										 |  |  | 		COMPLETION_RESOURCE_PATH, | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 		COMPLETION_INDEX, | 
					
						
							| 
									
										
										
										
											2016-08-06 22:11:03 -03:00
										 |  |  | 		COMPLETION_VIRTUAL_FUNC, | 
					
						
							|  |  |  | 		COMPLETION_YIELD, | 
					
						
							| 
									
										
										
										
											2017-08-24 00:06:56 -03:00
										 |  |  | 		COMPLETION_ASSIGN, | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 		COMPLETION_TYPE_HINT, | 
					
						
							|  |  |  | 		COMPLETION_TYPE_HINT_INDEX, | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | 	GDScriptTokenizer *tokenizer; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Node *head; | 
					
						
							|  |  |  | 	Node *list; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	template <class T> | 
					
						
							|  |  |  | 	T *alloc_node(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 23:21:45 -03:00
										 |  |  | 	bool validating; | 
					
						
							| 
									
										
										
										
											2015-06-26 01:14:31 -03:00
										 |  |  | 	bool for_completion; | 
					
						
							| 
									
										
										
										
											2014-04-05 18:50:09 -03:00
										 |  |  | 	int parenthesis; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	bool error_set; | 
					
						
							|  |  |  | 	String error; | 
					
						
							|  |  |  | 	int error_line; | 
					
						
							|  |  |  | 	int error_column; | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 	bool check_types; | 
					
						
							| 
									
										
										
										
											2019-03-03 16:36:42 -03:00
										 |  |  | 	bool dependencies_only; | 
					
						
							|  |  |  | 	List<String> dependencies; | 
					
						
							| 
									
										
										
										
											2018-06-05 13:50:21 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	Set<int> *safe_lines; | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	List<GDScriptWarning> warnings; | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-24 01:35:47 -03:00
										 |  |  | 	int pending_newline; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-13 22:48:18 +03:00
										 |  |  | 	struct IndentLevel { | 
					
						
							|  |  |  | 		int indent; | 
					
						
							|  |  |  | 		int tabs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool is_mixed(IndentLevel other) { | 
					
						
							|  |  |  | 			return ( | 
					
						
							|  |  |  | 					(indent == other.indent && tabs != other.tabs) || | 
					
						
							|  |  |  | 					(indent > other.indent && tabs < other.tabs) || | 
					
						
							|  |  |  | 					(indent < other.indent && tabs > other.tabs)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		IndentLevel() : | 
					
						
							|  |  |  | 				indent(0), | 
					
						
							|  |  |  | 				tabs(0) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		IndentLevel(int p_indent, int p_tabs) : | 
					
						
							|  |  |  | 				indent(p_indent), | 
					
						
							|  |  |  | 				tabs(p_tabs) {} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<IndentLevel> indent_level; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String base_path; | 
					
						
							| 
									
										
										
										
											2014-12-07 02:04:20 -03:00
										 |  |  | 	String self_path; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 	ClassNode *current_class; | 
					
						
							|  |  |  | 	FunctionNode *current_function; | 
					
						
							|  |  |  | 	BlockNode *current_block; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool _get_completable_identifier(CompletionType p_type, StringName &identifier); | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 	void _make_completable_call(int p_arg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CompletionType completion_type; | 
					
						
							|  |  |  | 	StringName completion_cursor; | 
					
						
							|  |  |  | 	Variant::Type completion_built_in_constant; | 
					
						
							|  |  |  | 	Node *completion_node; | 
					
						
							|  |  |  | 	ClassNode *completion_class; | 
					
						
							|  |  |  | 	FunctionNode *completion_function; | 
					
						
							|  |  |  | 	BlockNode *completion_block; | 
					
						
							|  |  |  | 	int completion_line; | 
					
						
							|  |  |  | 	int completion_argument; | 
					
						
							| 
									
										
										
										
											2015-08-30 11:50:10 -03:00
										 |  |  | 	bool completion_found; | 
					
						
							| 
									
										
										
										
											2016-09-12 10:52:29 -03:00
										 |  |  | 	bool completion_ident_is_call; | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	PropertyInfo current_export; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-13 07:07:56 +02:00
										 |  |  | 	MultiplayerAPI::RPCMode rpc_mode; | 
					
						
							| 
									
										
										
										
											2016-08-19 16:48:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void _set_error(const String &p_error, int p_line = -1, int p_column = -1); | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	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()); | 
					
						
							|  |  |  | 	void _add_warning(int p_code, int p_line, const Vector<String> &p_symbols); | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							| 
									
										
										
										
											2015-08-30 11:50:10 -03:00
										 |  |  | 	bool _recover_from_completion(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 17:28:50 +03:00
										 |  |  | 	bool _parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete = false, bool p_parsing_constant = false); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool _enter_indent_block(BlockNode *p_block = NULL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	bool _parse_newline(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Node *_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign = false, bool p_parsing_constant = false); | 
					
						
							|  |  |  | 	Node *_reduce_expression(Node *p_node, bool p_to_const = false); | 
					
						
							|  |  |  | 	Node *_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const = false, bool p_allow_assign = false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-30 21:40:31 +02:00
										 |  |  | 	PatternNode *_parse_pattern(bool p_static); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static); | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 	void _transform_match_statment(MatchNode *p_match_statement); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void _parse_block(BlockNode *p_block, bool p_static); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void _parse_extends(ClassNode *p_class); | 
					
						
							|  |  |  | 	void _parse_class(ClassNode *p_class); | 
					
						
							|  |  |  | 	bool _end_statement(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 17:59:29 +03:00
										 |  |  | 	void _determine_inheritance(ClassNode *p_class, bool p_recursive = true); | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 	bool _parse_type(DataType &r_type, bool p_can_be_void = false); | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 	DataType _resolve_type(const DataType &p_source, int p_line); | 
					
						
							|  |  |  | 	DataType _type_from_variant(const Variant &p_value) const; | 
					
						
							|  |  |  | 	DataType _type_from_property(const PropertyInfo &p_property, bool p_nil_is_variant = true) const; | 
					
						
							|  |  |  | 	DataType _type_from_gdtype(const GDScriptDataType &p_gdtype) const; | 
					
						
							|  |  |  | 	DataType _get_operation_type(const Variant::Operator p_op, const DataType &p_a, const DataType &p_b, bool &r_valid) const; | 
					
						
							|  |  |  | 	Variant::Operator _get_variant_operation(const OperatorNode::Operator &p_op) const; | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 	bool _get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type) const; | 
					
						
							| 
									
										
										
										
											2019-03-04 12:25:59 +01:00
										 |  |  | 	bool _is_type_compatible(const DataType &p_container, const DataType &p_expression, bool p_allow_implicit_conversion = false) const; | 
					
						
							| 
									
										
										
										
											2019-09-03 10:39:04 +03:00
										 |  |  | 	Node *_get_default_value_for_type(const DataType &p_type, int p_line = -1); | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DataType _reduce_node_type(Node *p_node); | 
					
						
							|  |  |  | 	DataType _reduce_function_call_type(const OperatorNode *p_call); | 
					
						
							| 
									
										
										
										
											2019-01-16 16:02:56 -02:00
										 |  |  | 	DataType _reduce_identifier_type(const DataType *p_base_type, const StringName &p_identifier, int p_line, bool p_is_indexing); | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:54 -03:00
										 |  |  | 	void _check_class_level_types(ClassNode *p_class); | 
					
						
							|  |  |  | 	void _check_class_blocks_types(ClassNode *p_class); | 
					
						
							|  |  |  | 	void _check_function_types(FunctionNode *p_function); | 
					
						
							|  |  |  | 	void _check_block_types(BlockNode *p_block); | 
					
						
							| 
									
										
										
										
											2018-06-05 13:50:21 -03:00
										 |  |  | 	_FORCE_INLINE_ void _mark_line_as_safe(int p_line) const { | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 		if (safe_lines) safe_lines->insert(p_line); | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	_FORCE_INLINE_ void _mark_line_as_unsafe(int p_line) const { | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 		if (safe_lines) safe_lines->erase(p_line); | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-29 23:16:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Error _parse(const String &p_base_path); | 
					
						
							| 
									
										
										
										
											2014-02-25 09:31:47 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-06-14 22:38:54 +08:00
										 |  |  | 	bool has_error() const; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	String get_error() const; | 
					
						
							|  |  |  | 	int get_error_line() const; | 
					
						
							|  |  |  | 	int get_error_column() const; | 
					
						
							| 
									
										
										
										
											2018-07-01 13:17:40 -03:00
										 |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	const List<GDScriptWarning> &get_warnings() const { return warnings; } | 
					
						
							|  |  |  | #endif // DEBUG_ENABLED
 | 
					
						
							| 
									
										
										
										
											2019-03-03 16:36:42 -03:00
										 |  |  | 	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 = NULL, bool p_dependencies_only = false); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Error parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path = "", const String &p_self_path = ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 15:36:03 -03:00
										 |  |  | 	bool is_tool_script() const; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	const Node *get_parse_tree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 	//completion info
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CompletionType get_completion_type(); | 
					
						
							|  |  |  | 	StringName get_completion_cursor(); | 
					
						
							|  |  |  | 	int get_completion_line(); | 
					
						
							|  |  |  | 	Variant::Type get_completion_built_in_constant(); | 
					
						
							|  |  |  | 	Node *get_completion_node(); | 
					
						
							|  |  |  | 	ClassNode *get_completion_class(); | 
					
						
							|  |  |  | 	BlockNode *get_completion_block(); | 
					
						
							|  |  |  | 	FunctionNode *get_completion_function(); | 
					
						
							|  |  |  | 	int get_completion_argument_index(); | 
					
						
							| 
									
										
										
										
											2016-09-12 10:52:29 -03:00
										 |  |  | 	int get_completion_identifier_is_function(); | 
					
						
							| 
									
										
										
										
											2014-12-16 22:31:57 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-03 16:36:42 -03:00
										 |  |  | 	const List<String> &get_dependencies() const { return dependencies; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	void clear(); | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | 	GDScriptParser(); | 
					
						
							|  |  |  | 	~GDScriptParser(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 18:38:18 +01:00
										 |  |  | #endif // GDSCRIPT_PARSER_H
 |