2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* bindings_generator.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. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
#ifndef BINDINGS_GENERATOR_H
|
|
|
|
#define BINDINGS_GENERATOR_H
|
|
|
|
|
2023-06-13 16:56:21 +02:00
|
|
|
#include "core/typedefs.h" // DEBUG_METHODS_ENABLED
|
|
|
|
|
|
|
|
#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED)
|
|
|
|
|
2020-11-29 04:42:06 +01:00
|
|
|
#include "core/doc_data.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/class_db.h"
|
|
|
|
#include "core/string/string_builder.h"
|
2023-06-13 16:56:21 +02:00
|
|
|
#include "core/string/ustring.h"
|
2020-11-29 04:42:06 +01:00
|
|
|
#include "editor/doc_tools.h"
|
2017-10-02 23:24:00 +02:00
|
|
|
#include "editor/editor_help.h"
|
|
|
|
|
|
|
|
class BindingsGenerator {
|
2017-12-24 03:17:48 +01:00
|
|
|
struct ConstantInterface {
|
|
|
|
String name;
|
2018-10-18 19:41:10 +02:00
|
|
|
String proxy_name;
|
2022-05-09 11:47:10 +02:00
|
|
|
int64_t value = 0;
|
2017-12-24 03:17:48 +01:00
|
|
|
const DocData::ConstantDoc *const_doc;
|
|
|
|
|
|
|
|
ConstantInterface() {}
|
|
|
|
|
2022-05-09 11:47:10 +02:00
|
|
|
ConstantInterface(const String &p_name, const String &p_proxy_name, int64_t p_value) {
|
2017-12-24 03:17:48 +01:00
|
|
|
name = p_name;
|
2018-10-18 19:41:10 +02:00
|
|
|
proxy_name = p_proxy_name;
|
2017-12-24 03:17:48 +01:00
|
|
|
value = p_value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EnumInterface {
|
|
|
|
StringName cname;
|
|
|
|
List<ConstantInterface> constants;
|
2022-06-24 20:25:30 +02:00
|
|
|
bool is_flags = false;
|
2017-12-24 03:17:48 +01:00
|
|
|
|
|
|
|
_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;
|
2020-11-24 10:12:55 +01:00
|
|
|
int index = 0;
|
2017-12-24 03:17:48 +01:00
|
|
|
|
|
|
|
StringName setter;
|
|
|
|
StringName getter;
|
|
|
|
|
|
|
|
const DocData::PropertyDoc *prop_doc;
|
|
|
|
};
|
|
|
|
|
2018-04-28 22:25:25 +02:00
|
|
|
struct TypeReference {
|
|
|
|
StringName cname;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_enum = false;
|
2018-04-28 22:25:25 +02:00
|
|
|
|
2022-02-09 00:56:10 +01:00
|
|
|
List<TypeReference> generic_type_parameters;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
TypeReference() {}
|
2019-03-18 21:59:35 +01:00
|
|
|
|
|
|
|
TypeReference(const StringName &p_cname) :
|
2020-05-12 17:01:17 +02:00
|
|
|
cname(p_cname) {}
|
2018-04-28 22:25:25 +02:00
|
|
|
};
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
struct ArgumentInterface {
|
|
|
|
enum DefaultParamMode {
|
|
|
|
CONSTANT,
|
|
|
|
NULLABLE_VAL,
|
|
|
|
NULLABLE_REF
|
|
|
|
};
|
|
|
|
|
2018-04-28 22:25:25 +02:00
|
|
|
TypeReference type;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
String name;
|
2020-05-16 04:03:05 +02:00
|
|
|
|
|
|
|
Variant def_param_value;
|
2020-05-12 17:01:17 +02:00
|
|
|
DefaultParamMode def_param_mode = CONSTANT;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2020-03-14 19:20:17 +01:00
|
|
|
/**
|
|
|
|
* Determines the expression for the parameter default value.
|
|
|
|
* Formatting elements:
|
|
|
|
* %0 or %s: [cs_type] of the argument type
|
|
|
|
*/
|
|
|
|
String default_argument;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
ArgumentInterface() {}
|
2017-10-02 23:24:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MethodInterface {
|
|
|
|
String name;
|
2017-12-24 03:17:48 +01:00
|
|
|
StringName cname;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the C# method
|
|
|
|
*/
|
|
|
|
String proxy_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [TypeInterface::name] of the return type
|
|
|
|
*/
|
2018-04-28 22:25:25 +02:00
|
|
|
TypeReference return_type;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the method has a variable number of arguments (VarArg)
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_vararg = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-03-21 01:25:50 +01:00
|
|
|
/**
|
|
|
|
* Determines if the method is static.
|
|
|
|
*/
|
|
|
|
bool is_static = false;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
/**
|
|
|
|
* Virtual methods ("virtual" as defined by the Godot API) are methods that by default do nothing,
|
|
|
|
* but can be overridden by the user to add custom functionality.
|
|
|
|
* e.g.: _ready, _process, etc.
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_virtual = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the call should fallback to Godot's object.Call(string, params) in C#.
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool requires_object_call = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
2019-08-09 03:39:45 +02:00
|
|
|
* Determines if the method visibility is 'internal' (visible only to files in the same assembly).
|
2017-10-02 23:24:00 +02:00
|
|
|
* Currently, we only use this for methods that are not meant to be exposed,
|
|
|
|
* but are required by properties as getters or setters.
|
|
|
|
* Methods that are not meant to be exposed are those that begin with underscore and are not virtual.
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_internal = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
List<ArgumentInterface> arguments;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
const DocData::MethodDoc *method_doc = nullptr;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_deprecated = false;
|
2019-04-25 17:11:01 +02:00
|
|
|
String deprecation_message;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
void add_argument(const ArgumentInterface &argument) {
|
|
|
|
arguments.push_back(argument);
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
MethodInterface() {}
|
2017-10-02 23:24:00 +02:00
|
|
|
};
|
|
|
|
|
2020-03-14 19:20:17 +01:00
|
|
|
struct SignalInterface {
|
|
|
|
String name;
|
|
|
|
StringName cname;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the C# method
|
|
|
|
*/
|
|
|
|
String proxy_name;
|
|
|
|
|
|
|
|
List<ArgumentInterface> arguments;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
const DocData::MethodDoc *method_doc = nullptr;
|
2020-03-14 19:20:17 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_deprecated = false;
|
2020-03-14 19:20:17 +01:00
|
|
|
String deprecation_message;
|
|
|
|
|
|
|
|
void add_argument(const ArgumentInterface &argument) {
|
|
|
|
arguments.push_back(argument);
|
|
|
|
}
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
SignalInterface() {}
|
2020-03-14 19:20:17 +01:00
|
|
|
};
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
struct TypeInterface {
|
|
|
|
/**
|
|
|
|
* Identifier name for this type.
|
|
|
|
* Also used to format [c_out].
|
|
|
|
*/
|
|
|
|
String name;
|
2017-12-24 03:17:48 +01:00
|
|
|
StringName cname;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-12-01 01:45:11 +01:00
|
|
|
int type_parameter_count = 0;
|
2022-02-09 00:56:10 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
/**
|
|
|
|
* Identifier name of the base class.
|
|
|
|
*/
|
2017-12-24 03:17:48 +01:00
|
|
|
StringName base_name;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the C# class
|
|
|
|
*/
|
|
|
|
String proxy_name;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
ClassDB::APIType api_type = ClassDB::API_NONE;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_enum = false;
|
|
|
|
bool is_object_type = false;
|
|
|
|
bool is_singleton = false;
|
2023-07-14 16:05:48 +02:00
|
|
|
bool is_singleton_instance = false;
|
2021-06-04 18:03:15 +02:00
|
|
|
bool is_ref_counted = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2023-07-14 20:22:04 +02:00
|
|
|
/**
|
|
|
|
* Class is a singleton, but can't be declared as a static class as that would
|
|
|
|
* break backwards compatibility. As such, instead of going with a static class,
|
|
|
|
* we use the actual singleton pattern (private constructor with instance property),
|
|
|
|
* which doesn't break compatibility.
|
|
|
|
*/
|
|
|
|
bool is_compat_singleton = false;
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
/**
|
|
|
|
* Determines whether the native return value of this type must be disposed
|
|
|
|
* by the generated internal call (think of `godot_string`, whose destructor
|
|
|
|
* must be called). Some structs that are disposable may still disable this
|
|
|
|
* flag if the ownership is transferred.
|
|
|
|
*/
|
|
|
|
bool c_type_is_disposable_struct = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the native return value of this type must be zero initialized
|
|
|
|
* before its address is passed to ptrcall. This is required for types whose destructor
|
|
|
|
* is called before being assigned the return value by `PtrToArg::encode`, e.g.:
|
2022-07-28 17:41:49 +02:00
|
|
|
* Array, Dictionary, String, StringName, Variant.
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
* It's not necessary to set this to `true` if [c_type_is_disposable_struct] is already `true`.
|
|
|
|
*/
|
|
|
|
bool c_ret_needs_default_initialization = false;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
/**
|
|
|
|
* Used only by Object-derived types.
|
2018-08-27 20:39:51 +02:00
|
|
|
* Determines if this type is not abstract (incomplete).
|
2017-10-02 23:24:00 +02:00
|
|
|
* e.g.: CanvasItem cannot be instantiated.
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool is_instantiable = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used only by Object-derived types.
|
|
|
|
* Determines if the C# class owns the native handle and must free it somehow when disposed.
|
2021-06-04 18:03:15 +02:00
|
|
|
* e.g.: RefCounted types must notify when the C# instance is disposed, for proper refcounting.
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
bool memory_own = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
// !! The comments of the following fields make reference to other fields via square brackets, e.g.: [field_name]
|
|
|
|
// !! When renaming those fields, make sure to rename their references in the comments
|
|
|
|
|
|
|
|
// --- C INTERFACE ---
|
|
|
|
|
|
|
|
/**
|
2021-12-28 23:25:16 +01:00
|
|
|
* One or more statements that transform the parameter before being passed as argument of a ptrcall.
|
2017-10-02 23:24:00 +02:00
|
|
|
* If the statement adds a local that must be passed as the argument instead of the parameter,
|
2021-12-28 23:25:16 +01:00
|
|
|
* the expression with the name of that local must be specified with [c_arg_in].
|
2017-10-02 23:24:00 +02:00
|
|
|
* Formatting elements:
|
|
|
|
* %0: [c_type] of the parameter
|
|
|
|
* %1: name of the parameter
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
* %2-4: reserved
|
|
|
|
* %5: indentation text
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String c_in;
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
/**
|
2021-12-28 23:25:16 +01:00
|
|
|
* One or more statements that transform the parameter before being passed as argument of a vararg call.
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
* If the statement adds a local that must be passed as the argument instead of the parameter,
|
|
|
|
* the name of that local must be specified with [c_arg_in].
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: [c_type] of the parameter
|
|
|
|
* %1: name of the parameter
|
|
|
|
* %2-4: reserved
|
|
|
|
* %5: indentation text
|
|
|
|
*/
|
|
|
|
String c_in_vararg;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
/**
|
2018-10-17 21:37:57 +02:00
|
|
|
* Determines the expression that will be passed as argument to ptrcall.
|
2017-10-02 23:24:00 +02:00
|
|
|
* By default the value equals the name of the parameter,
|
|
|
|
* this varies for types that require special manipulation via [c_in].
|
|
|
|
* Formatting elements:
|
|
|
|
* %0 or %s: name of the parameter
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
String c_arg_in = "%s";
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* One or more statements that determine how a variable of this type is returned from a function.
|
|
|
|
* It must contain the return statement(s).
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: [c_type_out] of the return type
|
|
|
|
* %1: name of the variable to be returned
|
|
|
|
* %2: [name] of the return type
|
2019-11-14 21:48:49 +01:00
|
|
|
* ---------------------------------------
|
|
|
|
* If [ret_as_byref_arg] is true, the format is different. Instead of using a return statement,
|
|
|
|
* the value must be assigned to a parameter. This type of this parameter is a pointer to [c_type_out].
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: [c_type_out] of the return type
|
|
|
|
* %1: name of the variable to be returned
|
|
|
|
* %2: [name] of the return type
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
* %3-4: reserved
|
|
|
|
* %5: indentation text
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String c_out;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The actual expected type, as seen (in most cases) in Variant copy constructors
|
|
|
|
* Used for the type of the return variable and to format [c_in].
|
|
|
|
* The value must be the following depending of the type:
|
|
|
|
* Object-derived types: Object*
|
|
|
|
* Other types: [name]
|
|
|
|
* -- Exceptions --
|
|
|
|
* VarArg (fictitious type to represent variable arguments): Array
|
|
|
|
* float: double (because ptrcall only supports double)
|
|
|
|
* int: int64_t (because ptrcall only supports int64_t and uint64_t)
|
2021-06-04 18:03:15 +02:00
|
|
|
* RefCounted types override this for the type of the return variable: Ref<RefCounted>
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String c_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the type used for parameters in function signatures.
|
|
|
|
*/
|
|
|
|
String c_type_in;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the return type used for function signatures.
|
|
|
|
* Also used to construct a default value to return in case of errors,
|
|
|
|
* and to format [c_out].
|
|
|
|
*/
|
|
|
|
String c_type_out;
|
|
|
|
|
|
|
|
// --- C# INTERFACE ---
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An expression that overrides the way the parameter is passed to the internal call.
|
|
|
|
* If empty, the parameter is passed as is.
|
|
|
|
* Formatting elements:
|
2021-12-28 23:25:16 +01:00
|
|
|
* %0: name of the parameter
|
|
|
|
* %1: [c_type] of the parameter
|
|
|
|
*/
|
|
|
|
String cs_in_expr;
|
|
|
|
bool cs_in_expr_is_unsafe = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* One or more statements that transform the parameter before being passed to the internal call.
|
|
|
|
* If the statement adds a local that must be passed as the argument instead of the parameter,
|
|
|
|
* the expression with the name of that local must be specified with [cs_in_expr].
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: [c_type] of the parameter
|
|
|
|
* %1: name of the parameter
|
|
|
|
* %2-4: reserved
|
|
|
|
* %5: indentation text
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String cs_in;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* One or more statements that determine how a variable of this type is returned from a method.
|
|
|
|
* It must contain the return statement(s).
|
|
|
|
* Formatting elements:
|
2019-11-14 21:48:49 +01:00
|
|
|
* %0: internal method name
|
|
|
|
* %1: internal method call arguments without surrounding parenthesis
|
|
|
|
* %2: [cs_type] of the return type
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
* %3: [c_type_out] of the return type
|
|
|
|
* %4: reserved
|
|
|
|
* %5: indentation text
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String cs_out;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type used for method signatures, both for parameters and the return type.
|
2018-08-27 20:39:51 +02:00
|
|
|
* Same as [proxy_name] except for variable arguments (VarArg) and collections (which include the namespace).
|
2017-10-02 23:24:00 +02:00
|
|
|
*/
|
|
|
|
String cs_type;
|
|
|
|
|
2022-02-27 21:57:46 +01:00
|
|
|
/**
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: input expression of type `in godot_variant`
|
|
|
|
* %1: [cs_type] of this type
|
|
|
|
* %2: [name] of this type
|
|
|
|
*/
|
|
|
|
String cs_variant_to_managed;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formatting elements:
|
|
|
|
* %0: input expression
|
|
|
|
* %1: [cs_type] of this type
|
|
|
|
* %2: [name] of this type
|
|
|
|
*/
|
|
|
|
String cs_managed_to_variant;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
const DocData::ClassDoc *class_doc = nullptr;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
List<ConstantInterface> constants;
|
|
|
|
List<EnumInterface> enums;
|
|
|
|
List<PropertyInterface> properties;
|
2017-10-02 23:24:00 +02:00
|
|
|
List<MethodInterface> methods;
|
2020-03-14 19:20:17 +01:00
|
|
|
List<SignalInterface> signals_;
|
2023-03-24 11:40:54 +01:00
|
|
|
HashSet<String> ignored_members;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2021-09-12 20:21:15 +02:00
|
|
|
bool has_virtual_methods = false;
|
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
const MethodInterface *find_method_by_name(const StringName &p_cname) const {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (const MethodInterface &E : methods) {
|
|
|
|
if (E.cname == p_cname) {
|
|
|
|
return &E;
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 19:01:18 +01:00
|
|
|
const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const {
|
|
|
|
for (const MethodInterface &E : methods) {
|
|
|
|
if (E.proxy_name == p_proxy_name) {
|
|
|
|
return &E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-03-18 21:59:35 +01:00
|
|
|
const PropertyInterface *find_property_by_name(const StringName &p_cname) const {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (const PropertyInterface &E : properties) {
|
|
|
|
if (E.cname == p_cname) {
|
|
|
|
return &E;
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2019-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-03-18 21:59:35 +01:00
|
|
|
}
|
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
const PropertyInterface *find_property_by_proxy_name(const String &p_proxy_name) const {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (const PropertyInterface &E : properties) {
|
|
|
|
if (E.proxy_name == p_proxy_name) {
|
|
|
|
return &E;
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2017-12-24 03:17:48 +01:00
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2017-12-24 03:17:48 +01:00
|
|
|
}
|
|
|
|
|
2022-02-09 19:01:18 +01:00
|
|
|
const SignalInterface *find_signal_by_name(const StringName &p_cname) const {
|
|
|
|
for (const SignalInterface &E : signals_) {
|
|
|
|
if (E.cname == p_cname) {
|
|
|
|
return &E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SignalInterface *find_signal_by_proxy_name(const String &p_proxy_name) const {
|
|
|
|
for (const SignalInterface &E : signals_) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E.proxy_name == p_proxy_name) {
|
|
|
|
return &E;
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2020-03-14 19:20:17 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2020-03-14 19:20:17 +01:00
|
|
|
}
|
|
|
|
|
2023-03-24 11:40:54 +01:00
|
|
|
bool is_intentionally_ignored(const String &p_name) const {
|
|
|
|
return ignored_members.has(p_name);
|
|
|
|
}
|
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
private:
|
2022-12-07 16:11:39 +01:00
|
|
|
static DocData::ClassDoc *_get_type_doc(TypeInterface &itype) {
|
|
|
|
String doc_name = itype.name.begins_with("_") ? itype.name.substr(1) : itype.name;
|
|
|
|
return &EditorHelp::get_doc_data()->class_list[doc_name];
|
|
|
|
}
|
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
static void _init_value_type(TypeInterface &itype) {
|
2022-12-07 16:11:39 +01:00
|
|
|
if (itype.proxy_name.is_empty()) {
|
|
|
|
itype.proxy_name = itype.name;
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
itype.cs_type = itype.proxy_name;
|
2022-12-07 16:11:39 +01:00
|
|
|
itype.c_type = itype.cs_type;
|
|
|
|
itype.c_type_in = itype.cs_type + "*";
|
|
|
|
itype.c_type_out = itype.cs_type;
|
|
|
|
|
|
|
|
itype.class_doc = _get_type_doc(itype);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _init_object_type(TypeInterface &itype, ClassDB::APIType p_api_type) {
|
|
|
|
if (itype.proxy_name.is_empty()) {
|
|
|
|
itype.proxy_name = itype.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itype.proxy_name.begins_with("_")) {
|
|
|
|
itype.proxy_name = itype.proxy_name.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
itype.api_type = p_api_type;
|
|
|
|
itype.is_object_type = true;
|
|
|
|
|
|
|
|
itype.class_doc = _get_type_doc(itype);
|
2017-12-24 03:17:48 +01:00
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
public:
|
2022-12-07 16:11:39 +01:00
|
|
|
static TypeInterface create_value_type(const String &p_name, const String &p_proxy_name) {
|
2017-12-24 03:17:48 +01:00
|
|
|
TypeInterface itype;
|
|
|
|
itype.name = p_name;
|
2022-12-07 16:11:39 +01:00
|
|
|
itype.cname = p_name;
|
|
|
|
itype.proxy_name = p_proxy_name;
|
2017-12-24 03:17:48 +01:00
|
|
|
_init_value_type(itype);
|
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
2022-12-07 16:11:39 +01:00
|
|
|
static TypeInterface create_value_type(const StringName &p_cname, const String &p_proxy_name) {
|
2017-12-24 03:17:48 +01:00
|
|
|
TypeInterface itype;
|
2022-12-07 16:11:39 +01:00
|
|
|
itype.name = p_cname;
|
|
|
|
itype.cname = p_cname;
|
|
|
|
itype.proxy_name = p_proxy_name;
|
|
|
|
_init_value_type(itype);
|
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TypeInterface create_value_type(const String &p_name) {
|
|
|
|
TypeInterface itype;
|
|
|
|
itype.name = p_name;
|
2017-12-24 03:17:48 +01:00
|
|
|
itype.cname = p_name;
|
|
|
|
_init_value_type(itype);
|
2017-10-02 23:24:00 +02:00
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
2022-12-07 16:11:39 +01:00
|
|
|
static TypeInterface create_value_type(const StringName &p_cname) {
|
2017-10-02 23:24:00 +02:00
|
|
|
TypeInterface itype;
|
2022-12-07 16:11:39 +01:00
|
|
|
itype.name = p_cname;
|
|
|
|
itype.cname = p_cname;
|
|
|
|
_init_value_type(itype);
|
|
|
|
return itype;
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-12-07 16:11:39 +01:00
|
|
|
static TypeInterface create_object_type(const StringName &p_cname, const String &p_proxy_name, ClassDB::APIType p_api_type) {
|
|
|
|
TypeInterface itype;
|
2017-12-24 03:17:48 +01:00
|
|
|
itype.name = p_cname;
|
|
|
|
itype.cname = p_cname;
|
2022-12-07 16:11:39 +01:00
|
|
|
itype.proxy_name = p_proxy_name;
|
|
|
|
_init_object_type(itype, p_api_type);
|
|
|
|
return itype;
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-12-07 16:11:39 +01:00
|
|
|
static TypeInterface create_object_type(const StringName &p_cname, ClassDB::APIType p_api_type) {
|
|
|
|
TypeInterface itype;
|
|
|
|
itype.name = p_cname;
|
|
|
|
itype.cname = p_cname;
|
|
|
|
_init_object_type(itype, p_api_type);
|
2017-10-02 23:24:00 +02:00
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
static void postsetup_enum_type(TypeInterface &r_enum_itype);
|
2018-04-28 22:25:25 +02:00
|
|
|
|
2022-12-01 01:45:11 +01:00
|
|
|
TypeInterface() {
|
|
|
|
static String default_cs_variant_to_managed = "VariantUtils.ConvertTo<%1>(%0)";
|
|
|
|
static String default_cs_managed_to_variant = "VariantUtils.CreateFrom<%1>(%0)";
|
|
|
|
cs_variant_to_managed = default_cs_variant_to_managed;
|
|
|
|
cs_managed_to_variant = default_cs_managed_to_variant;
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct InternalCall {
|
|
|
|
String name;
|
|
|
|
String unique_sig; // Unique signature to avoid duplicates in containers
|
2020-11-24 10:12:55 +01:00
|
|
|
bool editor_only = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
bool is_vararg = false;
|
|
|
|
bool is_static = false;
|
|
|
|
TypeReference return_type;
|
|
|
|
List<TypeReference> argument_types;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
_FORCE_INLINE_ int get_arguments_count() const { return argument_types.size(); }
|
|
|
|
|
|
|
|
InternalCall() {}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
InternalCall(ClassDB::APIType api_type, const String &p_name, const String &p_unique_sig = String()) {
|
2017-10-02 23:24:00 +02:00
|
|
|
name = p_name;
|
|
|
|
unique_sig = p_unique_sig;
|
|
|
|
editor_only = api_type == ClassDB::API_EDITOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator==(const InternalCall &p_a) const {
|
|
|
|
return p_a.unique_sig == unique_sig;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool log_print_enabled = true;
|
|
|
|
bool initialized = false;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-05-08 10:09:19 +02:00
|
|
|
HashMap<StringName, TypeInterface> obj_types;
|
2018-01-09 19:06:59 +01:00
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<StringName, TypeInterface> builtin_types;
|
|
|
|
HashMap<StringName, TypeInterface> enum_types;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
List<EnumInterface> global_enums;
|
|
|
|
List<ConstantInterface> global_constants;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
List<InternalCall> method_icalls;
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
/// Stores the unique internal calls from [method_icalls] that are assigned to each method.
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<const MethodInterface *, const InternalCall *> method_icalls_map;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<StringName, List<StringName>> blacklisted_methods;
|
2023-07-14 20:22:04 +02:00
|
|
|
HashSet<StringName> compat_singletons;
|
2019-05-24 00:40:16 +02:00
|
|
|
|
|
|
|
void _initialize_blacklisted_methods();
|
2023-07-14 20:22:04 +02:00
|
|
|
void _initialize_compat_singletons();
|
2019-05-24 00:40:16 +02:00
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
struct NameCache {
|
2020-05-16 04:03:05 +02:00
|
|
|
StringName type_void = StaticCString::create("void");
|
|
|
|
StringName type_Variant = StaticCString::create("Variant");
|
|
|
|
StringName type_VarArg = StaticCString::create("VarArg");
|
|
|
|
StringName type_Object = StaticCString::create("Object");
|
2021-06-04 18:03:15 +02:00
|
|
|
StringName type_RefCounted = StaticCString::create("RefCounted");
|
2020-05-16 04:03:05 +02:00
|
|
|
StringName type_RID = StaticCString::create("RID");
|
2021-08-20 11:18:04 +02:00
|
|
|
StringName type_Callable = StaticCString::create("Callable");
|
|
|
|
StringName type_Signal = StaticCString::create("Signal");
|
2020-05-16 04:03:05 +02:00
|
|
|
StringName type_String = StaticCString::create("String");
|
|
|
|
StringName type_StringName = StaticCString::create("StringName");
|
|
|
|
StringName type_NodePath = StaticCString::create("NodePath");
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
StringName type_Array_generic = StaticCString::create("Array_@generic");
|
|
|
|
StringName type_Dictionary_generic = StaticCString::create("Dictionary_@generic");
|
2020-05-16 04:03:05 +02:00
|
|
|
StringName type_at_GlobalScope = StaticCString::create("@GlobalScope");
|
|
|
|
StringName enum_Error = StaticCString::create("Error");
|
|
|
|
|
|
|
|
StringName type_sbyte = StaticCString::create("sbyte");
|
|
|
|
StringName type_short = StaticCString::create("short");
|
|
|
|
StringName type_int = StaticCString::create("int");
|
|
|
|
StringName type_byte = StaticCString::create("byte");
|
|
|
|
StringName type_ushort = StaticCString::create("ushort");
|
|
|
|
StringName type_uint = StaticCString::create("uint");
|
|
|
|
StringName type_long = StaticCString::create("long");
|
|
|
|
StringName type_ulong = StaticCString::create("ulong");
|
|
|
|
|
|
|
|
StringName type_bool = StaticCString::create("bool");
|
|
|
|
StringName type_float = StaticCString::create("float");
|
|
|
|
StringName type_double = StaticCString::create("double");
|
|
|
|
|
|
|
|
StringName type_Vector2 = StaticCString::create("Vector2");
|
|
|
|
StringName type_Rect2 = StaticCString::create("Rect2");
|
|
|
|
StringName type_Vector3 = StaticCString::create("Vector3");
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
|
|
|
StringName type_Vector3i = StaticCString::create("Vector3i");
|
|
|
|
StringName type_Vector4 = StaticCString::create("Vector4");
|
|
|
|
StringName type_Vector4i = StaticCString::create("Vector4i");
|
2020-05-16 04:03:05 +02:00
|
|
|
|
|
|
|
// Object not included as it must be checked for all derived classes
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
static constexpr int nullable_types_count = 18;
|
2020-05-16 04:03:05 +02:00
|
|
|
StringName nullable_types[nullable_types_count] = {
|
|
|
|
type_String,
|
|
|
|
type_StringName,
|
|
|
|
type_NodePath,
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
type_Array_generic,
|
|
|
|
type_Dictionary_generic,
|
2020-05-16 04:03:05 +02:00
|
|
|
StaticCString::create(_STR(Array)),
|
|
|
|
StaticCString::create(_STR(Dictionary)),
|
|
|
|
StaticCString::create(_STR(Callable)),
|
|
|
|
StaticCString::create(_STR(Signal)),
|
|
|
|
|
|
|
|
StaticCString::create(_STR(PackedByteArray)),
|
|
|
|
StaticCString::create(_STR(PackedInt32Array)),
|
2021-07-30 18:36:33 +02:00
|
|
|
StaticCString::create(_STR(PackedInt64Array)),
|
2020-05-16 04:03:05 +02:00
|
|
|
StaticCString::create(_STR(PackedFloat32Array)),
|
|
|
|
StaticCString::create(_STR(PackedFloat64Array)),
|
|
|
|
StaticCString::create(_STR(PackedStringArray)),
|
|
|
|
StaticCString::create(_STR(PackedVector2Array)),
|
|
|
|
StaticCString::create(_STR(PackedVector3Array)),
|
|
|
|
StaticCString::create(_STR(PackedColorArray)),
|
|
|
|
};
|
|
|
|
|
|
|
|
bool is_nullable_type(const StringName &p_type) const {
|
|
|
|
for (int i = 0; i < nullable_types_count; i++) {
|
|
|
|
if (p_type == nullable_types[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-12-24 03:17:48 +01:00
|
|
|
}
|
|
|
|
|
2020-05-16 04:03:05 +02:00
|
|
|
NameCache() {}
|
|
|
|
|
2019-04-25 15:45:12 +02:00
|
|
|
private:
|
2017-12-24 03:17:48 +01:00
|
|
|
NameCache(const NameCache &);
|
2021-11-30 15:19:26 +01:00
|
|
|
void operator=(const NameCache &);
|
2017-12-24 03:17:48 +01:00
|
|
|
};
|
|
|
|
|
2018-01-01 03:04:49 +01:00
|
|
|
NameCache name_cache;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-03-27 20:01:16 +01:00
|
|
|
const ConstantInterface *find_constant_by_name(const String &p_name, const List<ConstantInterface> &p_constants) const {
|
2021-07-16 05:45:57 +02:00
|
|
|
for (const ConstantInterface &E : p_constants) {
|
|
|
|
if (E.name == p_name) {
|
|
|
|
return &E;
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2019-03-27 20:01:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-03-27 20:01:16 +01:00
|
|
|
}
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
inline String get_arg_unique_sig(const TypeInterface &p_type) {
|
|
|
|
// For parameters, we treat reference and non-reference derived types the same.
|
|
|
|
if (p_type.is_object_type) {
|
2017-10-02 23:24:00 +02:00
|
|
|
return "Obj";
|
2020-05-16 04:03:05 +02:00
|
|
|
} else if (p_type.is_enum) {
|
2018-04-28 22:25:25 +02:00
|
|
|
return "int";
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
} else if (p_type.cname == name_cache.type_Array_generic) {
|
|
|
|
return "Array";
|
|
|
|
} else if (p_type.cname == name_cache.type_Dictionary_generic) {
|
|
|
|
return "Dictionary";
|
2020-05-16 04:03:05 +02:00
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
return p_type.name;
|
|
|
|
}
|
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
inline String get_ret_unique_sig(const TypeInterface *p_type) {
|
|
|
|
// Reference derived return types are treated differently.
|
|
|
|
if (p_type->is_ref_counted) {
|
|
|
|
return "Ref";
|
|
|
|
} else if (p_type->is_object_type) {
|
|
|
|
return "Obj";
|
|
|
|
} else if (p_type->is_enum) {
|
|
|
|
return "int";
|
|
|
|
} else if (p_type->cname == name_cache.type_Array_generic) {
|
|
|
|
return "Array";
|
|
|
|
} else if (p_type->cname == name_cache.type_Dictionary_generic) {
|
|
|
|
return "Dictionary";
|
|
|
|
}
|
|
|
|
|
|
|
|
return p_type->name;
|
|
|
|
}
|
|
|
|
|
2019-03-18 21:59:35 +01:00
|
|
|
String bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype);
|
|
|
|
|
2022-03-03 23:35:10 +01:00
|
|
|
void _append_xml_method(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
|
|
|
|
void _append_xml_member(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
|
|
|
|
void _append_xml_signal(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
|
|
|
|
void _append_xml_enum(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
|
|
|
|
void _append_xml_constant(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
|
|
|
|
void _append_xml_constant_in_global_scope(StringBuilder &p_xml_output, const String &p_target_cname, const String &p_link_target);
|
|
|
|
void _append_xml_undeclared(StringBuilder &p_xml_output, const String &p_link_target);
|
|
|
|
|
2018-10-18 19:41:10 +02:00
|
|
|
int _determine_enum_prefix(const EnumInterface &p_ienum);
|
|
|
|
void _apply_prefix_to_enum_constants(EnumInterface &p_ienum, int p_prefix_length);
|
2017-12-24 03:17:48 +01:00
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
Error _populate_method_icalls_table(const TypeInterface &p_itype);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2018-04-28 22:25:25 +02:00
|
|
|
const TypeInterface *_get_type_or_null(const TypeReference &p_typeref);
|
2023-07-14 16:05:48 +02:00
|
|
|
const TypeInterface *_get_type_or_singleton_or_null(const TypeReference &p_typeref);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-02-09 00:56:10 +01:00
|
|
|
const String _get_generic_type_parameters(const TypeInterface &p_itype, const List<TypeReference> &p_generic_type_parameters);
|
|
|
|
|
2022-09-01 00:40:59 +02:00
|
|
|
StringName _get_type_name_from_meta(Variant::Type p_type, GodotTypeInfo::Metadata p_meta);
|
2019-04-25 20:24:48 +02:00
|
|
|
StringName _get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta);
|
|
|
|
StringName _get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta);
|
|
|
|
|
2019-09-24 15:09:54 +02:00
|
|
|
bool _arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg);
|
2020-05-16 04:03:05 +02:00
|
|
|
bool _arg_default_value_is_assignable_to_type(const Variant &p_val, const TypeInterface &p_arg_type);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-09-24 15:09:54 +02:00
|
|
|
bool _populate_object_type_interfaces();
|
2017-10-02 23:24:00 +02:00
|
|
|
void _populate_builtin_type_interfaces();
|
|
|
|
|
2017-12-24 03:17:48 +01:00
|
|
|
void _populate_global_constants();
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
Error _generate_cs_type(const TypeInterface &itype, const String &p_output_file);
|
|
|
|
|
2019-04-19 01:10:08 +02:00
|
|
|
Error _generate_cs_property(const TypeInterface &p_itype, const PropertyInterface &p_iprop, StringBuilder &p_output);
|
|
|
|
Error _generate_cs_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, int &p_method_bind_count, StringBuilder &p_output);
|
2020-03-14 19:20:17 +01:00
|
|
|
Error _generate_cs_signal(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::SignalInterface &p_isignal, StringBuilder &p_output);
|
2017-10-29 02:37:13 +01:00
|
|
|
|
C#: Move marshaling logic and generated glue to C#
We will be progressively moving most code to C#.
The plan is to only use Mono's embedding APIs to set things at launch.
This will make it much easier to later support CoreCLR too which
doesn't have rich embedding APIs.
Additionally the code in C# is more maintainable and makes it easier
to implement new features, e.g.: runtime codegen which we could use to
avoid using reflection for marshaling everytime a field, property or
method is accessed.
SOME NOTES ON INTEROP
We make the same assumptions as GDNative about the size of the Godot
structures we use. We take it a bit further by also assuming the layout
of fields in some cases, which is riskier but let's us squeeze out some
performance by avoiding unnecessary managed to native calls.
Code that deals with native structs is less safe than before as there's
no RAII and copy constructors in C#. It's like using the GDNative C API
directly. One has to take special care to free values they own.
Perhaps we could use roslyn analyzers to check this, but I don't know
any that uses attributes to determine what's owned or borrowed.
As to why we maily use pointers for native structs instead of ref/out:
- AFAIK (and confirmed with a benchmark) ref/out are pinned
during P/Invoke calls and that has a cost.
- Native struct fields can't be ref/out in the first place.
- A `using` local can't be passed as ref/out, only `in`. Calling a
method or property on an `in` value makes a silent copy, so we want
to avoid `in`.
REGARDING THE BUILD SYSTEM
There's no longer a `mono_glue=yes/no` SCons options. We no longer
need to build with `mono_glue=no`, generate the glue and then build
again with `mono_glue=yes`. We build only once and generate the glue
(which is in C# now).
However, SCons no longer builds the C# projects for us. Instead one
must run `build_assemblies.py`, e.g.:
```sh
%godot_src_root%/modules/mono/build_scripts/build_assemblies.py \
--godot-output-dir=%godot_src_root%/bin \
--godot-target=release_debug`
```
We could turn this into a custom build target, but I don't know how
to do that with SCons (it's possible with Meson).
OTHER NOTES
Most of the moved code doesn't follow the C# naming convention and
still has the word Mono in the names despite no longer dealing with
Mono's embedding APIs. This is just temporary while transitioning,
to make it easier to understand what was moved where.
2021-05-03 15:21:06 +02:00
|
|
|
Error _generate_cs_native_calls(const InternalCall &p_icall, StringBuilder &r_output);
|
|
|
|
|
2021-01-13 11:17:39 +01:00
|
|
|
void _generate_array_extensions(StringBuilder &p_output);
|
2019-04-19 01:10:08 +02:00
|
|
|
void _generate_global_constants(StringBuilder &p_output);
|
2017-12-24 03:17:48 +01:00
|
|
|
|
2019-04-19 01:10:08 +02:00
|
|
|
Error _save_file(const String &p_path, const StringBuilder &p_content);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-04-25 15:45:12 +02:00
|
|
|
void _log(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-04-25 15:45:12 +02:00
|
|
|
void _initialize();
|
2018-01-01 03:04:49 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
public:
|
2019-12-28 19:12:32 +01:00
|
|
|
Error generate_cs_core_project(const String &p_proj_dir);
|
|
|
|
Error generate_cs_editor_project(const String &p_proj_dir);
|
2019-04-25 15:45:12 +02:00
|
|
|
Error generate_cs_api(const String &p_output_dir);
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2019-07-03 09:44:53 +02:00
|
|
|
_FORCE_INLINE_ bool is_log_print_enabled() { return log_print_enabled; }
|
|
|
|
_FORCE_INLINE_ void set_log_print_enabled(bool p_enabled) { log_print_enabled = p_enabled; }
|
2019-04-25 15:45:12 +02:00
|
|
|
|
2019-09-24 15:09:54 +02:00
|
|
|
_FORCE_INLINE_ bool is_initialized() { return initialized; }
|
|
|
|
|
2019-04-25 15:45:12 +02:00
|
|
|
static void handle_cmdline_args(const List<String> &p_cmdline_args);
|
2018-01-01 03:04:49 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
BindingsGenerator() {
|
2019-04-25 15:45:12 +02:00
|
|
|
_initialize();
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // BINDINGS_GENERATOR_H
|