Skip to content

Commit d240ab2

Browse files
mandel-macaqueGitHub Actions Autoformatter
and
GitHub Actions Autoformatter
authored
[RGen] Keep track in the generator if a type needs a stret call. (#22138)
This changes a little the way we create parameters and types because we need the compilation target to know if a type needs a stret call. We do not use the NeedsStret in the equlas method because that information has not value when we are deciding if a type needs to be regenerated or not by the roslyn code generator. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
1 parent e816eb9 commit d240ab2

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/rgen/Microsoft.Macios.Generator/DataModel/Constructor.Generator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static bool TryCreate (ConstructorDeclarationSyntax declaration, RootCont
2525
// loop over the parameters of the construct since changes on those implies a change in the generated code
2626
foreach (var parameter in constructor.Parameters) {
2727
var parameterDeclaration = declaration.ParameterList.Parameters [parameter.Ordinal];
28-
if (!Parameter.TryCreate (parameter, parameterDeclaration, context.SemanticModel, out var parameterChange))
28+
if (!Parameter.TryCreate (parameter, parameterDeclaration, context, out var parameterChange))
2929
continue;
3030
parametersBucket.Add (parameterChange.Value);
3131
}

src/rgen/Microsoft.Macios.Generator/DataModel/Method.Generator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static bool TryCreate (MethodDeclarationSyntax declaration, RootContext c
7676
// loop over the parameters of the construct since changes on those implies a change in the generated code
7777
foreach (var parameter in method.Parameters) {
7878
var parameterDeclaration = declaration.ParameterList.Parameters [parameter.Ordinal];
79-
if (!Parameter.TryCreate (parameter, parameterDeclaration, context.SemanticModel, out var parameterChange))
79+
if (!Parameter.TryCreate (parameter, parameterDeclaration, context, out var parameterChange))
8080
continue;
8181
parametersBucket.Add (parameterChange.Value);
8282
}
@@ -90,7 +90,7 @@ public static bool TryCreate (MethodDeclarationSyntax declaration, RootContext c
9090
change = new (
9191
type: method.ContainingSymbol.ToDisplayString ().Trim (), // we want the full name
9292
name: method.Name,
93-
returnType: new TypeInfo (method.ReturnType),
93+
returnType: new TypeInfo (method.ReturnType, context.Compilation),
9494
symbolAvailability: method.GetSupportedPlatforms (),
9595
exportMethodData: exportData,
9696
attributes: attributes,

src/rgen/Microsoft.Macios.Generator/DataModel/Parameter.Generator.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.CodeAnalysis;
66
using Microsoft.CodeAnalysis.CSharp.Syntax;
77
using Microsoft.Macios.Generator.Attributes;
8+
using Microsoft.Macios.Generator.Context;
89
using Microsoft.Macios.Generator.Extensions;
910

1011
namespace Microsoft.Macios.Generator.DataModel;
@@ -40,7 +41,7 @@ public bool NeedsNullCheck {
4041
}
4142
}
4243

43-
public static bool TryCreate (IParameterSymbol symbol, ParameterSyntax declaration, SemanticModel semanticModel,
44+
public static bool TryCreate (IParameterSymbol symbol, ParameterSyntax declaration, RootContext context,
4445
[NotNullWhen (true)] out Parameter? parameter)
4546
{
4647
DelegateInfo? delegateInfo = null;
@@ -49,15 +50,15 @@ public static bool TryCreate (IParameterSymbol symbol, ParameterSyntax declarati
4950
DelegateInfo.TryCreate (namedTypeSymbol.DelegateInvokeMethod, out delegateInfo);
5051
}
5152

52-
parameter = new (symbol.Ordinal, new (symbol.Type), symbol.Name) {
53+
parameter = new (symbol.Ordinal, new (symbol.Type, context.Compilation), symbol.Name) {
5354
BindAs = symbol.GetBindFromData (),
5455
IsOptional = symbol.IsOptional,
5556
IsParams = symbol.IsParams,
5657
IsThis = symbol.IsThis,
5758
DefaultValue = (symbol.HasExplicitDefaultValue) ? symbol.ExplicitDefaultValue?.ToString () : null,
5859
ReferenceKind = symbol.RefKind.ToReferenceKind (),
5960
Delegate = delegateInfo,
60-
Attributes = declaration.GetAttributeCodeChanges (semanticModel),
61+
Attributes = declaration.GetAttributeCodeChanges (context.SemanticModel),
6162
};
6263
return true;
6364
}

src/rgen/Microsoft.Macios.Generator/DataModel/Property.Generator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static bool TryCreate (PropertyDeclarationSyntax declaration, RootContext
200200

201201
change = new (
202202
name: memberName,
203-
returnType: new (propertySymbol.Type),
203+
returnType: new (propertySymbol.Type, context.Compilation),
204204
symbolAvailability: propertySupportedPlatforms,
205205
attributes: attributes,
206206
modifiers: [.. declaration.Modifiers],

src/rgen/Microsoft.Macios.Generator/DataModel/TypeInfo.Generator.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ readonly partial struct TypeInfo {
1313
/// </summary>
1414
public bool IsWrapped { get; init; }
1515

16+
/// <summary>
17+
/// True if the type needs to use a stret call.
18+
/// </summary>
19+
public bool NeedsStret { get; init; }
20+
1621
/// <summary>
1722
/// Returns, if the type is an array, if its elements are a wrapped object from the objc world.
1823
/// </summary>
1924
public bool ArrayElementTypeIsWrapped { get; init; }
2025

21-
internal TypeInfo (ITypeSymbol symbol) :
26+
internal TypeInfo (ITypeSymbol symbol, Compilation compilation) :
2227
this (
2328
symbol is IArrayTypeSymbol arrayTypeSymbol
2429
? arrayTypeSymbol.ElementType.ToDisplayString ()
@@ -33,6 +38,7 @@ symbol is IArrayTypeSymbol arrayTypeSymbol
3338
IsInterface = symbol.TypeKind == TypeKind.Interface;
3439
IsNativeIntegerType = symbol.IsNativeIntegerType;
3540
IsNativeEnum = symbol.HasAttribute (AttributesNames.NativeEnumAttribute);
41+
NeedsStret = symbol.NeedsStret (compilation);
3642

3743
// data that we can get from the symbol without being INamedType
3844
symbol.GetInheritance (

0 commit comments

Comments
 (0)