-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rgen] Add a property invocations struct to be used with the syntaxt …
…factory. This will allow to have a struct that will contain all the needed invocation data. We need to update some of the uses froma CompilationUnit to a StatementSyntax, which actually makes the code better overall while letting us use a throw statement as the invocation statement for a property.
- Loading branch information
1 parent
de74ece
commit 10de30e
Showing
7 changed files
with
167 additions
and
134 deletions.
There are no files selected for viewing
121 changes: 58 additions & 63 deletions
121
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Dlfcn.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Property.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Macios.Generator.DataModel; | ||
using TypeInfo = Microsoft.Macios.Generator.DataModel.TypeInfo; | ||
|
||
namespace Microsoft.Macios.Generator.Emitters; | ||
|
||
static partial class BindingSyntaxFactory { | ||
|
||
internal static (string? Getter, string? Setter) GetObjCMessageSendMethods (in Property property, | ||
bool isSuper = false, bool isStret = false) | ||
{ | ||
if (property.IsProperty) { | ||
// the getter and the setter depend of the accessors that have been set for the property, we do not want | ||
// to calculate things that we won't use. The export data used will also depend if the getter/setter has a | ||
// export attribute attached | ||
var getter = property.GetAccessor (AccessorKind.Getter); | ||
string? getterMsgSend = null; | ||
if (getter is not null) { | ||
var getterExportData = getter.Value.ExportPropertyData ?? property.ExportPropertyData; | ||
if (getterExportData is not null) { | ||
getterMsgSend = GetObjCMessageSendMethodName (getterExportData.Value, property.ReturnType, [], | ||
isSuper, isStret); | ||
} | ||
} | ||
|
||
var setter = property.GetAccessor (AccessorKind.Setter); | ||
string? setterMsgSend = null; | ||
if (setter is not null) { | ||
var setterExportData = setter.Value.ExportPropertyData ?? property.ExportPropertyData; | ||
if (setterExportData is not null) { | ||
setterMsgSend = GetObjCMessageSendMethodName (setterExportData.Value, TypeInfo.Void, | ||
[property.ValueParameter], isSuper, isStret); | ||
} | ||
} | ||
|
||
return (Getter: getterMsgSend, Setter: setterMsgSend); | ||
} | ||
|
||
return default; | ||
} | ||
|
||
internal static PropertyInvocations GetInvocations (in Property property) | ||
{ | ||
return new () { | ||
Getter = (ThrowNotImplementedException (), ThrowNotImplementedException ()), | ||
Setter = (ThrowNotImplementedException (), ThrowNotImplementedException ()), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/rgen/Microsoft.Macios.Generator/Emitters/PropertyInvocations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Microsoft.Macios.Generator.Emitters; | ||
|
||
/// <summary> | ||
/// Represents all the invocations of a property. | ||
/// </summary> | ||
readonly record struct PropertyInvocations { | ||
|
||
/// <summary> | ||
/// Invocations for the getter. | ||
/// </summary> | ||
public (StatementSyntax Send, StatementSyntax SendSuper) Getter { get; init; } | ||
|
||
/// <summary> | ||
/// Invocations for the setter. | ||
/// </summary> | ||
public (StatementSyntax Send, StatementSyntax SendSuper) Setter { get; init; } | ||
} |