-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rgen] Provide a data model to make the code generator more performan…
…t. (#21517) In order to fully take advantage of the [caching](https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md#caching) provided by the incremental code generator infrastructure we move to use a data model that will represent the code changes that will trigger a regeneration of certain classes. The current implementation only takes care of the changes that will trigger a regeneration on enums: 1. Enum fully qualified name changed. 2. Attributes added or removed in the enum. 2. Enum values added/removed. We provide our own Comparer to have more control on how the structures are compared. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]> Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
- Loading branch information
1 parent
f11253b
commit d51fa94
Showing
43 changed files
with
1,907 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
#nullable enable | ||
|
||
namespace ObjCBindings { | ||
|
||
/// <summary> | ||
/// Generic attribute that is used to mark code to be backed by a field in ObjC. | ||
/// </summary> | ||
[Experimental ("APL0003")] | ||
[AttributeUsage (AttributeTargets.Property | AttributeTargets.Field)] | ||
public sealed class FieldAttribute<T> : Attribute where T : FieldTag { | ||
|
||
/// <summary> | ||
/// Create a new FieldAttribute for the given symbol and using the namespace as its containing library. | ||
/// <param name="symbolName">The name of the symbol.</param> | ||
/// </summary> | ||
public FieldAttribute (string symbolName) | ||
{ | ||
SymbolName = symbolName; | ||
} | ||
|
||
/// <summary> | ||
/// Create a new FieldAttribute for the given symbol in the provided library. | ||
/// <param name="symbolName">The name of the symbol.</param> | ||
/// <param name="libraryName">The name of the library that contains the symbol.</param> | ||
/// </summary> | ||
public FieldAttribute (string symbolName, string libraryName) | ||
{ | ||
SymbolName = symbolName; | ||
LibraryName = libraryName; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Get/Set the symbol represented by the attribute. | ||
/// </summary> | ||
public string SymbolName { get; set; } | ||
|
||
/// <summary> | ||
/// Get/Set the library that contains the symbol.. | ||
/// </summary> | ||
public string? LibraryName { get; set; } | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
#nullable enable | ||
|
||
namespace ObjCBindings { | ||
|
||
/// <summary> | ||
/// Base class use to flag a FieldAttribute usage. Each FieldAttribute must have a flag attached to it so that the | ||
/// binding generator analyzer can verify the binding definition. | ||
/// </summary> | ||
[Experimental ("APL0003")] | ||
public abstract class FieldTag { } | ||
|
||
/// <summary> | ||
/// Field flag that states that the field is used as a Enum value. | ||
/// </summary> | ||
[Experimental ("APL0003")] | ||
public sealed class EnumValue : FieldTag { } | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/rgen/Microsoft.Macios.Generator/Attributes/FieldData.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 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Microsoft.Macios.Generator.Attributes; | ||
|
||
record FieldData { | ||
public string SymbolName { get; } | ||
public string? LibraryName { get; private set; } | ||
|
||
FieldData (string symbolName, string? libraryName = null) | ||
{ | ||
SymbolName = symbolName; | ||
LibraryName = libraryName; | ||
} | ||
|
||
public static bool TryParse (SyntaxNode attributeSyntax, AttributeData attributeData, | ||
[NotNullWhen (true)] out FieldData? data) | ||
{ | ||
data = default; | ||
|
||
var count = attributeData.ConstructorArguments.Length; | ||
switch (count) { | ||
case 1: | ||
data = new ((string) attributeData.ConstructorArguments [0].Value!); | ||
break; | ||
case 2: | ||
data = new ((string) attributeData.ConstructorArguments [0].Value!, | ||
(string) attributeData.ConstructorArguments [1].Value!); | ||
break; | ||
default: | ||
// 0 should not be an option.. | ||
return false; | ||
} | ||
|
||
if (attributeData.NamedArguments.Length == 0) | ||
return true; | ||
|
||
// LibraryName can be a param value | ||
foreach (var (name, value) in attributeData.NamedArguments) { | ||
switch (name) { | ||
case "LibraryName": | ||
data.LibraryName = (string?) value.Value!; | ||
break; | ||
default: | ||
data = null; | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.