-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codegen and building improvements (#13)
codegen, diagnostics, linking and post processing improvements
- Loading branch information
Showing
172 changed files
with
1,601 additions
and
1,212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
<Project> | ||
<ItemGroup> | ||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" /> | ||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.3.2" /> | ||
|
||
<PackageVersion Include="Docfx.App" Version="2.77.0" /> | ||
<PackageVersion Include="BenchmarkDotNet" Version="0.13.13-nightly.20240601.156" /> | ||
|
||
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" /> | ||
|
||
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" /> | ||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" /> | ||
|
||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
|
||
<PackageVersion Include="xunit" Version="2.9.0" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> | ||
<PackageVersion Include="Avalonia" Version="11.1.0" /> | ||
<PackageVersion Include="Avalonia.Desktop" Version="11.1.0" /> | ||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.0.11" /> | ||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.1.0" /> | ||
<PackageVersion Include="Semi.Avalonia" Version="11.1.0-rc2.1" /> | ||
<PackageVersion Include="Irihi.Ursa" Version="1.0.0-rc1" /> | ||
<PackageVersion Include="Irihi.Ursa.Themes.Semi" Version="1.0.0-rc1" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" | ||
PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> | ||
|
||
<PackageVersion Include="Avalonia" Version="11.1.3" /> | ||
<PackageVersion Include="Avalonia.Desktop" Version="11.1.3" /> | ||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.1.3" /> | ||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.1.3" /> | ||
|
||
<PackageVersion Include="Semi.Avalonia" Version="11.1.0.4" /> | ||
<PackageVersion Include="Irihi.Ursa" Version="1.3.0" /> | ||
<PackageVersion Include="Irihi.Ursa.Themes.Semi" Version="1.3.0" /> | ||
</ItemGroup> | ||
</Project> | ||
</Project> |
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 |
---|---|---|
@@ -1,6 +1,47 @@ | ||
using System.Text; | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Arinc424.Generators; | ||
|
||
using static Constants; | ||
|
||
[Generator] | ||
public class CharGenerator() : ConverterGenerator(Constants.CharAttribute); | ||
public class CharGenerator : ConverterGenerator | ||
{ | ||
private protected override StringBuilder WriteTarget(StringBuilder builder, BaseTarget target) | ||
{ | ||
var (members, blank) = ((Target)target).GetMembersWithBlank(); | ||
|
||
_ = builder.Append($@" | ||
public static bool TryConvert({CharArg}, out {target.Symbol.Name} value) | ||
{{ | ||
switch ({Char}) | ||
{{ | ||
case (char)32: | ||
value = {blank}; return true;"); | ||
|
||
foreach (var member in members) | ||
{ | ||
var (name, argument) = member; | ||
|
||
_ = builder.Append($@" | ||
case {argument}: | ||
value = {name}; return true;"); | ||
} | ||
return builder.Append(@$" | ||
default: | ||
value = {target.Unknown}; return false; | ||
}}").Append($@" | ||
}}"); | ||
} | ||
|
||
private protected override bool IsMatch(EnumDeclarationSyntax @enum) => @enum.HaveAttribute(CharAttribute); | ||
|
||
public CharGenerator() | ||
{ | ||
@base = CharConverter; | ||
qualifier = CharAttributeQualifier; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Text; | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Arinc424.Generators; | ||
|
||
using static Constants; | ||
|
||
[Generator] | ||
public class FlagsGenerator : ConverterGenerator | ||
{ | ||
private protected override StringBuilder WriteTarget(StringBuilder builder, BaseTarget target) | ||
{ | ||
_ = builder.Append($@" | ||
public static Result<{target.Symbol.Name}> Convert({StringArg}) | ||
{{ | ||
bool valid = true; | ||
var value = {target.Unknown};").Append("\n"); | ||
|
||
var offsetMembers = ((FlagsTarget)target).GetMembersWithBlank(); | ||
|
||
string[] charDeclarations = new string[offsetMembers.Length]; | ||
|
||
for (int i = 0; i < offsetMembers.Length; i++) | ||
charDeclarations[i] = $"{Char}{i} = {String}[{i}]"; | ||
|
||
_ = builder.Append($@" | ||
char {string.Join(", ", charDeclarations)};").Append("\n"); | ||
|
||
for (int i = 0; i < offsetMembers.Length; i++) | ||
{ | ||
_ = builder.Append(@$" | ||
switch ({Char}{i}) | ||
{{"); | ||
|
||
var (members, blank) = offsetMembers[i]; | ||
|
||
_ = builder.Append(@$" | ||
case (char)32: | ||
value |= {blank}; break;"); | ||
|
||
foreach (var member in members) | ||
{ | ||
var (fullName, argument) = member; | ||
|
||
_ = builder.Append($@" | ||
case {argument}: | ||
value |= {fullName}; break;"); | ||
} | ||
_ = builder.Append(@$" | ||
default: | ||
valid = false; break; | ||
}}"); | ||
} | ||
return builder.Append($@" | ||
return valid ? value : {String}; | ||
}}"); | ||
} | ||
|
||
private protected override BaseTarget CreateTarget(GeneratorAttributeSyntaxContext context, CancellationToken _) | ||
{ | ||
var enumSyntax = (EnumDeclarationSyntax)context.TargetNode; | ||
|
||
var symbol = (INamedTypeSymbol)context.TargetSymbol; | ||
|
||
List<Member> members = []; | ||
List<Member[]> offsetMembers = []; | ||
|
||
foreach (var member in enumSyntax.Members) | ||
{ | ||
if (member.HaveAttribute(OffsetAttribute)) | ||
{ | ||
offsetMembers.Add([.. members]); | ||
members = []; | ||
} | ||
|
||
if (member.TryAttribute(MapAttribute, out var attribute)) | ||
members.Add(new($"{symbol.Name}.{member.Identifier}", attribute!.ArgumentList?.Arguments.First().ToString() ?? string.Empty)); | ||
} | ||
offsetMembers.Add([.. members]); | ||
|
||
return new FlagsTarget((INamedTypeSymbol)context.TargetSymbol, [.. offsetMembers]); | ||
} | ||
|
||
private protected override bool IsMatch(EnumDeclarationSyntax @enum) => @enum.HaveAttribute(FlagsAttribute); | ||
|
||
public FlagsGenerator() | ||
{ | ||
@base = StringConverter; | ||
qualifier = StringAttributeQualifier; | ||
} | ||
} |
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.