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

SamboyCoding / Cpp2IL / 15144170590

20 May 2025 05:37PM UTC coverage: 34.277% (+0.2%) from 34.047%
15144170590

Pull #462

github

web-flow
Merge 4a307f12a into 5807d2b6c
Pull Request #462: Support overriding member types

1799 of 6648 branches covered (27.06%)

Branch coverage included in aggregate %.

115 of 202 new or added lines in 33 files covered. (56.93%)

22 existing lines in 6 files now uncovered.

4197 of 10845 relevant lines covered (38.7%)

186399.11 hits per line

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

39.22
/Cpp2IL.Core/Model/Contexts/ParameterAnalysisContext.cs
1
using System.Reflection;
2
using System.Text;
3
using Cpp2IL.Core.Utils;
4
using LibCpp2IL.Metadata;
5
using StableNameDotNet.Providers;
6

7
namespace Cpp2IL.Core.Model.Contexts;
8

9
public class ParameterAnalysisContext : HasCustomAttributesAndName, IParameterInfoProvider
10
{
11
    /// <summary>
12
    /// The backing il2cpp definition of this parameter. Can be null if the parameter is injected. 
13
    /// </summary>
14
    public Il2CppParameterDefinition? Definition { get; }
2,349,267✔
15

16
    /// <summary>
17
    /// The index of this parameter in the declaring method's parameter list.
18
    /// </summary>
19
    public int ParameterIndex { get; }
512,093✔
20

21
    /// <summary>
22
    /// The method which this parameter belongs to. Cannot be null.
23
    /// </summary>
24
    public MethodAnalysisContext DeclaringMethod { get; }
1,517,161✔
25

26
    protected override int CustomAttributeIndex => Definition?.customAttributeIndex ?? throw new("Subclasses of ParameterAnalysisContext must provide a customAttributeIndex");
412,587!
27
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringMethod.DeclaringType!.DeclaringAssembly;
1,103,148✔
28
    public override string DefaultName => Definition?.Name ?? throw new("Subclasses of ParameterAnalysisContext must provide a default name");
98,235!
29

30
    /// <summary>
31
    /// The human-readable display value of the parameter type.
32
    /// </summary>
NEW
33
    public string ReadableTypeName => ParameterType.FullName;
×
34

35
    /// <summary>
36
    /// The human-readable display value of the parameter, as it would appear in a c# method declaration.
37
    /// </summary>
38
    public string HumanReadableSignature => $"{ReadableTypeName} {Name}";
×
39

40
    public virtual ParameterAttributes DefaultAttributes => (ParameterAttributes?)Definition?.RawType?.Attrs ?? throw new("Subclasses of ParameterAnalysisContext must provide parameter attributes");
603,480!
41

42
    public virtual ParameterAttributes? OverrideAttributes { get; set; }
603,480✔
43

44
    /// <summary>
45
    /// The ParameterAttributes of this parameter.
46
    /// </summary>
47
    public ParameterAttributes Attributes => OverrideAttributes ?? DefaultAttributes;
603,480!
48

49
    /// <summary>
50
    /// True if this parameter is passed by reference.
51
    /// </summary>
NEW
52
    public bool IsRef => ParameterType is ByRefTypeAnalysisContext || Attributes.HasFlag(ParameterAttributes.Out);
×
53

54
    /// <summary>
55
    /// The default value data for this parameter. Null if, and only if, the parameter has no default value. If it has a default value of literally null, this will be non-null and have a data index of -1.
56
    /// </summary>
57
    public Il2CppParameterDefaultValue? DefaultValue { get; }
98,235✔
58

59
    public virtual TypeAnalysisContext DefaultParameterType => DeclaringMethod.DeclaringType!.DeclaringAssembly.ResolveIl2CppType(Definition?.RawType) ?? throw new("Subclasses of ParameterAnalysisContext must provide a parameter type");
414,013!
60

61
    public TypeAnalysisContext? OverrideParameterType { get; set; }
414,015✔
62

63
    public virtual TypeAnalysisContext ParameterType => OverrideParameterType ?? DefaultParameterType;
414,015✔
64

65
    public ParameterAnalysisContext(Il2CppParameterDefinition? definition, int parameterIndex, MethodAnalysisContext declaringMethod) : base(definition?.token ?? 0, declaringMethod.AppContext)
820,952✔
66
    {
67
        Definition = definition;
820,952✔
68
        ParameterIndex = parameterIndex;
820,952✔
69
        DeclaringMethod = declaringMethod;
820,952✔
70

71
        if (Definition != null)
820,952✔
72
        {
73
            InitCustomAttributeData();
505,245✔
74

75
            if (Attributes.HasFlag(ParameterAttributes.HasDefault))
505,245✔
76
            {
77
                DefaultValue = AppContext.Metadata.GetParameterDefaultValueFromIndex(declaringMethod.Definition!.parameterStart + parameterIndex)!;
2,199✔
78
            }
79
        }
80
    }
820,952✔
81

82
    public override string ToString()
83
    {
84
        if (!AppContext.HasFinishedInitializing)
×
85
            //Cannot safely access ParameterTypeContext.Name if we haven't finished initializing as it may require doing system type lookups etc.
NEW
86
            return $"Parameter {Name} (ordinal {ParameterIndex}) of {DeclaringMethod}";
×
87

88
        var result = new StringBuilder();
×
89

NEW
90
        if (Attributes.HasFlag(ParameterAttributes.Out))
×
91
            result.Append("out ");
×
NEW
92
        else if (Attributes.HasFlag(ParameterAttributes.In))
×
93
            result.Append("in ");
×
NEW
94
        else if (ParameterType is ByRefTypeAnalysisContext)
×
95
            result.Append("ref ");
×
96

NEW
97
        result.Append(CsFileUtils.GetTypeName(ParameterType.Name)).Append(' ');
×
98

99
        if (string.IsNullOrEmpty(ParameterName))
×
NEW
100
            result.Append("unnamed_param_").Append(ParameterIndex);
×
101
        else
102
            result.Append(ParameterName);
×
103

NEW
104
        if (Attributes.HasFlag(ParameterAttributes.HasDefault))
×
105
        {
106
            var defaultValue = DefaultValue!.ContainedDefaultValue;
×
107
            if (defaultValue is string stringDefaultValue)
×
108
                defaultValue = $"\"{stringDefaultValue}\"";
×
109
            else if (defaultValue is bool boolDefaultValue)
×
110
                defaultValue = boolDefaultValue.ToString().ToLowerInvariant();
×
111
            else if (defaultValue is null)
×
112
                defaultValue = "null";
×
113

114
            result.Append(" = ").Append(defaultValue);
×
115
        }
116

117
        return result.ToString();
×
118
    }
119

120
    #region StableNameDotNet implementation
121

122
    public ITypeInfoProvider ParameterTypeInfoProvider
123
        => Definition!.RawType!.ThisOrElementIsGenericParam()
×
124
            ? new GenericParameterTypeInfoProviderWrapper(Definition.RawType!.GetGenericParamName())
×
125
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, Definition.RawType);
×
126

127
    public string ParameterName => Name;
×
128

129
    #endregion
130
}
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

© 2025 Coveralls, Inc