-
-
Notifications
You must be signed in to change notification settings - Fork 674
Implement typed dictionaries #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -672,6 +672,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl | |
for include in fully_used_classes: | ||
if include == "TypedArray": | ||
includes.append("godot_cpp/variant/typed_array.hpp") | ||
elif include == "TypedDictionary": | ||
includes.append("godot_cpp/variant/typed_dictionary.hpp") | ||
else: | ||
includes.append(f"godot_cpp/{get_include_path(include)}") | ||
|
||
|
@@ -1022,6 +1024,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl | |
if class_name == "Dictionary": | ||
result.append("\tconst Variant &operator[](const Variant &p_key) const;") | ||
result.append("\tVariant &operator[](const Variant &p_key);") | ||
result.append( | ||
"\tvoid set_typed(uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script);" | ||
) | ||
|
||
result.append("};") | ||
|
||
|
@@ -1438,6 +1443,32 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node): | |
fully_used_classes.add(array_type_name) | ||
else: | ||
used_classes.add(array_type_name) | ||
elif type_name.startswith("typeddictionary::"): | ||
fully_used_classes.add("TypedDictionary") | ||
dict_type_name = type_name.replace("typeddictionary::", "") | ||
if dict_type_name.startswith("const "): | ||
dict_type_name = dict_type_name[6:] | ||
dict_type_names = dict_type_name.split(";") | ||
dict_type_name = dict_type_names[0] | ||
if dict_type_name.endswith("*"): | ||
dict_type_name = dict_type_name[:-1] | ||
if is_included(dict_type_name, class_name): | ||
if is_enum(dict_type_name): | ||
fully_used_classes.add(get_enum_class(dict_type_name)) | ||
elif "default_value" in argument: | ||
fully_used_classes.add(dict_type_name) | ||
else: | ||
used_classes.add(dict_type_name) | ||
dict_type_name = dict_type_names[2] | ||
if dict_type_name.endswith("*"): | ||
dict_type_name = dict_type_name[:-1] | ||
if is_included(dict_type_name, class_name): | ||
if is_enum(dict_type_name): | ||
fully_used_classes.add(get_enum_class(dict_type_name)) | ||
elif "default_value" in argument: | ||
fully_used_classes.add(dict_type_name) | ||
else: | ||
used_classes.add(dict_type_name) | ||
elif is_enum(type_name): | ||
fully_used_classes.add(get_enum_class(type_name)) | ||
elif "default_value" in argument: | ||
|
@@ -1467,6 +1498,32 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node): | |
fully_used_classes.add(array_type_name) | ||
else: | ||
used_classes.add(array_type_name) | ||
elif type_name.startswith("typeddictionary::"): | ||
fully_used_classes.add("TypedDictionary") | ||
dict_type_name = type_name.replace("typeddictionary::", "") | ||
if dict_type_name.startswith("const "): | ||
dict_type_name = dict_type_name[6:] | ||
dict_type_names = dict_type_name.split(";") | ||
dict_type_name = dict_type_names[0] | ||
if dict_type_name.endswith("*"): | ||
dict_type_name = dict_type_name[:-1] | ||
if is_included(dict_type_name, class_name): | ||
if is_enum(dict_type_name): | ||
fully_used_classes.add(get_enum_class(dict_type_name)) | ||
elif is_variant(dict_type_name): | ||
fully_used_classes.add(dict_type_name) | ||
else: | ||
used_classes.add(dict_type_name) | ||
dict_type_name = dict_type_names[2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why index 2? That would be the third entry. I think dictionary only have 2 types? |
||
if dict_type_name.endswith("*"): | ||
dict_type_name = dict_type_name[:-1] | ||
if is_included(dict_type_name, class_name): | ||
if is_enum(dict_type_name): | ||
fully_used_classes.add(get_enum_class(dict_type_name)) | ||
elif is_variant(dict_type_name): | ||
fully_used_classes.add(dict_type_name) | ||
else: | ||
used_classes.add(dict_type_name) | ||
elif is_enum(type_name): | ||
fully_used_classes.add(get_enum_class(type_name)) | ||
elif is_variant(type_name): | ||
|
@@ -1600,6 +1657,8 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us | |
for included in fully_used_classes: | ||
if included == "TypedArray": | ||
includes.append("godot_cpp/variant/typed_array.hpp") | ||
elif included == "TypedDictionary": | ||
includes.append("godot_cpp/variant/typed_dictionary.hpp") | ||
else: | ||
includes.append(f"godot_cpp/{get_include_path(included)}") | ||
|
||
|
@@ -2688,6 +2747,7 @@ def is_variant(type_name): | |
or type_name in builtin_classes | ||
or type_name == "Nil" | ||
or type_name.startswith("typedarray::") | ||
or type_name.startswith("typeddictionary::") | ||
) | ||
|
||
|
||
|
@@ -2727,6 +2787,8 @@ def is_included(type_name, current_type): | |
""" | ||
if type_name.startswith("typedarray::"): | ||
return True | ||
if type_name.startswith("typeddictionary::"): | ||
return True | ||
to_include = get_enum_class(type_name) if is_enum(type_name) else type_name | ||
if to_include == current_type or is_pod_type(to_include): | ||
return False | ||
|
@@ -2765,6 +2827,12 @@ def correct_typed_array(type_name): | |
return type_name | ||
|
||
|
||
def correct_typed_dictionary(type_name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's unused? |
||
if type_name.startswith("typeddictionary::"): | ||
return type_name.replace("typeddictionary::", "TypedDictionary<").replace(";", ", ") + ">" | ||
return type_name | ||
|
||
|
||
def correct_type(type_name, meta=None, use_alias=True): | ||
type_conversion = {"float": "double", "int": "int64_t", "Nil": "Variant"} | ||
if meta is not None: | ||
|
@@ -2778,6 +2846,8 @@ def correct_type(type_name, meta=None, use_alias=True): | |
return type_conversion[type_name] | ||
if type_name.startswith("typedarray::"): | ||
return type_name.replace("typedarray::", "TypedArray<") + ">" | ||
if type_name.startswith("typeddictionary::"): | ||
return type_name.replace("typeddictionary::", "TypedDictionary<").replace(";", ", ") + ">" | ||
if is_enum(type_name): | ||
if is_bitfield(type_name): | ||
base_class = get_enum_class(type_name) | ||
|
@@ -2924,6 +2994,8 @@ def get_default_value_for_type(type_name): | |
return "false" | ||
if type_name.startswith("typedarray::"): | ||
return f"{correct_type(type_name)}()" | ||
if type_name.startswith("typeddictionary::"): | ||
return f"{correct_type(type_name)}()" | ||
if is_enum(type_name): | ||
return f"{correct_type(type_name)}(0)" | ||
if is_variant(type_name): | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why index 2? That would be the third entry. I think dictionary only have 2 types?