-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rgen] Add the missing code to complety the property datamodel in the…
… transformer. Add the missing methods to be able to correcly parse a property and store it in the data model. This change adds support for Fields and Properties.
- Loading branch information
1 parent
aa4e62c
commit 8826755
Showing
13 changed files
with
628 additions
and
107 deletions.
There are no files selected for viewing
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
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
41 changes: 39 additions & 2 deletions
41
src/rgen/Microsoft.Macios.Transformer/DataModel/Accessor.Transformer.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 |
---|---|---|
@@ -1,13 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Macios.Generator.Availability; | ||
using Microsoft.Macios.Transformer.Attributes; | ||
|
||
namespace Microsoft.Macios.Generator.DataModel; | ||
|
||
readonly partial struct Accessor { | ||
|
||
public ExportData? ExportPropertyData { get; init; } | ||
readonly ExportData? overrideExportData; | ||
|
||
public Accessor () { } | ||
/// <summary> | ||
/// The data of the field attribute used to mark the value as a property binding. | ||
/// </summary> | ||
public ExportData? ExportPropertyData { | ||
get => overrideExportData ?? ExportAttribute; | ||
init => overrideExportData = value; | ||
} | ||
|
||
/// <summary> | ||
/// State if we should marshal native exceptions when generating the accessor. | ||
/// </summary> | ||
public bool MarshalNativeExceptions => HasMarshalNativeExceptionsFlag; | ||
|
||
public Accessor (AccessorKind accessorKind, | ||
SymbolAvailability symbolAvailability, | ||
Dictionary<string, List<AttributeData>> attributes) | ||
{ | ||
Kind = accessorKind; | ||
SymbolAvailability = symbolAvailability; | ||
AttributesDictionary = attributes; | ||
|
||
// we trust the modifiers of the property itself | ||
Modifiers = []; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString () | ||
{ | ||
var sb = new StringBuilder ($"{{ Kind: {Kind}, "); | ||
sb.Append ($"Supported Platforms: {SymbolAvailability}, "); | ||
sb.Append ($"ExportData: {ExportPropertyData?.ToString () ?? "null"} Modifiers: ["); | ||
sb.AppendJoin (",", Modifiers.Select (x => x.Text)); | ||
sb.Append ("] }"); | ||
return sb.ToString (); | ||
} | ||
} |
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
109 changes: 109 additions & 0 deletions
109
src/rgen/Microsoft.Macios.Transformer/DataModel/ModifiersFlags.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,109 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; | ||
|
||
namespace Microsoft.Macios.Generator.DataModel; | ||
|
||
/// <summary> | ||
/// Helper class to store the modifiers flags. It also provides a method that will | ||
/// return the correct modifiers according to the flags; | ||
/// </summary> | ||
readonly record struct ModifiersFlags { | ||
|
||
public bool HasAbstractFlag { get; } | ||
public bool HasInternalFlag { get; } | ||
public bool HasNewFlag { get; } | ||
public bool HasOverrideFlag { get; } | ||
public bool HasStaticFlag { get; } | ||
|
||
/// <summary> | ||
/// Create a new structure with the provided flags. | ||
/// </summary> | ||
/// <param name="hasAbstractFlag">The state of the abstract flag.</param> | ||
/// <param name="hasInternalFlag">The state of the internal flag.</param> | ||
/// <param name="hasNewFlag">The state of the new flag.</param> | ||
/// <param name="hasOverrideFlag">The state of the override flag.</param> | ||
/// <param name="hasStaticFlag">The state of the static flag.</param> | ||
public ModifiersFlags (bool hasAbstractFlag, bool hasInternalFlag, bool hasNewFlag, bool hasOverrideFlag, bool hasStaticFlag) | ||
{ | ||
HasAbstractFlag = hasAbstractFlag; | ||
HasInternalFlag = hasInternalFlag; | ||
HasNewFlag = hasNewFlag; | ||
HasOverrideFlag = hasOverrideFlag; | ||
HasStaticFlag = hasStaticFlag; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the list of modifiers to be used with the provided set of flags. | ||
/// </summary> | ||
/// <returns>The list of modifiers to use to write the transformed method/property.</returns> | ||
public ImmutableArray<SyntaxToken> ToModifiersArray () | ||
{ | ||
#pragma warning disable format | ||
// Modifiers are special because we might be dealing with several flags that the user has set in the method. | ||
// We have to add the partial keyword so that we can have the partial implementation of the method later generated | ||
// by the roslyn code generator | ||
return this switch { | ||
// internal static partial | ||
{ HasNewFlag: false, HasStaticFlag: true, HasInternalFlag: true } | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// public static partial | ||
{ HasNewFlag: false, HasStaticFlag: true, HasInternalFlag: false } | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// internal new static partial | ||
{ HasNewFlag: true, HasStaticFlag: true, HasInternalFlag: true} | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// public new static partial | ||
{ HasNewFlag: true, HasStaticFlag: true, HasInternalFlag: false } | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.StaticKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// public new virtual partial | ||
{ HasNewFlag: true, HasStaticFlag: false, HasAbstractFlag: false, HasInternalFlag: false } | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.VirtualKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// internal new virtual partial | ||
{ HasNewFlag: true, HasStaticFlag: false, HasAbstractFlag: false, HasInternalFlag: true } | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.VirtualKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// public new abstract | ||
{ HasNewFlag: true, HasAbstractFlag: true, HasInternalFlag: false} | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.AbstractKeyword)], | ||
|
||
// internal new abstract | ||
{ HasNewFlag: true, HasAbstractFlag: true, HasInternalFlag: true} | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.NewKeyword), Token (SyntaxKind.AbstractKeyword)], | ||
|
||
// public override partial | ||
{ HasNewFlag: false, HasOverrideFlag: true, HasInternalFlag: false} | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.OverrideKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// internal override partial | ||
{ HasNewFlag: false, HasOverrideFlag: true, HasInternalFlag: true} | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.OverrideKeyword), Token (SyntaxKind.PartialKeyword)], | ||
|
||
// public abstract | ||
{ HasAbstractFlag: true, HasInternalFlag: false} | ||
=> [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.AbstractKeyword)], | ||
|
||
// internal abstract | ||
{ HasAbstractFlag: true, HasInternalFlag: true} | ||
=> [Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.AbstractKeyword)], | ||
|
||
// general case, but internal | ||
{ HasInternalFlag: true} => | ||
[Token (SyntaxKind.InternalKeyword), Token (SyntaxKind.VirtualKeyword), Token (SyntaxKind.VirtualKeyword)], | ||
|
||
// general case | ||
_ => [Token (SyntaxKind.PublicKeyword), Token (SyntaxKind.VirtualKeyword), Token (SyntaxKind.PartialKeyword)] | ||
}; | ||
#pragma warning restore format | ||
} | ||
|
||
} |
Oops, something went wrong.