Skip to content

Commit

Permalink
Split one more part of MemberReferenceScanner into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
CorruptComputer committed Nov 26, 2023
1 parent 44df0ff commit 66ea3b0
Showing 1 changed file with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,47 +55,53 @@ when typeCfg.FieldsParsed.Any(field => field.Name == mMemberRefField.Name
errors.Add(new($"Access to field not allowed: {mMemberRefField}"));
return;
case MMemberRefMethod mMemberRefMethod:
bool safe = IsMMemberRefMethodSafe(mMemberRefMethod, typeCfg);
if (!safe)
{
foreach (WhitelistMethodDefine parsed in typeCfg.MethodsParsed)
{
bool paramMismatch = false;

if (parsed.Name != mMemberRefMethod.Name ||
!mMemberRefMethod.ReturnType.WhitelistEquals(parsed.ReturnType) ||
mMemberRefMethod.ParameterTypes.Length != parsed.ParameterTypes.Count ||
mMemberRefMethod.GenericParameterCount != parsed.GenericParameterCount)
{
continue;
}

for (int i = 0; i < mMemberRefMethod.ParameterTypes.Length; i++)
{
MType a = mMemberRefMethod.ParameterTypes[i];
MType b = parsed.ParameterTypes[i];

if (a.WhitelistEquals(b))
{
continue;
}

paramMismatch = true;
break;
}

if (!paramMismatch)
{
return; // Found
}
}

errors.Add(new($"Access to method not allowed: {mMemberRefMethod}"));
return;
}

return;
default:
throw new ArgumentException($"Invalid memberRef type: {memberRef.GetType()}", nameof(memberRef));
}
}

private static bool IsMMemberRefMethodSafe(MMemberRefMethod mMemberRefMethod, TypeConfig typeCfg)
{
foreach (WhitelistMethodDefine parsed in typeCfg.MethodsParsed)
{
bool paramMismatch = false;
if (parsed.Name != mMemberRefMethod.Name ||
!mMemberRefMethod.ReturnType.WhitelistEquals(parsed.ReturnType) ||
mMemberRefMethod.ParameterTypes.Length != parsed.ParameterTypes.Count ||
mMemberRefMethod.GenericParameterCount != parsed.GenericParameterCount)
{
continue;
}

for (int i = 0; i < mMemberRefMethod.ParameterTypes.Length; i++)
{
MType a = mMemberRefMethod.ParameterTypes[i];
MType b = parsed.ParameterTypes[i];

if (a.WhitelistEquals(b))
{
continue;
}

paramMismatch = true;
break;
}
if (!paramMismatch)
{
return true; // Found
}
}

return false;
}


private static MTypeReferenced? GetBaseMTypeReferenced(MMemberRef memberRef)
{
Expand Down

0 comments on commit 66ea3b0

Please sign in to comment.