Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Implement C and Java generation support for implicit/explicit operators #588

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[support] Added mono_embeddinator_lookup_method_ret() to lookup metho…
…ds with return type overloading.
  • Loading branch information
tritao committed Jan 28, 2018
commit 667d28c1d4e7d09254718b69a519de47535216e8
37 changes: 36 additions & 1 deletion support/mono_embeddinator.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,45 @@ MonoClass* mono_embeddinator_search_class(const char* assembly, const char* _nam
return klass;
}

static MonoMethod* mono_method_desc_search_in_class_extra(const char* return_type,
MonoMethodDesc *desc, MonoClass *klass)
{
MonoMethod* m;
gpointer iter = NULL;

while ((m = mono_class_get_methods (klass, &iter)))
if (mono_method_desc_match (desc, m)) {
if (return_type == NULL)
return m;

MonoType* ret = *(MonoType**)mono_method_signature(m);
char* name = mono_type_full_name(ret);
gboolean matches = strcmp(name, return_type) == 0;
g_free(name);

if (!matches) continue;

return m;
}

return NULL;
}

MonoMethod* mono_embeddinator_lookup_method(const char* method_name, MonoClass *klass)
{
return mono_embeddinator_lookup_method_ret(NULL, method_name, klass);
}

MonoMethod* mono_embeddinator_lookup_method_ret(const char* ret_type_name,
const char* method_name, MonoClass *klass)
{
MonoMethodDesc* desc = mono_method_desc_new(method_name, /*include_namespace=*/true);
MonoMethod* method = mono_method_desc_search_in_class(desc, klass);

// Previously we used mono_method_desc_search_in_class but since it does not take
// return types into account, it leads to wrong results in the case of explicit
// operators due to return type overloading.

MonoMethod* method = mono_method_desc_search_in_class_extra(ret_type_name, desc, klass);
mono_method_desc_free(desc);

if (!method)
Expand Down
8 changes: 8 additions & 0 deletions support/mono_embeddinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ MonoClass* mono_embeddinator_search_class(const char* assembly, const char* _nam
MONO_EMBEDDINATOR_API
MonoMethod* mono_embeddinator_lookup_method(const char* method_name, MonoClass* klass);

/**
* Looks up and returns a MonoMethod* for a given Mono class and method name,
* taking the return type of the method into account.
*/
MONO_EMBEDDINATOR_API
MonoMethod* mono_embeddinator_lookup_method_ret(const char* ret_type_name,
const char* method_name, MonoClass* klass);

/**
* Throws an exception based on a given Mono exception object.
*/
Expand Down