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

SamboyCoding / Cpp2IL / 15043797356

15 May 2025 11:28AM UTC coverage: 34.797% (+0.002%) from 34.795%
15043797356

Pull #450

github

web-flow
Merge 913336839 into 26422e974
Pull Request #450: Update IsRef property in InjectedParameterAnalysisContext

1809 of 6498 branches covered (27.84%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

4159 of 10653 relevant lines covered (39.04%)

161155.46 hits per line

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

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

9
namespace Cpp2IL.Core.Model.Contexts;
10

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

18
    /// <summary>
19
    /// The index of this parameter in the declaring method's parameter list.
20
    /// </summary>
21
    public int ParamIndex { get; }
196,470✔
22

23
    /// <summary>
24
    /// The method which this parameter belongs to. Cannot be null.
25
    /// </summary>
26
    public MethodAnalysisContext DeclaringMethod { get; }
1,082,504✔
27

28
    /// <summary>
29
    /// The il2cpp type of the parameter. Cannot be null.
30
    /// </summary>
31
    public virtual Il2CppType ParameterType => Definition?.RawType ?? throw new("Subclasses of ParameterAnalysisContext must provide a parameter type");
1,088,081!
32

33
    protected override int CustomAttributeIndex => Definition?.customAttributeIndex ?? throw new("Subclasses of ParameterAnalysisContext must provide a customAttributeIndex");
314,352!
34
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringMethod.DeclaringType!.DeclaringAssembly;
499,668✔
35
    public override string DefaultName => Definition?.Name ?? throw new("Subclasses of ParameterAnalysisContext must provide a default name");
205,405!
36

37
    /// <summary>
38
    /// The human-readable display value of the parameter type.
39
    /// </summary>
40
    public string ReadableTypeName => ParameterTypeContext.FullName;
×
41

42
    /// <summary>
43
    /// The human-readable display value of the parameter, as it would appear in a c# method declaration.
44
    /// </summary>
45
    public string HumanReadableSignature => $"{ReadableTypeName} {Name}";
×
46

47
    /// <summary>
48
    /// The ParameterAttributes of this parameter.
49
    /// </summary>
50
    public virtual ParameterAttributes ParameterAttributes => (ParameterAttributes)ParameterType.Attrs;
505,245✔
51

52
    /// <summary>
53
    /// True if this parameter is passed by reference.
54
    /// </summary>
NEW
55
    public bool IsRef => ParameterTypeContext is ByRefTypeAnalysisContext || ParameterAttributes.HasFlag(ParameterAttributes.Out);
×
56

57
    /// <summary>
58
    /// 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.
59
    /// </summary>
60
    public Il2CppParameterDefaultValue? DefaultValue { get; }
98,235✔
61

62
    public virtual TypeAnalysisContext ParameterTypeContext => DeclaringMethod.DeclaringType!.DeclaringAssembly.ResolveIl2CppType(ParameterType);
582,836✔
63

64
    public ParameterAnalysisContext(Il2CppParameterDefinition? definition, int paramIndex, MethodAnalysisContext declaringMethod) : base(definition?.token ?? 0, declaringMethod.AppContext)
514,264✔
65
    {
66
        Definition = definition;
514,264✔
67
        ParamIndex = paramIndex;
514,264✔
68
        DeclaringMethod = declaringMethod;
514,264✔
69

70
        if (Definition != null)
514,264✔
71
        {
72
            InitCustomAttributeData();
407,010✔
73

74
            if (ParameterAttributes.HasFlag(ParameterAttributes.HasDefault))
407,010✔
75
            {
76
                DefaultValue = AppContext.Metadata.GetParameterDefaultValueFromIndex(declaringMethod.Definition!.parameterStart + paramIndex)!;
1,784✔
77
            }
78
        }
79
    }
514,264✔
80

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

87
        var result = new StringBuilder();
×
88

89
        if (ParameterAttributes.HasFlag(ParameterAttributes.Out))
×
90
            result.Append("out ");
×
91
        else if (ParameterAttributes.HasFlag(ParameterAttributes.In))
×
92
            result.Append("in ");
×
93
        else if (ParameterType.Byref == 1)
×
94
            result.Append("ref ");
×
95

96
        result.Append(CsFileUtils.GetTypeName(ParameterTypeContext.Name)).Append(' ');
×
97

98
        if (string.IsNullOrEmpty(ParameterName))
×
99
            result.Append("unnamed_param_").Append(ParamIndex);
×
100
        else
101
            result.Append(ParameterName);
×
102

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

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

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

119
    #region StableNameDotNet implementation
120

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

126
    public string ParameterName => Name;
×
127

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