Skip to content

Commit

Permalink
Restore FindTypeDef code for reflection types (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
edleno2 authored Jun 2, 2021
1 parent 52191e1 commit 4befd3b
Showing 1 changed file with 101 additions and 95 deletions.
196 changes: 101 additions & 95 deletions src/CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3645,101 +3645,107 @@ bool CLR_RT_TypeSystem::FindTypeDef(const char *szClass, CLR_RT_Assembly *assm,

NATIVE_PROFILE_CLR_CORE();

// UNDONE: FIXME
// char rgName [ MAXTYPENAMELEN ];
// char rgNamespace[ MAXTYPENAMELEN ];
// CLR_RT_TypeDef_Index res;

// if(hal_strlen_s(szClass) < ARRAYSIZE(rgNamespace))
// {
// const char* szPtr = szClass;
// const char* szPtr_LastDot = NULL;
// const char* szPtr_FirstSubType = NULL;
// char c;
// size_t len;
// bool arrayType = false;

// while(true)
// {
// c = szPtr[ 0 ]; if(!c) break;

// if(c == '.')
// {
// szPtr_LastDot = szPtr;
// }
// else if(c == '+')
// {
// szPtr_FirstSubType = szPtr;
// break;
// }
// else if(c == '[')
// {
// char ch = szPtr[ 1 ];
// if (ch == ']')
// {
// arrayType = true;
// break;
// }
// }

// szPtr++;
// }

// if(szPtr_LastDot)
// {
// len = szPtr_LastDot++ - szClass ; hal_strncpy_s( rgNamespace, ARRAYSIZE(rgNamespace), szClass ,
// len ); len = szPtr - szPtr_LastDot; hal_strncpy_s( rgName , ARRAYSIZE(rgName ),
// szPtr_LastDot, len );
// }
// else
// {
// rgNamespace[ 0 ] = 0;
// hal_strcpy_s( rgName, ARRAYSIZE(rgName), szClass );
// }

// if(FindTypeDef( rgName, rgNamespace, assm, res ))
// {
// //
// // Found the containing type, let's look for the nested type.
// //
// if(szPtr_FirstSubType)
// {
// CLR_RT_TypeDef_Instance inst;

// do
// {
// szPtr = ++szPtr_FirstSubType;

// while(true)
// {
// c = szPtr_FirstSubType[ 0 ]; if(!c) break;

// if(c == '+') break;

// szPtr_FirstSubType++;
// }

// len = szPtr_FirstSubType - szPtr; hal_strncpy_s( rgName, ARRAYSIZE(rgName), szPtr, len );

// inst.InitializeFromIndex( res );

// if(inst.m_assm->FindTypeDef( rgName, res.Type(), res ) == false)
// {
// return false;
// }

// } while(c == '+');
// }

// reflex.m_kind = REFLECTION_TYPE;
// // make sure this works for multidimensional arrays.
// reflex.m_levels = arrayType ? 1 : 0;
// reflex.m_data.m_type = res;
// return true;
// }
// }
//
// res.Clear();
char rgName[MAXTYPENAMELEN];
char rgNamespace[MAXTYPENAMELEN];
CLR_RT_TypeDef_Index res;

if (hal_strlen_s(szClass) < ARRAYSIZE(rgNamespace))
{
const char *szPtr = szClass;
const char *szPtr_LastDot = NULL;
const char *szPtr_FirstSubType = NULL;
char c;
size_t len;
bool arrayType = false;

while (true)
{
c = szPtr[0];
if (!c)
break;

if (c == '.')
{
szPtr_LastDot = szPtr;
}
else if (c == '+')
{
szPtr_FirstSubType = szPtr;
break;
}
else if (c == '[')
{
char ch = szPtr[1];
if (ch == ']')
{
arrayType = true;
break;
}
}

szPtr++;
}

if (szPtr_LastDot)
{
len = szPtr_LastDot++ - szClass;
hal_strncpy_s(rgNamespace, ARRAYSIZE(rgNamespace), szClass, len);
len = szPtr - szPtr_LastDot;
hal_strncpy_s(rgName, ARRAYSIZE(rgName), szPtr_LastDot, len);
}
else
{
rgNamespace[0] = 0;
hal_strcpy_s(rgName, ARRAYSIZE(rgName), szClass);
}

if (FindTypeDef(rgName, rgNamespace, assm, res))
{
//
// Found the containing type, let's look for the nested type.
//
if (szPtr_FirstSubType)
{
CLR_RT_TypeDef_Instance inst;

do
{
szPtr = ++szPtr_FirstSubType;

while (true)
{
c = szPtr_FirstSubType[0];
if (!c)
break;

if (c == '+')
break;

szPtr_FirstSubType++;
}

len = szPtr_FirstSubType - szPtr;
hal_strncpy_s(rgName, ARRAYSIZE(rgName), szPtr, len);

inst.InitializeFromIndex(res);

if (inst.m_assm->FindTypeDef(rgName, res.Type(), res) == false)
{
return false;
}

} while (c == '+');
}

reflex.m_kind = REFLECTION_TYPE;
// make sure this works for multidimensional arrays.
reflex.m_levels = arrayType ? 1 : 0;
reflex.m_data.m_type = res;
return true;
}
}

res.Clear();

return false;
}
Expand Down

0 comments on commit 4befd3b

Please sign in to comment.