• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SamboyCoding / Cpp2IL / 13502852876

24 Feb 2025 04:27PM UTC coverage: 27.267% (-0.07%) from 27.341%
13502852876

push

github

web-flow
Fix explicit interface method overrides (#414)

1261 of 6442 branches covered (19.57%)

Branch coverage included in aggregate %.

17 of 123 new or added lines in 10 files covered. (13.82%)

1 existing line in 1 file now uncovered.

3375 of 10560 relevant lines covered (31.96%)

123364.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.63
/Cpp2IL.Core/Model/Contexts/ConcreteGenericMethodAnalysisContext.cs
1
using System.Linq;
2
using System.Reflection;
3
using Cpp2IL.Core.Utils;
4
using LibCpp2IL;
5
using LibCpp2IL.BinaryStructures;
6
using LibCpp2IL.Reflection;
7

8
namespace Cpp2IL.Core.Model.Contexts;
9

10
public class ConcreteGenericMethodAnalysisContext : MethodAnalysisContext
11
{
12
    public readonly AssemblyAnalysisContext DeclaringAsm;
13
    public readonly Cpp2IlMethodRef? MethodRef;
14
    public readonly MethodAnalysisContext BaseMethodContext;
15

NEW
16
    public TypeAnalysisContext[] TypeGenericParameters { get; }
×
17

NEW
18
    public TypeAnalysisContext[] MethodGenericParameters { get; }
×
19

20
    public sealed override ulong UnderlyingPointer => MethodRef?.GenericVariantPtr ?? default;
435,658!
21

22
    public override bool IsStatic => BaseMethodContext.IsStatic;
×
23

24
    public override bool IsVoid => BaseMethodContext.IsVoid;
×
25

26
    public override string DefaultName => BaseMethodContext.DefaultName;
×
27

28
    public override MethodAttributes Attributes => BaseMethodContext.Attributes;
×
29

30
    public override AssemblyAnalysisContext CustomAttributeAssembly => BaseMethodContext.CustomAttributeAssembly;
×
31

32
    public ConcreteGenericMethodAnalysisContext(Cpp2IlMethodRef methodRef, ApplicationAnalysisContext context)
33
        : this(methodRef, ResolveDeclaringAssembly(methodRef, context))
145,386✔
34
    {
35
    }
145,386✔
36

37
    private ConcreteGenericMethodAnalysisContext(Cpp2IlMethodRef methodRef, AssemblyAnalysisContext declaringAssembly)
38
        : this(
145,386✔
39
              methodRef,
145,386✔
40
              ResolveBaseMethod(methodRef, declaringAssembly.GetTypeByDefinition(methodRef.DeclaringType)!),
145,386✔
41
              ResolveDeclaringType(methodRef, declaringAssembly),
145,386✔
42
              ResolveTypeArray(methodRef.TypeGenericParams, declaringAssembly),
145,386✔
43
              ResolveTypeArray(methodRef.MethodGenericParams, declaringAssembly),
145,386✔
44
              declaringAssembly)
145,386✔
45
    {
46
    }
145,386✔
47

48
    public ConcreteGenericMethodAnalysisContext(MethodAnalysisContext baseMethod, TypeAnalysisContext[] typeGenericParameters, TypeAnalysisContext[] methodGenericParameters)
NEW
49
        : this(
×
NEW
50
              null,
×
NEW
51
              baseMethod,
×
NEW
52
              typeGenericParameters.Length > 0 ? baseMethod.DeclaringType!.MakeGenericInstanceType(typeGenericParameters) : baseMethod.DeclaringType!,
×
NEW
53
              typeGenericParameters,
×
NEW
54
              methodGenericParameters,
×
NEW
55
              baseMethod.CustomAttributeAssembly)
×
56
    {
NEW
57
    }
×
58

59
    private ConcreteGenericMethodAnalysisContext(Cpp2IlMethodRef? methodRef, MethodAnalysisContext baseMethodContext, TypeAnalysisContext declaringType, TypeAnalysisContext[] typeGenericParameters, TypeAnalysisContext[] methodGenericParameters, AssemblyAnalysisContext declaringAssembly)
60
        : base(null, declaringType)
145,386✔
61
    {
62
        MethodRef = methodRef;
145,386✔
63
        DeclaringAsm = declaringAssembly;
145,386✔
64
        BaseMethodContext = baseMethodContext;
145,386✔
65

66
        TypeGenericParameters = typeGenericParameters;
145,386✔
67
        MethodGenericParameters = methodGenericParameters;
145,386✔
68

69
        // For the purpose of generic instantiation, we need an array of method generic parameters, even if none are provided.
70
        if (methodGenericParameters.Length == 0 && baseMethodContext.GenericParameterCount > 0)
145,386!
NEW
71
            methodGenericParameters = Enumerable.Range(0, baseMethodContext.GenericParameterCount)
×
NEW
72
                .Select(i => new GenericParameterTypeAnalysisContext("T", i, Il2CppTypeEnum.IL2CPP_TYPE_MVAR, declaringAssembly))
×
NEW
73
                .ToArray();
×
74

75
        for (var i = 0; i < BaseMethodContext.Parameters.Count; i++)
598,748✔
76
        {
77
            var parameter = BaseMethodContext.Parameters[i];
153,988✔
78
            var parameterType = parameter.ParameterTypeContext;
153,988✔
79
            var instantiatedType = GenericInstantiation.Instantiate(
153,988✔
80
                parameter.ParameterTypeContext,
153,988✔
81
                typeGenericParameters,
153,988✔
82
                methodGenericParameters);
153,988✔
83

84
            Parameters.Add(parameterType == instantiatedType
153,988✔
85
                ? parameter
153,988✔
86
                : new InjectedParameterAnalysisContext(parameter.Name, instantiatedType, i, BaseMethodContext));
153,988✔
87
        }
88

89
        InjectedReturnType = GenericInstantiation.Instantiate(BaseMethodContext.ReturnTypeContext, typeGenericParameters, methodGenericParameters);
145,386✔
90

91
        if (UnderlyingPointer != 0)
145,386✔
92
            rawMethodBody = AppContext.InstructionSet.GetRawBytesForMethod(this, false);
144,886✔
93
    }
145,386✔
94

95
    private static AssemblyAnalysisContext ResolveDeclaringAssembly(Cpp2IlMethodRef methodRef, ApplicationAnalysisContext context)
96
    {
97
        return context.GetAssemblyByName(methodRef.DeclaringType.DeclaringAssembly!.Name!)
145,386!
98
               ?? throw new($"Unable to resolve declaring assembly {methodRef.DeclaringType.DeclaringAssembly.Name} for generic method {methodRef}");
145,386✔
99
    }
100

101
    private static TypeAnalysisContext ResolveDeclaringType(Cpp2IlMethodRef methodRef, AssemblyAnalysisContext declaringAssembly)
102
    {
103
        var baseType = declaringAssembly.AppContext.ResolveContextForType(methodRef.DeclaringType)
145,386!
104
                       ?? throw new($"Unable to resolve declaring type {methodRef.DeclaringType.FullName} for generic method {methodRef}");
145,386✔
105

106
        if (methodRef.TypeGenericParams.Length == 0)
145,386✔
107
            return baseType;
21,386✔
108

109
        var genericParams = ResolveTypeArray(methodRef.TypeGenericParams, declaringAssembly);
124,000✔
110

111
        return new GenericInstanceTypeAnalysisContext(baseType, genericParams, declaringAssembly);
124,000✔
112
    }
113

114
    private static TypeAnalysisContext[] ResolveTypeArray(Il2CppTypeReflectionData[] array, AssemblyAnalysisContext declaringAssembly)
115
    {
116
        if (array.Length == 0)
414,772✔
117
            return [];
143,490✔
118

119
        var ret = new TypeAnalysisContext[array.Length];
271,282✔
120
        for (var i = 0; i < array.Length; i++)
1,245,356✔
121
        {
122
            ret[i] = array[i].ToContext(declaringAssembly)
351,396!
123
                     ?? throw new($"Unable to resolve generic parameter {array[i]} for generic method.");
351,396✔
124
        }
125

126
        return ret;
271,282✔
127
    }
128

129
    private static MethodAnalysisContext ResolveBaseMethod(Cpp2IlMethodRef methodRef, TypeAnalysisContext declaringType)
130
    {
131
        return declaringType.GetMethod(methodRef.BaseMethod)
145,386!
132
               ?? throw new($"Unable to resolve base method {methodRef.BaseMethod} for generic method {methodRef}");
145,386✔
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc