Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native implementation for Enum.HasFlag #1739

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions src/CLR/CorLib/corlib_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_corlib_native_System_Reflection_Assembly::LoadInternal___STATIC__SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4,
Library_corlib_native_System_Reflection_Assembly::Load___STATIC__SystemReflectionAssembly__SZARRAY_U1,
NULL,
Library_corlib_native_System_Enum::HasFlag___BOOLEAN__SystemEnum,
NULL,
Library_corlib_native_System_GC::AnyPendingFinalizers___STATIC__BOOLEAN,
NULL,
Expand Down Expand Up @@ -1175,6 +1176,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
Library_corlib_native_System_Enum::HasFlag___BOOLEAN__SystemEnum,
NULL,
Library_corlib_native_System_GC::AnyPendingFinalizers___STATIC__BOOLEAN,
NULL,
Expand Down Expand Up @@ -1411,18 +1413,18 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =

#if (NANOCLR_REFLECTION == TRUE)

0x5B91B419,
0x7F15FC30,

#elif (NANOCLR_REFLECTION == FALSE)

0x13B1386D,
0xB2C71FC2,

#else
#error "NANOCLR_REFLECTION has to be define either TRUE or FALSE. Check the build options."
#endif

method_lookup,
{ 100, 5, 0, 1 }
{ 100, 5, 0, 2 }
};

// clang-format on
7 changes: 7 additions & 0 deletions src/CLR/CorLib/corlib_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,13 @@ struct Library_corlib_native_System_Reflection_Assembly
#endif // NANOCLR_REFLECTION
};

struct Library_corlib_native_System_Enum
{
NANOCLR_NATIVE_DECLARE(HasFlag___BOOLEAN__SystemEnum);

//--//
};

struct Library_corlib_native_System_GC
{

Expand Down
38 changes: 37 additions & 1 deletion src/CLR/CorLib/corlib_native_System_Enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,40 @@
//
#include "CorLib.h"

// no code generated for this class
HRESULT Library_corlib_native_System_Enum::HasFlag___BOOLEAN__SystemEnum(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();

CLR_RT_TypeDescriptor enumTypeDesc;
CLR_RT_TypeDescriptor flagTypeDesc;
CLR_RT_HeapBlock *pEnum;
CLR_RT_HeapBlock *enumValue;
CLR_RT_HeapBlock *pFlag;
CLR_RT_HeapBlock *flagValue;

// get Enum value from 'This'
pEnum = &(stack.ThisRef());
enumValue = pEnum;

// need to unbox Enum to get value
NANOCLR_CHECK_HRESULT(enumTypeDesc.InitializeFromObject(*enumValue));
NANOCLR_CHECK_HRESULT(enumValue->PerformUnboxing(enumTypeDesc.m_handlerCls));

// get Enum value from 'flag' arg
pFlag = &(stack.Arg1());
flagValue = pFlag;

// need to unbox Enum to get value
NANOCLR_CHECK_HRESULT(flagTypeDesc.InitializeFromObject(*enumValue));
NANOCLR_CHECK_HRESULT(flagValue->PerformUnboxing(flagTypeDesc.m_handlerCls));

// check if both types are equivalent
if (enumTypeDesc.m_handlerCls.Type() != flagTypeDesc.m_handlerCls.Type())
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}

stack.SetResult_Boolean(enumValue->NumericByRef().s4 & flagValue->NumericByRef().s4);

NANOCLR_NOCLEANUP();
}