/**************************************************************************/ /* gdscript_compiler.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* 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. */ /**************************************************************************/ #ifndef GDSCRIPT_COMPILER_H #define GDSCRIPT_COMPILER_H #include "gdscript.h" #include "gdscript_codegen.h" #include "gdscript_function.h" #include "gdscript_parser.h" #include "core/templates/hash_set.h" class GDScriptCompiler { const GDScriptParser *parser = nullptr; HashSet parsed_classes; HashSet parsing_classes; GDScript *main_script = nullptr; struct FunctionLambdaInfo { GDScriptFunction *function = nullptr; GDScriptFunction *parent = nullptr; GDScript *script = nullptr; StringName name; int line = 0; int index = 0; int depth = 0; //uint64_t code_hash; //int code_size; int capture_count = 0; bool use_self = false; int arg_count = 0; int default_arg_count = 0; //Vector argument_types; //GDScriptDataType return_type; Vector sublambdas; }; struct ScriptLambdaInfo { Vector implicit_initializer_info; Vector implicit_ready_info; Vector static_initializer_info; HashMap> member_function_infos; Vector other_function_infos; HashMap subclass_info; }; struct CodeGen { GDScript *script = nullptr; const GDScriptParser::ClassNode *class_node = nullptr; const GDScriptParser::FunctionNode *function_node = nullptr; StringName function_name; GDScriptCodeGenerator *generator = nullptr; HashMap parameters; HashMap locals; List> locals_stack; bool is_static = false; GDScriptCodeGenerator::Address add_local(const StringName &p_name, const GDScriptDataType &p_type) { uint32_t addr = generator->add_local(p_name, p_type); locals[p_name] = GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::LOCAL_VARIABLE, addr, p_type); return locals[p_name]; } GDScriptCodeGenerator::Address add_local_constant(const StringName &p_name, const Variant &p_value) { uint32_t addr = generator->add_local_constant(p_name, p_value); locals[p_name] = GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::CONSTANT, addr); return locals[p_name]; } GDScriptCodeGenerator::Address add_temporary(const GDScriptDataType &p_type = GDScriptDataType()) { uint32_t addr = generator->add_temporary(p_type); return GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::TEMPORARY, addr, p_type); } GDScriptCodeGenerator::Address add_constant(const Variant &p_constant) { GDScriptDataType type; type.has_type = true; type.kind = GDScriptDataType::BUILTIN; type.builtin_type = p_constant.get_type(); if (type.builtin_type == Variant::OBJECT) { Object *obj = p_constant; if (obj) { type.kind = GDScriptDataType::NATIVE; type.native_type = obj->get_class_name(); Ref