-
Notifications
You must be signed in to change notification settings - Fork 548
[RGen] Use the PlatformSupportVersion for the supported and unsupported versions. #23842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mandel-macaque
wants to merge
7
commits into
main
Choose a base branch
from
dev/mandel/platform-availability-kind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−48
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14ac3c9
[RGen] Add a new type to track versions.
mandel-macaque 382ee7e
Auto-format source code
46eb2d3
[RGen] Use the new PlatformSupportVersion in the builder.
mandel-macaque ec61da7
Auto-format source code
ef44958
[RGen] Use the PlatformSupportVersion for the supported and unsupport…
mandel-macaque 47f3c28
Auto-format source code
06314f8
Merge branch 'main' into dev/mandel/platform-availability-kind
mandel-macaque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
149 changes: 149 additions & 0 deletions
149
src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs
This file contains hidden or 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,149 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Macios.Generator.Availability; | ||
|
||
/// <summary> | ||
/// Represents a platform support version, combining a version number and a support kind. | ||
/// </summary> | ||
public readonly record struct PlatformSupportVersion : IComparable<PlatformSupportVersion> { | ||
/// <summary> | ||
/// Gets the version number. | ||
/// </summary> | ||
public Version Version { get; init; } | ||
/// <summary> | ||
/// Gets the kind of support (e.g., explicit, implicit). | ||
/// </summary> | ||
public SupportKind Kind { get; init; } | ||
|
||
/// <summary> | ||
/// Gets a default platform support version with an implicit kind. | ||
/// </summary> | ||
public static PlatformSupportVersion ImplicitDefault { get; } = new () { | ||
Version = new (), | ||
Kind = SupportKind.Implicit | ||
}; | ||
|
||
/// <summary> | ||
/// Gets a default platform support version with an explicit kind. | ||
/// </summary> | ||
public static PlatformSupportVersion ExplicitDefault { get; } = new () { | ||
Version = new (), | ||
Kind = SupportKind.Explicit | ||
}; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlatformSupportVersion"/> struct. | ||
/// </summary> | ||
/// <param name="version">The version number.</param> | ||
/// <param name="kind">The kind of support.</param> | ||
public PlatformSupportVersion (Version version, SupportKind kind) | ||
{ | ||
Version = version; | ||
Kind = kind; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PlatformSupportVersion"/> struct with an explicit support kind. | ||
/// </summary> | ||
/// <param name="version">The version number.</param> | ||
public PlatformSupportVersion (Version version) : this (version, SupportKind.Explicit) { } | ||
|
||
/// <summary> | ||
/// Returns the platform support version with the highest precedence. | ||
/// </summary> | ||
/// <param name="v1">The first platform support version to compare.</param> | ||
/// <param name="v2">The second platform support version to compare.</param> | ||
/// <returns> | ||
/// The platform support version with the highest precedence. If the kinds are the same, it returns the one with the greater version. | ||
/// If the kinds are different, it returns the one with the higher kind value. | ||
/// </returns> | ||
public static PlatformSupportVersion? Max (PlatformSupportVersion? v1, PlatformSupportVersion? v2) | ||
{ | ||
if (v1 is null) | ||
return v2; | ||
if (v2 is null) | ||
return v1; | ||
|
||
if (v1.Value.Kind == v2.Value.Kind) { | ||
return v1.Value.Version >= v2.Value.Version ? v1 : v2; | ||
} | ||
return (int) v1.Value.Kind > (int) v2.Value.Kind ? v1 : v2; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the platform support version with the lowest version if the kinds are the same, otherwise returns the one with the highest precedence kind. | ||
/// </summary> | ||
/// <param name="v1">The first platform support version to compare.</param> | ||
/// <param name="v2">The second platform support version to compare.</param> | ||
/// <returns> | ||
/// The platform support version with the lowest version if the kinds are the same. | ||
/// If the kinds are different, it returns the one with the higher kind value. | ||
/// </returns> | ||
public static PlatformSupportVersion? Min (PlatformSupportVersion? v1, PlatformSupportVersion? v2) | ||
{ | ||
if (v1 is null) | ||
return v2; | ||
if (v2 is null) | ||
return v1; | ||
if (v1.Value.Kind == v2.Value.Kind) { | ||
return v1.Value.Version <= v2.Value.Version ? v1 : v2; | ||
} | ||
return (int) v1.Value.Kind > (int) v2.Value.Kind ? v1 : v2; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public int CompareTo(PlatformSupportVersion other) | ||
{ | ||
var versionComparison = Version.CompareTo (other.Version); | ||
if (versionComparison != 0) | ||
return versionComparison; | ||
return Kind.CompareTo (other.Kind); | ||
} | ||
|
||
/// <summary> | ||
/// Compares two <see cref="PlatformSupportVersion"/> instances to determine if the left is less than the right. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <param name="right">The second <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <returns><c>true</c> if the left instance is less than the right instance; otherwise, <c>false</c>.</returns> | ||
public static bool operator <(PlatformSupportVersion left, PlatformSupportVersion right) | ||
{ | ||
return left.CompareTo (right) < 0; | ||
} | ||
|
||
/// <summary> | ||
/// Compares two <see cref="PlatformSupportVersion"/> instances to determine if the left is greater than the right. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <param name="right">The second <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <returns><c>true</c> if the left instance is greater than the right instance; otherwise, <c>false</c>.</returns> | ||
public static bool operator >(PlatformSupportVersion left, PlatformSupportVersion right) | ||
{ | ||
return left.CompareTo (right) > 0; | ||
} | ||
|
||
/// <summary> | ||
/// Compares two <see cref="PlatformSupportVersion"/> instances to determine if the left is less than or equal to the right. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <param name="right">The second <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <returns><c>true</c> if the left instance is less than or equal to the right instance; otherwise, <c>false</c>.</returns> | ||
public static bool operator <=(PlatformSupportVersion left, PlatformSupportVersion right) | ||
{ | ||
return left.CompareTo (right) <= 0; | ||
} | ||
|
||
/// <summary> | ||
/// Compares two <see cref="PlatformSupportVersion"/> instances to determine if the left is greater than or equal to the right. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <param name="right">The second <see cref="PlatformSupportVersion"/> to compare.</param> | ||
/// <returns><c>true</c> if the left instance is greater than or equal to the right instance; otherwise, <c>false</c>.</returns> | ||
public static bool operator >=(PlatformSupportVersion left, PlatformSupportVersion right) | ||
{ | ||
return left.CompareTo(right) >= 0; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs
This file contains hidden or 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,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Macios.Generator.Availability; | ||
|
||
/// <summary> | ||
/// Compares two <see cref="PlatformSupportVersion"/> instances for sorting. | ||
/// </summary> | ||
public class PlatformSupportVersionComparer : IComparer<PlatformSupportVersion> { | ||
|
||
/// <summary> | ||
/// Compares two platform support versions and returns a value indicating whether one is less than, equal to, or greater than the other. | ||
/// </summary> | ||
/// <param name="x">The first object to compare.</param> | ||
/// <param name="y">The second object to compare.</param> | ||
/// <returns>A signed integer that indicates the relative values of x and y.</returns> | ||
public int Compare (PlatformSupportVersion x, PlatformSupportVersion y) | ||
{ | ||
int versionComparison = x.Version.CompareTo (y.Version); | ||
if (versionComparison != 0) return versionComparison; | ||
return x.Kind.CompareTo (y.Kind); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/rgen/Microsoft.Macios.Generator/Availability/SupportKind.cs
This file contains hidden or 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,9 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.Macios.Generator.Availability; | ||
|
||
public enum SupportKind { | ||
Implicit, | ||
Explicit | ||
} |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around method call parentheses. Should be
left.CompareTo (right)
to match the pattern used in other comparison operators in this file.Copilot uses AI. Check for mistakes.