| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  test_gdscript.cpp                                                    */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-03-05 15:47:28 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2017-04-08 00:11:42 +02:00
										 |  |  | /* Copyright (c) 2014-2017 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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "test_gdscript.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "os/file_access.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "os/main_loop.h"
 | 
					
						
							|  |  |  | #include "os/os.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef GDSCRIPT_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 09:53:33 -03:00
										 |  |  | #include "modules/gdscript/gd_compiler.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "modules/gdscript/gd_parser.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 09:53:33 -03:00
										 |  |  | #include "modules/gdscript/gd_script.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "modules/gdscript/gd_tokenizer.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace TestGDScript { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _print_indent(int p_ident, const String &p_text) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_ident; i++) { | 
					
						
							|  |  |  | 		txt += '\t'; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	print_line(txt + p_text); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static String _parser_extends(const GDParser::ClassNode *p_class) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	String txt = "extends "; | 
					
						
							|  |  |  | 	if (String(p_class->extends_file) != "") { | 
					
						
							|  |  |  | 		txt += "\"" + p_class->extends_file + "\""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (p_class->extends_class.size()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "."; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->extends_class.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (i != 0) | 
					
						
							|  |  |  | 			txt += "."; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		txt += p_class->extends_class[i]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return txt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static String _parser_expr(const GDParser::Node *p_expr) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_expr->type) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_IDENTIFIER: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 			const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt = id_node->name; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_CONSTANT: { | 
					
						
							|  |  |  | 			const GDParser::ConstantNode *c_node = static_cast<const GDParser::ConstantNode *>(p_expr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (c_node->value.get_type() == Variant::STRING) | 
					
						
							|  |  |  | 				txt = "\"" + String(c_node->value) + "\""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				txt = c_node->value; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_SELF: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt = "self"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_ARRAY: { | 
					
						
							|  |  |  | 			const GDParser::ArrayNode *arr_node = static_cast<const GDParser::ArrayNode *>(p_expr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "["; | 
					
						
							|  |  |  | 			for (int i = 0; i < arr_node->elements.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (i > 0) | 
					
						
							|  |  |  | 					txt += ", "; | 
					
						
							|  |  |  | 				txt += _parser_expr(arr_node->elements[i]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "]"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_DICTIONARY: { | 
					
						
							|  |  |  | 			const GDParser::DictionaryNode *dict_node = static_cast<const GDParser::DictionaryNode *>(p_expr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "{"; | 
					
						
							|  |  |  | 			for (int i = 0; i < dict_node->elements.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (i > 0) | 
					
						
							|  |  |  | 					txt += ", "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				const GDParser::DictionaryNode::Pair &p = dict_node->elements[i]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				txt += _parser_expr(p.key); | 
					
						
							|  |  |  | 				txt += ":"; | 
					
						
							|  |  |  | 				txt += _parser_expr(p.value); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "}"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_OPERATOR: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const GDParser::OperatorNode *c_node = static_cast<const GDParser::OperatorNode *>(p_expr); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			switch (c_node->op) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_PARENT_CALL: | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += "."; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				case GDParser::OperatorNode::OP_CALL: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					ERR_FAIL_COND_V(c_node->arguments.size() < 1, ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					String func_name; | 
					
						
							|  |  |  | 					const GDParser::Node *nfunc = c_node->arguments[0]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int arg_ofs = 0; | 
					
						
							|  |  |  | 					if (nfunc->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						const GDParser::BuiltInFunctionNode *bif_node = static_cast<const GDParser::BuiltInFunctionNode *>(nfunc); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						func_name = GDFunctions::get_func_name(bif_node->function); | 
					
						
							|  |  |  | 						arg_ofs = 1; | 
					
						
							|  |  |  | 					} else if (nfunc->type == GDParser::Node::TYPE_TYPE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						const GDParser::TypeNode *t_node = static_cast<const GDParser::TypeNode *>(nfunc); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						func_name = Variant::get_type_name(t_node->vtype); | 
					
						
							|  |  |  | 						arg_ofs = 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						ERR_FAIL_COND_V(c_node->arguments.size() < 2, ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						nfunc = c_node->arguments[1]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						ERR_FAIL_COND_V(nfunc->type != GDParser::Node::TYPE_IDENTIFIER, ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						if (c_node->arguments[0]->type != GDParser::Node::TYPE_SELF) | 
					
						
							|  |  |  | 							func_name = _parser_expr(c_node->arguments[0]) + "."; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						func_name += _parser_expr(nfunc); | 
					
						
							|  |  |  | 						arg_ofs = 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += func_name + "("; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int i = arg_ofs; i < c_node->arguments.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						const GDParser::Node *arg = c_node->arguments[i]; | 
					
						
							|  |  |  | 						if (i > arg_ofs) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += _parser_expr(arg); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_INDEX: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					ERR_FAIL_COND_V(c_node->arguments.size() != 2, ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					//index with []
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "[" + _parser_expr(c_node->arguments[1]) + "]"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_INDEX_NAMED: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					ERR_FAIL_COND_V(c_node->arguments.size() != 2, ""); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "." + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_NEG: { | 
					
						
							|  |  |  | 					txt = "-" + _parser_expr(c_node->arguments[0]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_NOT: { | 
					
						
							|  |  |  | 					txt = "not " + _parser_expr(c_node->arguments[0]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_BIT_INVERT: { | 
					
						
							|  |  |  | 					txt = "~" + _parser_expr(c_node->arguments[0]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_PREINC: { | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_PREDEC: { | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_INC: { | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_DEC: { | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_IN: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + " in " + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_EQUAL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "==" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_NOT_EQUAL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "!=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_LESS: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "<" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_LESS_EQUAL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "<=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_GREATER: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + ">" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_GREATER_EQUAL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + ">=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_AND: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + " and " + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_OR: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + " or " + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ADD: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "+" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_SUB: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "-" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_MUL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "*" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_DIV: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "/" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_MOD: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "%" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_SHIFT_LEFT: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "<<" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_SHIFT_RIGHT: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + ">>" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_ADD: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "+=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_SUB: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "-=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_MUL: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "*=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_DIV: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "/=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_MOD: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "%=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "<<=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + ">>=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "&=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "|=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "^=" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_BIT_AND: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "&" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_BIT_OR: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "|" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDParser::OperatorNode::OP_BIT_XOR: { | 
					
						
							|  |  |  | 					txt = _parser_expr(c_node->arguments[0]) + "^" + _parser_expr(c_node->arguments[1]); | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				default: {} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDParser::Node::TYPE_NEWLINE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//skippie
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		default: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			String error = "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			ERR_EXPLAIN(error); | 
					
						
							|  |  |  | 			ERR_FAIL_V(""); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return txt; | 
					
						
							|  |  |  | 	//return "("+txt+")";
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _parser_show_block(const GDParser::BlockNode *p_block, int p_indent) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_block->statements.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDParser::Node *statement = p_block->statements[i]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		switch (statement->type) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			case GDParser::Node::TYPE_CONTROL_FLOW: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				const GDParser::ControlFlowNode *cf_node = static_cast<const GDParser::ControlFlowNode *>(statement); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				switch (cf_node->cf_type) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_IF: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						ERR_FAIL_COND(cf_node->arguments.size() != 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += "if "; | 
					
						
							|  |  |  | 						txt += _parser_expr(cf_node->arguments[0]); | 
					
						
							|  |  |  | 						txt += ":"; | 
					
						
							|  |  |  | 						_print_indent(p_indent, txt); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						ERR_FAIL_COND(!cf_node->body); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_parser_show_block(cf_node->body, p_indent + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						if (cf_node->body_else) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							_print_indent(p_indent, "else:"); | 
					
						
							|  |  |  | 							_parser_show_block(cf_node->body_else, p_indent + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_FOR: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						ERR_FAIL_COND(cf_node->arguments.size() != 2); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += "for "; | 
					
						
							|  |  |  | 						txt += _parser_expr(cf_node->arguments[0]); | 
					
						
							|  |  |  | 						txt += " in "; | 
					
						
							|  |  |  | 						txt += _parser_expr(cf_node->arguments[1]); | 
					
						
							|  |  |  | 						txt += ":"; | 
					
						
							|  |  |  | 						_print_indent(p_indent, txt); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						ERR_FAIL_COND(!cf_node->body); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_parser_show_block(cf_node->body, p_indent + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_WHILE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						ERR_FAIL_COND(cf_node->arguments.size() != 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += "while "; | 
					
						
							|  |  |  | 						txt += _parser_expr(cf_node->arguments[0]); | 
					
						
							|  |  |  | 						txt += ":"; | 
					
						
							|  |  |  | 						_print_indent(p_indent, txt); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						ERR_FAIL_COND(!cf_node->body); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_parser_show_block(cf_node->body, p_indent + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_SWITCH: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_CONTINUE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_print_indent(p_indent, "continue"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_BREAK: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						_print_indent(p_indent, "break"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} break; | 
					
						
							|  |  |  | 					case GDParser::ControlFlowNode::CF_RETURN: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						if (cf_node->arguments.size()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							_print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0])); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							_print_indent(p_indent, "return "); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} break; | 
					
						
							|  |  |  | 			case GDParser::Node::TYPE_LOCAL_VAR: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				const GDParser::LocalVarNode *lv_node = static_cast<const GDParser::LocalVarNode *>(statement); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				_print_indent(p_indent, "var " + String(lv_node->name)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} break; | 
					
						
							|  |  |  | 			default: { | 
					
						
							|  |  |  | 				//expression i guess
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				_print_indent(p_indent, _parser_expr(statement)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _parser_show_function(const GDParser::FunctionNode *p_func, int p_indent, GDParser::BlockNode *p_initializer = NULL) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String txt; | 
					
						
							|  |  |  | 	if (p_func->_static) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		txt = "static "; | 
					
						
							|  |  |  | 	txt += "func "; | 
					
						
							|  |  |  | 	if (p_func->name == "") // initializer
 | 
					
						
							|  |  |  | 		txt += "[built-in-initializer]"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		txt += String(p_func->name); | 
					
						
							|  |  |  | 	txt += "("; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_func->arguments.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (i != 0) | 
					
						
							|  |  |  | 			txt += ", "; | 
					
						
							|  |  |  | 		txt += "var " + String(p_func->arguments[i]); | 
					
						
							|  |  |  | 		if (i >= (p_func->arguments.size() - p_func->default_values.size())) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			int defarg = i - (p_func->arguments.size() - p_func->default_values.size()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			txt += "="; | 
					
						
							|  |  |  | 			txt += _parser_expr(p_func->default_values[defarg]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//todo constructor check!
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	txt += ":"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	_print_indent(p_indent, txt); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (p_initializer) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_parser_show_block(p_initializer, p_indent + 1); | 
					
						
							|  |  |  | 	_parser_show_block(p_func->body, p_indent + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _parser_show_class(const GDParser::ClassNode *p_class, int p_indent, const Vector<String> &p_code) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_indent == 0 && (String(p_class->extends_file) != "" || p_class->extends_class.size())) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_print_indent(p_indent, _parser_extends(p_class)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		print_line("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->subclasses.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDParser::ClassNode *subclass = p_class->subclasses[i]; | 
					
						
							|  |  |  | 		String line = "class " + subclass->name; | 
					
						
							|  |  |  | 		if (String(subclass->extends_file) != "" || subclass->extends_class.size()) | 
					
						
							|  |  |  | 			line += " " + _parser_extends(subclass); | 
					
						
							|  |  |  | 		line += ":"; | 
					
						
							|  |  |  | 		_print_indent(p_indent, line); | 
					
						
							|  |  |  | 		_parser_show_class(subclass, p_indent + 1, p_code); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		print_line("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->constant_expressions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDParser::ClassNode::Constant &constant = p_class->constant_expressions[i]; | 
					
						
							|  |  |  | 		_print_indent(p_indent, "const " + String(constant.identifier) + "=" + _parser_expr(constant.expression)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->variables.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDParser::ClassNode::Member &m = p_class->variables[i]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_print_indent(p_indent, "var " + String(m.identifier)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	print_line("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->static_functions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_parser_show_function(p_class->static_functions[i], p_indent); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		print_line("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < p_class->functions.size(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (String(p_class->functions[i]->name) == "_init") { | 
					
						
							|  |  |  | 			_parser_show_function(p_class->functions[i], p_indent, p_class->initializer); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			_parser_show_function(p_class->functions[i], p_indent); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		print_line("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//_parser_show_function(p_class->initializer,p_indent);
 | 
					
						
							|  |  |  | 	print_line("\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static String _disassemble_addr(const Ref<GDScript> &p_script, const GDFunction &func, int p_addr) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int addr = p_addr & GDFunction::ADDR_MASK; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_addr >> GDFunction::ADDR_BITS) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_SELF: { | 
					
						
							|  |  |  | 			return "self"; | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-05-01 11:34:10 -03:00
										 |  |  | 		case GDFunction::ADDR_TYPE_CLASS: { | 
					
						
							|  |  |  | 			return "class"; | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case GDFunction::ADDR_TYPE_MEMBER: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			return "member(" + p_script->debug_get_member_by_index(addr) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_CLASS_CONSTANT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			return "class_const(" + func.get_global_name(addr) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_LOCAL_CONSTANT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			Variant v = func.get_constant(addr); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			String txt; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH) | 
					
						
							|  |  |  | 				txt = "\"" + String(v) + "\""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				txt = v; | 
					
						
							|  |  |  | 			return "const(" + txt + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_STACK: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			return "stack(" + itos(addr) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_STACK_VARIABLE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			return "var_stack(" + itos(addr) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_GLOBAL: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			return "global(" + func.get_global_name(addr) + ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case GDFunction::ADDR_TYPE_NIL: { | 
					
						
							|  |  |  | 			return "nil"; | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return "<err>"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String> &p_code) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	const Map<StringName, GDFunction *> &mf = p_class->debug_get_member_functions(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (const Map<StringName, GDFunction *>::Element *E = mf.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDFunction &func = *E->get(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		const int *code = func.get_code(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int codelen = func.get_code_size(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		String defargs; | 
					
						
							|  |  |  | 		if (func.get_default_argument_count()) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			defargs = "defarg at: "; | 
					
						
							|  |  |  | 			for (int i = 0; i < func.get_default_argument_count(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (i > 0) | 
					
						
							|  |  |  | 					defargs += ","; | 
					
						
							|  |  |  | 				defargs += itos(func.get_default_argument_addr(i)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			defargs += " "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		print_line("== function " + String(func.get_name()) + "() :: stack size: " + itos(func.get_max_stack_size()) + " " + defargs + "=="); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #define DADDR(m_ip) (_disassemble_addr(p_class, func, code[ip + m_ip]))
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int ip = 0; ip < codelen;) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int incr = 0; | 
					
						
							|  |  |  | 			String txt = itos(ip) + " "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			switch (code[ip]) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_OPERATOR: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int op = code[ip + 1]; | 
					
						
							|  |  |  | 					txt += "op "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					String opname = Variant::get_operator_name(Variant::Operator(op)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += DADDR(4); | 
					
						
							|  |  |  | 					txt += " = "; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					txt += " " + opname + " "; | 
					
						
							|  |  |  | 					txt += DADDR(3); | 
					
						
							|  |  |  | 					incr += 5; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_SET: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += "set "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "["; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					txt += "]="; | 
					
						
							|  |  |  | 					txt += DADDR(3); | 
					
						
							|  |  |  | 					incr += 4; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_GET: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " get "; | 
					
						
							|  |  |  | 					txt += DADDR(3); | 
					
						
							|  |  |  | 					txt += "="; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "["; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					txt += "]"; | 
					
						
							|  |  |  | 					incr += 4; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_SET_NAMED: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " set_named "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "[\""; | 
					
						
							|  |  |  | 					txt += func.get_global_name(code[ip + 2]); | 
					
						
							|  |  |  | 					txt += "\"]="; | 
					
						
							|  |  |  | 					txt += DADDR(3); | 
					
						
							|  |  |  | 					incr += 4; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_GET_NAMED: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " get_named "; | 
					
						
							|  |  |  | 					txt += DADDR(3); | 
					
						
							|  |  |  | 					txt += "="; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "[\""; | 
					
						
							|  |  |  | 					txt += func.get_global_name(code[ip + 2]); | 
					
						
							|  |  |  | 					txt += "\"]"; | 
					
						
							|  |  |  | 					incr += 4; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 17:37:45 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_SET_MEMBER: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " set_member "; | 
					
						
							|  |  |  | 					txt += "[\""; | 
					
						
							|  |  |  | 					txt += func.get_global_name(code[ip + 1]); | 
					
						
							|  |  |  | 					txt += "\"]="; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					incr += 3; | 
					
						
							| 
									
										
										
										
											2017-01-04 17:37:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_GET_MEMBER: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " get_member "; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					txt += "="; | 
					
						
							|  |  |  | 					txt += "[\""; | 
					
						
							|  |  |  | 					txt += func.get_global_name(code[ip + 1]); | 
					
						
							|  |  |  | 					txt += "\"]"; | 
					
						
							|  |  |  | 					incr += 3; | 
					
						
							| 
									
										
										
										
											2017-01-04 17:37:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_ASSIGN: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " assign "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "="; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					incr += 3; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_ASSIGN_TRUE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " assign "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "= true"; | 
					
						
							|  |  |  | 					incr += 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_ASSIGN_FALSE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " assign "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += "= false"; | 
					
						
							|  |  |  | 					incr += 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CONSTRUCT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					Variant::Type t = Variant::Type(code[ip + 1]); | 
					
						
							|  |  |  | 					int argc = code[ip + 2]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " construct "; | 
					
						
							|  |  |  | 					txt += DADDR(3 + argc); | 
					
						
							|  |  |  | 					txt += " = "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += Variant::get_type_name(t) + "("; | 
					
						
							|  |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(i + 3); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 4 + argc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CONSTRUCT_ARRAY: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int argc = code[ip + 1]; | 
					
						
							|  |  |  | 					txt += " make_array "; | 
					
						
							|  |  |  | 					txt += DADDR(2 + argc); | 
					
						
							|  |  |  | 					txt += " = [ "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							|  |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(2 + i); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += "]"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr += 3 + argc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CONSTRUCT_DICTIONARY: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int argc = code[ip + 1]; | 
					
						
							|  |  |  | 					txt += " make_dict "; | 
					
						
							|  |  |  | 					txt += DADDR(2 + argc * 2); | 
					
						
							|  |  |  | 					txt += " = { "; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							|  |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(2 + i * 2 + 0); | 
					
						
							|  |  |  | 						txt += ":"; | 
					
						
							|  |  |  | 						txt += DADDR(2 + i * 2 + 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += "}"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr += 3 + argc * 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CALL: | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CALL_RETURN: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					bool ret = code[ip] == GDFunction::OPCODE_CALL_RETURN; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					if (ret) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += " call-ret "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += " call "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int argc = code[ip + 1]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					if (ret) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt += DADDR(4 + argc) + "="; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += DADDR(2) + "."; | 
					
						
							|  |  |  | 					txt += String(func.get_global_name(code[ip + 3])); | 
					
						
							|  |  |  | 					txt += "("; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							|  |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(4 + i); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 5 + argc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CALL_BUILT_IN: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " call-built-in "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int argc = code[ip + 2]; | 
					
						
							|  |  |  | 					txt += DADDR(3 + argc) + "="; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += GDFunctions::get_func_name(GDFunctions::Function(code[ip + 1])); | 
					
						
							|  |  |  | 					txt += "("; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							|  |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(3 + i); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 4 + argc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_CALL_SELF_BASE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " call-self-base "; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int argc = code[ip + 2]; | 
					
						
							|  |  |  | 					txt += DADDR(3 + argc) + "="; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += func.get_global_name(code[ip + 1]); | 
					
						
							|  |  |  | 					txt += "("; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int i = 0; i < argc; i++) { | 
					
						
							|  |  |  | 						if (i > 0) | 
					
						
							|  |  |  | 							txt += ", "; | 
					
						
							|  |  |  | 						txt += DADDR(3 + i); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += ")"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 4 + argc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2015-01-06 00:39:35 -03:00
										 |  |  | 				case GDFunction::OPCODE_YIELD: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " yield "; | 
					
						
							|  |  |  | 					incr = 1; | 
					
						
							| 
									
										
										
										
											2015-01-06 00:39:35 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_YIELD_SIGNAL: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " yield_signal "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += ","; | 
					
						
							|  |  |  | 					txt += DADDR(2); | 
					
						
							|  |  |  | 					incr = 3; | 
					
						
							| 
									
										
										
										
											2015-01-06 00:39:35 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_YIELD_RESUME: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " yield resume: "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					incr = 2; | 
					
						
							| 
									
										
										
										
											2015-01-06 00:39:35 -03:00
										 |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				case GDFunction::OPCODE_JUMP: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " jump "; | 
					
						
							|  |  |  | 					txt += itos(code[ip + 1]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_JUMP_IF: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " jump-if "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += " to "; | 
					
						
							|  |  |  | 					txt += itos(code[ip + 2]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 3; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_JUMP_IF_NOT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " jump-if-not "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					txt += " to "; | 
					
						
							|  |  |  | 					txt += itos(code[ip + 2]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 3; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " jump-to-default-argument "; | 
					
						
							|  |  |  | 					incr = 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_RETURN: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " return "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					incr = 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_ITERATE_BEGIN: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " for-init " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]); | 
					
						
							|  |  |  | 					incr += 5; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_ITERATE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " for-loop " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]); | 
					
						
							|  |  |  | 					incr += 5; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_LINE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int line = code[ip + 1] - 1; | 
					
						
							|  |  |  | 					if (line >= 0 && line < p_code.size()) | 
					
						
							|  |  |  | 						txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						txt = ""; | 
					
						
							|  |  |  | 					incr += 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case GDFunction::OPCODE_END: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " end"; | 
					
						
							|  |  |  | 					incr += 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2015-04-07 21:48:03 -03:00
										 |  |  | 				case GDFunction::OPCODE_ASSERT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					txt += " assert "; | 
					
						
							|  |  |  | 					txt += DADDR(1); | 
					
						
							|  |  |  | 					incr += 2; | 
					
						
							| 
									
										
										
										
											2015-04-07 21:48:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (incr == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				ERR_EXPLAIN("unhandled opcode: " + itos(code[ip])); | 
					
						
							|  |  |  | 				ERR_BREAK(incr == 0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			ip += incr; | 
					
						
							|  |  |  | 			if (txt != "") | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				print_line(txt); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | MainLoop *test(TestType p_type) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cmdlargs.empty()) { | 
					
						
							|  |  |  | 		//try editor!
 | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String test = cmdlargs.back()->get(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	FileAccess *fa = FileAccess::open(test, FileAccess::READ); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!fa) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ERR_EXPLAIN("Could not open file: " + test); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ERR_FAIL_V(NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<uint8_t> buf; | 
					
						
							|  |  |  | 	int flen = fa->get_len(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	buf.resize(fa->get_len() + 1); | 
					
						
							|  |  |  | 	fa->get_buffer(&buf[0], flen); | 
					
						
							|  |  |  | 	buf[flen] = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	String code; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	code.parse_utf8((const char *)&buf[0]); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<String> lines; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int last = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i <= code.length(); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (code[i] == '\n' || code[i] == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			lines.push_back(code.substr(last, i - last)); | 
					
						
							|  |  |  | 			last = i + 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | 	if (p_type == TEST_TOKENIZER) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-25 09:31:47 -03:00
										 |  |  | 		GDTokenizerText tk; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		tk.set_code(code); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int line = -1; | 
					
						
							|  |  |  | 		while (tk.get_token() != GDTokenizer::TK_EOF) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			String text; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (tk.get_token() == GDTokenizer::TK_IDENTIFIER) | 
					
						
							|  |  |  | 				text = "'" + tk.get_token_identifier() + "' (identifier)"; | 
					
						
							|  |  |  | 			else if (tk.get_token() == GDTokenizer::TK_CONSTANT) { | 
					
						
							|  |  |  | 				Variant c = tk.get_token_constant(); | 
					
						
							|  |  |  | 				if (c.get_type() == Variant::STRING) | 
					
						
							|  |  |  | 					text = "\"" + String(c) + "\""; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					text = c; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)"; | 
					
						
							|  |  |  | 			} else if (tk.get_token() == GDTokenizer::TK_ERROR) | 
					
						
							|  |  |  | 				text = "ERROR: " + tk.get_token_error(); | 
					
						
							|  |  |  | 			else if (tk.get_token() == GDTokenizer::TK_NEWLINE) | 
					
						
							|  |  |  | 				text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent()); | 
					
						
							|  |  |  | 			else if (tk.get_token() == GDTokenizer::TK_BUILT_IN_FUNC) | 
					
						
							|  |  |  | 				text = "'" + String(GDFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				text = tk.get_token_name(tk.get_token()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (tk.get_token_line() != line) { | 
					
						
							|  |  |  | 				int from = line + 1; | 
					
						
							| 
									
										
										
										
											2017-01-14 18:03:38 +01:00
										 |  |  | 				line = tk.get_token_line(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				for (int i = from; i <= line; i++) { | 
					
						
							|  |  |  | 					int l = i - 1; | 
					
						
							|  |  |  | 					if (l >= 0 && l < lines.size()) { | 
					
						
							|  |  |  | 						print_line("\n" + itos(i) + ": " + lines[l] + "\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			print_line("\t(" + itos(tk.get_token_column()) + "): " + text); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			tk.advance(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | 	if (p_type == TEST_PARSER) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		GDParser parser; | 
					
						
							|  |  |  | 		Error err = parser.parse(code); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			memdelete(fa); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const GDParser::Node *root = parser.get_parse_tree(); | 
					
						
							|  |  |  | 		ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, NULL); | 
					
						
							|  |  |  | 		const GDParser::ClassNode *cnode = static_cast<const GDParser::ClassNode *>(root); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_parser_show_class(cnode, 0, lines); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | 	if (p_type == TEST_COMPILER) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		GDParser parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Error err = parser.parse(code); | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			memdelete(fa); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		GDScript *script = memnew(GDScript); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		GDCompiler gdc; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		err = gdc.compile(&parser, script); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			print_line("Compile Error:\n" + itos(gdc.get_error_line()) + ":" + itos(gdc.get_error_column()) + ":" + gdc.get_error()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			memdelete(script); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<GDScript> gds = Ref<GDScript>(script); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Ref<GDScript> current = gds; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (current.is_valid()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			print_line("** CLASS **"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			_disassemble_class(current, lines); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current = current->get_base(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | 	} else if (p_type == TEST_BYTECODE) { | 
					
						
							| 
									
										
										
										
											2014-02-25 09:31:47 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Vector<uint8_t> buf = GDTokenizerBuffer::parse_code_string(code); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		String dst = test.get_basename() + ".gdc"; | 
					
						
							|  |  |  | 		FileAccess *fw = FileAccess::open(dst, FileAccess::WRITE); | 
					
						
							|  |  |  | 		fw->store_buffer(buf.ptr(), buf.size()); | 
					
						
							| 
									
										
										
										
											2014-02-25 09:31:47 -03:00
										 |  |  | 		memdelete(fw); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	Parser parser; | 
					
						
							|  |  |  | 	Error err = parser.parse(code); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		print_line("error:"+itos(parser.get_error_line())+":"+itos(parser.get_error_column())+":"+parser.get_error()); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		print_line("Parse O-K!"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memdelete(fa); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace TestGDScript { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | MainLoop *test(TestType p_type) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |