Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<!-- <PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="5.0.0" /> -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.202" />
<PackageVersion Include="N.SourceGenerators.UnionTypes" Version="0.28.2" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.9.50" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\UnionAttribute.cs" Link="System\Runtime\CompilerServices\UnionAttribute.cs" />
<None Include="$(MSBuildThisFileDirectory)images\icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions src/System/Runtime/CompilerServices/UnionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace System.Runtime.CompilerServices;

/// <summary>
/// Marks a type as a C# union.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)]
public sealed class UnionAttribute : Attribute;
8 changes: 4 additions & 4 deletions src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ bool IsValidParameter(ParameterSyntax ps, int i)
var extra = ProcessTrivia(leading, ds);
if (extra is not null && extra.AdditionalStatements.Count > 0)
{
modifications.Add(i, new List<StatementSyntax>(extra.AdditionalStatements));
modifications.Add(i + 1, true);
modifications.Add(i, new Operation([.. extra.AdditionalStatements]));
modifications.Add(i + 1, new Operation(true));
}

if (semanticModel.GetDeclaredSymbol(ps) is not { } symbol)
Expand Down Expand Up @@ -1074,8 +1074,8 @@ bool ShouldRemoveArgumentLocal(ArgumentSyntax arg, int index)

if (extra is { AdditionalStatements.Count: > 0 })
{
modifications.Add(index, new List<StatementSyntax>(extra.AdditionalStatements));
modifications.Add(index + 1, true);
modifications.Add(index, new Operation([.. extra.AdditionalStatements]));
modifications.Add(index + 1, new Operation(true));
}

if (byExpression || nullableParameters is not { } parameters)
Expand Down
40 changes: 37 additions & 3 deletions src/Zomp.SyncMethodGenerator/Operation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
namespace Zomp.SyncMethodGenerator;

[N.SourceGenerators.UnionTypes.UnionType(typeof(List<StatementSyntax>), "NewStatements")]
[N.SourceGenerators.UnionTypes.UnionType(typeof(bool), "RemoveLeadingEndIf")]
internal sealed partial class Operation
/// <summary>
/// Represents a sync-only operation.
/// </summary>
[Union]
internal readonly struct Operation
{
/// <summary>
/// Initializes a new instance of the <see cref="Operation"/> struct.
/// </summary>
/// <param name="value">The new statements to insert.</param>
public Operation(List<StatementSyntax> value)
{
Value = value;
}

/// <summary>
/// Initializes a new instance of the <see cref="Operation"/> struct.
/// </summary>
/// <param name="value">A value indicating whether to remove the leading end-if directive.</param>
public Operation(bool value)
{
Value = value;
}

/// <summary>
/// Gets the active operation value.
/// </summary>
public object? Value { get; }

/// <summary>
/// Gets a value indicating whether the operation inserts new statements.
/// </summary>
public bool IsNewStatements => Value is List<StatementSyntax>;

/// <summary>
/// Gets the operation value as new statements.
/// </summary>
public List<StatementSyntax> AsNewStatements => (List<StatementSyntax>)Value!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.Bcl.HashCode" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" Pack="false" />
<PackageReference Include="N.SourceGenerators.UnionTypes" PrivateAssets="all" Pack="false" />
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
<PackageReference Include="PolySharp" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<!-- <PackageReference Include="Microsoft.Net.Compilers.Toolset" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> -->
Expand Down
Loading