Merge branch 'master' into template_get_node

This commit is contained in:
Duncan Sparks
2020-08-16 14:50:32 -07:00
committed by GitHub
7 changed files with 235 additions and 155 deletions

View File

@@ -52,11 +52,11 @@ def is_reference_type(t):
return True
return False
def make_gdnative_type(t):
def make_gdnative_type(t, ref_allowed):
if is_enum(t):
return remove_enum_prefix(t) + " "
elif is_class_type(t):
if is_reference_type(t):
if is_reference_type(t) and ref_allowed:
return "Ref<" + strip_name(t) + "> "
else:
return strip_name(t) + " *"
@@ -89,8 +89,10 @@ def generate_class_header(used_classes, c, use_template_get_node):
# so don't include it here because it's not needed
if class_name != "Object" and class_name != "Reference":
source.append("#include <core/Ref.hpp>")
ref_allowed = True
else:
source.append("#include <core/TagDB.hpp>")
ref_allowed = False
included = []
@@ -215,7 +217,7 @@ def generate_class_header(used_classes, c, use_template_get_node):
# TODO decide what to do about virtual methods
# method_signature += "virtual " if method["is_virtual"] else ""
method_signature += make_gdnative_type(method["return_type"])
method_signature += make_gdnative_type(method["return_type"], ref_allowed)
method_name = escape_cpp(method["name"])
method_signature += method_name + "("
@@ -224,7 +226,7 @@ def generate_class_header(used_classes, c, use_template_get_node):
method_arguments = ""
for i, argument in enumerate(method["arguments"]):
method_signature += "const " + make_gdnative_type(argument["type"])
method_signature += "const " + make_gdnative_type(argument["type"], ref_allowed)
argument_name = escape_cpp(argument["name"])
method_signature += argument_name
method_arguments += argument_name
@@ -325,6 +327,9 @@ def generate_class_header(used_classes, c, use_template_get_node):
def generate_class_implementation(icalls, used_classes, c, use_template_get_node):
class_name = strip_name(c["name"])
ref_allowed = class_name != "Object" and class_name != "Reference"
source = []
source.append("#include \"" + class_name + ".hpp\"")
source.append("")
@@ -398,12 +403,11 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
correct_method_name(class_name, method)
method_signature = ""
method_signature += make_gdnative_type(method["return_type"])
method_signature += make_gdnative_type(method["return_type"], ref_allowed)
method_signature += strip_name(c["name"]) + "::" + escape_cpp(method["name"]) + "("
for i, argument in enumerate(method["arguments"]):
method_signature += "const " + make_gdnative_type(argument["type"])
method_signature += "const " + make_gdnative_type(argument["type"], ref_allowed)
method_signature += escape_cpp(argument["name"])
if i != len(method["arguments"]) - 1:
@@ -427,12 +431,13 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
continue
return_statement = ""
return_type_is_ref = is_reference_type(method["return_type"]) and ref_allowed
if method["return_type"] != "void":
if is_class_type(method["return_type"]):
if is_enum(method["return_type"]):
return_statement += "return (" + remove_enum_prefix(method["return_type"]) + ") "
elif is_reference_type(method["return_type"]):
elif return_type_is_ref:
return_statement += "return Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(";
else:
return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
@@ -507,7 +512,7 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
if method["return_type"] != "void":
cast = ""
if is_class_type(method["return_type"]):
if is_reference_type(method["return_type"]):
if return_type_is_ref:
cast += "Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(__result);"
else:
cast += "(" + strip_name(method["return_type"]) + " *) " + strip_name(method["return_type"] + "::___get_from_variant(") + "__result);"
@@ -516,7 +521,6 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
source.append("\treturn " + cast)
else:
args = []
@@ -534,11 +538,15 @@ def generate_class_implementation(icalls, used_classes, c, use_template_get_node
return_statement += icall_name + "(___mb.mb_" + method["name"] + ", (const Object *) " + core_object_name
for arg in method["arguments"]:
return_statement += ", " + escape_cpp(arg["name"]) + (".ptr()" if is_reference_type(arg["type"]) else "")
arg_is_ref = is_reference_type(arg["type"]) and ref_allowed
return_statement += ", " + escape_cpp(arg["name"]) + (".ptr()" if arg_is_ref else "")
return_statement += ")"
source.append("\t" + return_statement + (")" if is_reference_type(method["return_type"]) else "") + ";")
if return_type_is_ref:
return_statement += ")"
source.append("\t" + return_statement + ";")
source.append("}")
source.append("")
@@ -740,7 +748,6 @@ def get_icall_name(sig):
def get_used_classes(c, use_template_get_node):
classes = []
for method in c["methods"]:
@@ -758,9 +765,6 @@ def get_used_classes(c, use_template_get_node):
def strip_name(name):
if len(name) == 0:
return name