Skip to content

Commit de32afb

Browse files
committed
FindTypeDef is now able to process nested types
- Following nanoframework/metadata-processor@20ed3fd
1 parent 1d18fa1 commit de32afb

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/CLR/Core/TypeSystem.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,25 +4291,61 @@ bool CLR_RT_Assembly::FindTypeDef(const char *typeName, const char *nameSpace, C
42914291
NATIVE_PROFILE_CLR_CORE();
42924292
const CLR_RECORD_TYPEDEF *target = GetTypeDef(0);
42934293
int tblSize = tablesSize[TBL_TypeDef];
4294+
bool isNestedType = false;
4295+
4296+
// Check if typeName contains '/'
4297+
const char *slashPos = strchr(typeName, '/');
4298+
if (slashPos != nullptr)
4299+
{
4300+
// Extract the type name from the '/' to the end of the string
4301+
const char *extractedTypeName = slashPos + 1;
4302+
4303+
// Extract the enclosed type name from the '/' backwards to the '.' before
4304+
const char *dotPos = strrchr(typeName, '.');
4305+
std::string enclosedTypeName(dotPos + 1, slashPos);
4306+
4307+
// Extract the namespace from the beginning of the string to that '.'
4308+
std::string extractedNamespace(typeName, dotPos - typeName);
4309+
4310+
// Use the extracted values for further processing
4311+
typeName = extractedTypeName;
4312+
nameSpace = extractedNamespace.c_str();
4313+
4314+
// set flag to indicate that this is a nested type
4315+
isNestedType = true;
4316+
}
42944317

42954318
for (int i = 0; i < tblSize; i++, target++)
42964319
{
4297-
if (!target->HasValidEnclosingType())
4320+
if (isNestedType)
4321+
{
4322+
// check if this is a nested type
4323+
if (target->HasValidEnclosingType())
4324+
{
4325+
const char *szNameSpace = GetString(target->nameSpace);
4326+
const char *szName = GetString(target->name);
4327+
4328+
if (!strcmp(szName, typeName) && !strcmp(szNameSpace, nameSpace))
4329+
{
4330+
index.Set(assemblyIndex, i);
4331+
return true;
4332+
}
4333+
}
4334+
}
4335+
else if (!target->HasValidEnclosingType())
42984336
{
42994337
const char *szNameSpace = GetString(target->nameSpace);
43004338
const char *szName = GetString(target->name);
43014339

43024340
if (!strcmp(szName, typeName) && !strcmp(szNameSpace, nameSpace))
43034341
{
43044342
index.Set(assemblyIndex, i);
4305-
43064343
return true;
43074344
}
43084345
}
43094346
}
43104347

43114348
index.Clear();
4312-
43134349
return false;
43144350
}
43154351

0 commit comments

Comments
 (0)