Merge pull request #14996 from neikeq/enums-mono

Mono: Make the bindings generator output enums
This commit is contained in:
Noshyaar 2017-12-27 10:29:00 +07:00 committed by GitHub
commit ab444a8ca9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 808 additions and 298 deletions

View file

@ -98,6 +98,11 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(MARGIN_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT(MARGIN_BOTTOM);
BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_LEFT);
BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_LEFT);
BIND_GLOBAL_ENUM_CONSTANT(VERTICAL);
BIND_GLOBAL_ENUM_CONSTANT(HORIZONTAL);
@ -573,6 +578,38 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::POOL_VECTOR3_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::POOL_COLOR_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX);
//comparation
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_EQUAL", Variant::OP_EQUAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT_EQUAL", Variant::OP_NOT_EQUAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS", Variant::OP_LESS);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS_EQUAL", Variant::OP_LESS_EQUAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER", Variant::OP_GREATER);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER_EQUAL", Variant::OP_GREATER_EQUAL);
//mathematic
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_ADD", Variant::OP_ADD);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SUBTRACT", Variant::OP_SUBTRACT);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MULTIPLY", Variant::OP_MULTIPLY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_DIVIDE", Variant::OP_DIVIDE);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NEGATE", Variant::OP_NEGATE);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_POSITIVE", Variant::OP_POSITIVE);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MODULE", Variant::OP_MODULE);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_STRING_CONCAT", Variant::OP_STRING_CONCAT);
//bitwise
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_LEFT", Variant::OP_SHIFT_LEFT);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_RIGHT", Variant::OP_SHIFT_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_AND", Variant::OP_BIT_AND);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_OR", Variant::OP_BIT_OR);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_XOR", Variant::OP_BIT_XOR);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_NEGATE", Variant::OP_BIT_NEGATE);
//logic
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_AND", Variant::OP_AND);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_OR", Variant::OP_OR);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_XOR", Variant::OP_XOR);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT", Variant::OP_NOT);
//containment
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_IN", Variant::OP_IN);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MAX", Variant::OP_MAX);
}
void unregister_global_constants() {

View file

@ -1376,7 +1376,7 @@ bool CSharpScript::_update_exports() {
hint_string = NATIVE_GDMONOCLASS_NAME(field_type.type_class);
} else {
hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr));
hint_string = CACHED_FIELD(ExportAttribute, hint_string)->get_string_value(attr);
hint_string = CACHED_FIELD(ExportAttribute, hintString)->get_string_value(attr);
}
PropertyInfo prop_info = PropertyInfo(type, name, hint, hint_string, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE);

File diff suppressed because it is too large Load diff

View file

@ -39,6 +39,47 @@
#include "ustring.h"
class BindingsGenerator {
struct ConstantInterface {
String name;
int value;
const DocData::ConstantDoc *const_doc;
ConstantInterface() {}
ConstantInterface(const String &p_name, int p_value) {
name = p_name;
value = p_value;
}
};
struct EnumInterface {
StringName cname;
String prefix;
List<ConstantInterface> constants;
_FORCE_INLINE_ bool operator==(const EnumInterface &p_ienum) const {
return p_ienum.cname == cname;
}
EnumInterface() {}
EnumInterface(const StringName &p_cname) {
cname = p_cname;
}
};
struct PropertyInterface {
StringName cname;
String proxy_name;
int index;
StringName setter;
StringName getter;
const DocData::PropertyDoc *prop_doc;
};
struct ArgumentInterface {
enum DefaultParamMode {
CONSTANT,
@ -46,7 +87,7 @@ class BindingsGenerator {
NULLABLE_REF
};
String type;
StringName type;
String name;
String default_argument;
DefaultParamMode def_param_mode;
@ -58,6 +99,7 @@ class BindingsGenerator {
struct MethodInterface {
String name;
StringName cname;
/**
* Name of the C# method
@ -67,7 +109,7 @@ class BindingsGenerator {
/**
* [TypeInterface::name] of the return type
*/
String return_type;
StringName return_type;
/**
* Determines if the method has a variable number of arguments (VarArg)
@ -103,7 +145,7 @@ class BindingsGenerator {
}
MethodInterface() {
return_type = "void";
return_type = NameCache::get_singleton().type_void;
is_vararg = false;
is_virtual = false;
requires_object_call = false;
@ -118,11 +160,12 @@ class BindingsGenerator {
* Also used to format [c_out].
*/
String name;
StringName cname;
/**
* Identifier name of the base class.
*/
String base_name;
StringName base_name;
/**
* Name of the C# class
@ -256,23 +299,32 @@ class BindingsGenerator {
const DocData::ClassDoc *class_doc;
List<ConstantInterface> constants;
List<EnumInterface> enums;
List<PropertyInterface> properties;
List<MethodInterface> methods;
const MethodInterface *find_method_by_name(const String &p_name) const {
const MethodInterface *find_method_by_name(const StringName &p_cname) const {
for (const List<MethodInterface>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().name == p_name)
if (E->get().cname == p_cname)
return &E->get();
}
return NULL;
}
static TypeInterface create_value_type(const String &p_name) {
TypeInterface itype;
const PropertyInterface *find_property_by_proxy_name(const String &p_proxy_name) const {
for (const List<PropertyInterface>::Element *E = properties.front(); E; E = E->next()) {
if (E->get().proxy_name == p_proxy_name)
return &E->get();
}
itype.name = p_name;
itype.proxy_name = p_name;
return NULL;
}
private:
static void _init_value_type(TypeInterface &itype) {
itype.proxy_name = itype.name;
itype.c_type = itype.name;
itype.c_type_in = "void*";
@ -281,15 +333,31 @@ class BindingsGenerator {
itype.im_type_in = "ref " + itype.proxy_name;
itype.im_type_out = itype.proxy_name;
itype.class_doc = &EditorHelp::get_doc_data()->class_list[itype.proxy_name];
}
public:
static TypeInterface create_value_type(const String &p_name) {
TypeInterface itype;
itype.name = p_name;
itype.cname = StringName(p_name);
_init_value_type(itype);
return itype;
}
static TypeInterface create_object_type(const String &p_name, ClassDB::APIType p_api_type) {
static TypeInterface create_value_type(const StringName &p_name) {
TypeInterface itype;
itype.name = p_name.operator String();
itype.cname = p_name;
_init_value_type(itype);
return itype;
}
static TypeInterface create_object_type(const StringName &p_cname, ClassDB::APIType p_api_type) {
TypeInterface itype;
itype.name = p_name;
itype.proxy_name = p_name.begins_with("_") ? p_name.substr(1, p_name.length()) : p_name;
itype.name = p_cname;
itype.cname = p_cname;
itype.proxy_name = itype.name.begins_with("_") ? itype.name.substr(1, itype.name.length()) : itype.name;
itype.api_type = p_api_type;
itype.is_object_type = true;
itype.class_doc = &EditorHelp::get_doc_data()->class_list[itype.proxy_name];
@ -297,9 +365,10 @@ class BindingsGenerator {
return itype;
}
static void create_placeholder_type(TypeInterface &r_itype, const String &p_name) {
r_itype.name = p_name;
r_itype.proxy_name = p_name;
static void create_placeholder_type(TypeInterface &r_itype, const StringName &p_cname) {
r_itype.name = p_cname;
r_itype.cname = p_cname;
r_itype.proxy_name = r_itype.name;
r_itype.c_type = r_itype.name;
r_itype.c_type_in = "MonoObject*";
@ -359,11 +428,15 @@ class BindingsGenerator {
static bool verbose_output;
Map<String, TypeInterface> placeholder_types;
Map<String, TypeInterface> builtin_types;
Map<String, TypeInterface> obj_types;
Map<StringName, TypeInterface> placeholder_types;
Map<StringName, TypeInterface> builtin_types;
Map<StringName, TypeInterface> enum_types;
Map<StringName, TypeInterface> obj_types;
Map<String, String> extra_members;
List<EnumInterface> global_enums;
List<ConstantInterface> global_constants;
Map<StringName, String> extra_members;
List<InternalCall> method_icalls;
Map<const MethodInterface *, const InternalCall *> method_icalls_map;
@ -373,8 +446,41 @@ class BindingsGenerator {
List<InternalCall> core_custom_icalls;
List<InternalCall> editor_custom_icalls;
const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) {
struct NameCache {
StringName type_void;
StringName type_int;
StringName type_Array;
StringName type_Dictionary;
StringName type_Variant;
StringName type_VarArg;
StringName type_Object;
StringName type_Reference;
StringName enum_Error;
NameCache() {
type_void = StaticCString::create("void");
type_int = StaticCString::create("int");
type_Array = StaticCString::create("Array");
type_Dictionary = StaticCString::create("Dictionary");
type_Variant = StaticCString::create("Variant");
type_VarArg = StaticCString::create("VarArg");
type_Object = StaticCString::create("Object");
type_Reference = StaticCString::create("Reference");
enum_Error = StaticCString::create("Error");
}
static NameCache &get_singleton() {
static NameCache singleton;
return singleton;
}
NameCache(const NameCache &);
NameCache &operator=(const NameCache &);
};
const NameCache &name_cache;
const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) {
const List<InternalCall>::Element *it = p_list.front();
while (it) {
if (it->get().name == p_name) return it;
@ -392,11 +498,13 @@ class BindingsGenerator {
return p_type.name;
}
String _determine_enum_prefix(const EnumInterface &p_ienum);
void _generate_header_icalls();
void _generate_method_icalls(const TypeInterface &p_itype);
const TypeInterface *_get_type_by_name_or_null(const String &p_name);
const TypeInterface *_get_type_by_name_or_placeholder(const String &p_name);
const TypeInterface *_get_type_by_name_or_null(const StringName &p_cname);
const TypeInterface *_get_type_by_name_or_placeholder(const StringName &p_cname);
void _default_argument_from_variant(const Variant &p_var, ArgumentInterface &r_iarg);
void _populate_builtin_type(TypeInterface &r_type, Variant::Type vtype);
@ -404,11 +512,15 @@ class BindingsGenerator {
void _populate_object_type_interfaces();
void _populate_builtin_type_interfaces();
void _populate_global_constants();
Error _generate_cs_type(const TypeInterface &itype, const String &p_output_file);
Error _generate_cs_property(const TypeInterface &p_itype, const DocData::PropertyDoc &p_prop_doc, List<String> &p_output);
Error _generate_cs_property(const TypeInterface &p_itype, const PropertyInterface &p_prop_doc, List<String> &p_output);
Error _generate_cs_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, int &p_method_bind_count, List<String> &p_output);
void _generate_global_constants(List<String> &p_output);
Error _generate_glue_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, List<String> &p_output);
Error _save_file(const String &path, const List<String> &content);

View file

@ -313,7 +313,7 @@ GodotSharpBuilds *GodotSharpBuilds::singleton = NULL;
void GodotSharpBuilds::build_exit_callback(const MonoBuildInfo &p_build_info, int p_exit_code) {
BuildProcess *match = builds.getptr(p_build_info);
ERR_FAIL_COND(!match);
ERR_FAIL_NULL(match);
BuildProcess &bp = *match;
bp.on_exit(p_exit_code);

View file

@ -1,47 +0,0 @@
namespace Godot
{
public enum Error : int
{
OK = 0,
FAILED = 1,
ERR_UNAVAILABLE = 2,
ERR_UNCONFIGURED = 3,
ERR_UNAUTHORIZED = 4,
ERR_PARAMETER_RANGE_ERROR = 5,
ERR_OUT_OF_MEMORY = 6,
ERR_FILE_NOT_FOUND = 7,
ERR_FILE_BAD_DRIVE = 8,
ERR_FILE_BAD_PATH = 9,
ERR_FILE_NO_PERMISSION = 10,
ERR_FILE_ALREADY_IN_USE = 11,
ERR_FILE_CANT_OPEN = 12,
ERR_FILE_CANT_WRITE = 13,
ERR_FILE_CANT_READ = 14,
ERR_FILE_UNRECOGNIZED = 15,
ERR_FILE_CORRUPT = 16,
ERR_FILE_MISSING_DEPENDENCIES = 17,
ERR_FILE_EOF = 18,
ERR_CANT_OPEN = 19,
ERR_CANT_CREATE = 20,
ERR_PARSE_ERROR = 43,
ERROR_QUERY_FAILED = 21,
ERR_ALREADY_IN_USE = 22,
ERR_LOCKED = 23,
ERR_TIMEOUT = 24,
ERR_CANT_AQUIRE_RESOURCE = 28,
ERR_INVALID_DATA = 30,
ERR_INVALID_PARAMETER = 31,
ERR_ALREADY_EXISTS = 32,
ERR_DOES_NOT_EXIST = 33,
ERR_DATABASE_CANT_READ = 34,
ERR_DATABASE_CANT_WRITE = 35,
ERR_COMPILATION_FAILED = 36,
ERR_METHOD_NOT_FOUND = 37,
ERR_LINK_FAILED = 38,
ERR_SCRIPT_FAILED = 39,
ERR_CYCLIC_LINK = 40,
ERR_BUSY = 44,
ERR_HELP = 46,
ERR_BUG = 47
}
}

View file

@ -5,13 +5,13 @@ namespace Godot
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ExportAttribute : Attribute
{
private int hint;
private string hint_string;
private PropertyHint hint;
private string hintString;
public ExportAttribute(int hint = GD.PROPERTY_HINT_NONE, string hint_string = "")
public ExportAttribute(PropertyHint hint = PropertyHint.None, string hintString = "")
{
this.hint = hint;
this.hint_string = hint_string;
this.hintString = hintString;
}
}
}

View file

@ -2,10 +2,8 @@ using System;
namespace Godot
{
public static class GD
public static partial class GD
{
/*{GodotGlobalConstants}*/
public static object Bytes2Var(byte[] bytes)
{
return NativeCalls.godot_icall_Godot_bytes2var(bytes);

View file

@ -109,14 +109,14 @@ namespace Godot
return g;
}
public Rect2 GrowMargin(int margin, float by)
public Rect2 GrowMargin(Margin margin, float by)
{
Rect2 g = this;
g.GrowIndividual((GD.MARGIN_LEFT == margin) ? by : 0,
(GD.MARGIN_TOP == margin) ? by : 0,
(GD.MARGIN_RIGHT == margin) ? by : 0,
(GD.MARGIN_BOTTOM == margin) ? by : 0);
g.GrowIndividual((Margin.Left == margin) ? by : 0,
(Margin.Top == margin) ? by : 0,
(Margin.Right == margin) ? by : 0,
(Margin.Bottom == margin) ? by : 0);
return g;
}
@ -230,4 +230,4 @@ namespace Godot
});
}
}
}
}

View file

@ -95,7 +95,7 @@ void MonoCache::clear_members() {
class_ExportAttribute = NULL;
field_ExportAttribute_hint = NULL;
field_ExportAttribute_hint_string = NULL;
field_ExportAttribute_hintString = NULL;
class_ToolAttribute = NULL;
class_RemoteAttribute = NULL;
class_SyncAttribute = NULL;
@ -163,7 +163,7 @@ void update_godot_api_cache() {
// Attributes
CACHE_CLASS_AND_CHECK(ExportAttribute, GODOT_API_CLASS(ExportAttribute));
CACHE_FIELD_AND_CHECK(ExportAttribute, hint, CACHED_CLASS(ExportAttribute)->get_field("hint"));
CACHE_FIELD_AND_CHECK(ExportAttribute, hint_string, CACHED_CLASS(ExportAttribute)->get_field("hint_string"));
CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString"));
CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute));
CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute));
CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute));

View file

@ -97,7 +97,7 @@ struct MonoCache {
GDMonoClass *class_ExportAttribute;
GDMonoField *field_ExportAttribute_hint;
GDMonoField *field_ExportAttribute_hint_string;
GDMonoField *field_ExportAttribute_hintString;
GDMonoClass *class_ToolAttribute;
GDMonoClass *class_RemoteAttribute;
GDMonoClass *class_SyncAttribute;

View file

@ -325,7 +325,7 @@ public:
NOTIFICATION_TRANSFORM_CHANGED = 29
};
enum CallGroupFlags {
enum GroupCallFlags {
GROUP_CALL_DEFAULT = 0,
GROUP_CALL_REVERSE = 1,
GROUP_CALL_REALTIME = 2,
@ -466,6 +466,6 @@ public:
VARIANT_ENUM_CAST(SceneTree::StretchMode);
VARIANT_ENUM_CAST(SceneTree::StretchAspect);
VARIANT_ENUM_CAST(SceneTree::CallGroupFlags);
VARIANT_ENUM_CAST(SceneTree::GroupCallFlags);
#endif

View file

@ -654,6 +654,10 @@ void Physics2DServer::_bind_methods() {
BIND_ENUM_CONSTANT(JOINT_GROOVE);
BIND_ENUM_CONSTANT(JOINT_DAMPED_SPRING);
BIND_ENUM_CONSTANT(JOINT_PARAM_BIAS);
BIND_ENUM_CONSTANT(JOINT_PARAM_MAX_BIAS);
BIND_ENUM_CONSTANT(JOINT_PARAM_MAX_FORCE);
BIND_ENUM_CONSTANT(DAMPED_STRING_REST_LENGTH);
BIND_ENUM_CONSTANT(DAMPED_STRING_STIFFNESS);
BIND_ENUM_CONSTANT(DAMPED_STRING_DAMPING);