DeviceDependentGenerator added to tasks.json. It can now generate the files during VS Code builds. Ignore list updated.
This commit is contained in:
1 parent
af7c9491e4
commit
8ea975f2ed
4 files changed
+71
-5
No files matched your search
@@ -18,3 +18,5 @@ PerfectNumbers.Core.Tests/bin/*
|
|||||||
PerfectNumbers.Core.Tests/obj/*
|
PerfectNumbers.Core.Tests/obj/*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vs/*
|
.vs/*
|
||||||
|
*.generated.cs
|
||||||
|
PerfectNumbers.Core/generated/*
|
||||||
Vendored
+4
-2
@@ -11,7 +11,8 @@
|
|||||||
"--configuration",
|
"--configuration",
|
||||||
"Debug",
|
"Debug",
|
||||||
"--framework",
|
"--framework",
|
||||||
"net8.0"
|
"net8.0",
|
||||||
|
"/p:DeviceDependentGenerator_CopyGeneratedToProjectDir=true"
|
||||||
],
|
],
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
@@ -29,7 +30,8 @@
|
|||||||
"--configuration",
|
"--configuration",
|
||||||
"Release",
|
"Release",
|
||||||
"--framework",
|
"--framework",
|
||||||
"net8.0"
|
"net8.0",
|
||||||
|
"/p:DeviceDependentGenerator_CopyGeneratedToProjectDir=true"
|
||||||
],
|
],
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
|
|||||||
@@ -54,9 +54,12 @@ public sealed class DeviceDependentGenerator : IIncrementalGenerator
|
|||||||
IncrementalValueProvider<GeneratorOptions> options = context.AnalyzerConfigOptionsProvider.Select(
|
IncrementalValueProvider<GeneratorOptions> options = context.AnalyzerConfigOptionsProvider.Select(
|
||||||
static (provider, _) => new GeneratorOptions(provider.GlobalOptions));
|
static (provider, _) => new GeneratorOptions(provider.GlobalOptions));
|
||||||
|
|
||||||
context.RegisterSourceOutput(templates.Combine(options), static (productionContext, pair) =>
|
IncrementalValueProvider<(Compilation Compilation, GeneratorOptions Options)> compilationAndOptions =
|
||||||
|
context.CompilationProvider.Combine(options).Select(static (pair, _) => (pair.Left, pair.Right));
|
||||||
|
|
||||||
|
context.RegisterSourceOutput(templates.Combine(compilationAndOptions), static (productionContext, pair) =>
|
||||||
{
|
{
|
||||||
GenerateForTemplate(productionContext, pair.Left, pair.Right);
|
GenerateForTemplate(productionContext, pair.Left, pair.Right.Compilation, pair.Right.Options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +122,7 @@ public sealed class DeviceDependentGenerator : IIncrementalGenerator
|
|||||||
return TemplateInfo.CreateValid(templateSymbol, enumTypeSymbol, attributeLocation, enumValues, suffix);
|
return TemplateInfo.CreateValid(templateSymbol, enumTypeSymbol, attributeLocation, enumValues, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GenerateForTemplate(SourceProductionContext context, TemplateInfo template, GeneratorOptions options)
|
private static void GenerateForTemplate(SourceProductionContext context, TemplateInfo template, Compilation compilation, GeneratorOptions options)
|
||||||
{
|
{
|
||||||
if (!template.Valid)
|
if (!template.Valid)
|
||||||
{
|
{
|
||||||
@@ -146,6 +149,7 @@ public sealed class DeviceDependentGenerator : IIncrementalGenerator
|
|||||||
SourceText fileText = templateSyntax.SyntaxTree.GetText(context.CancellationToken);
|
SourceText fileText = templateSyntax.SyntaxTree.GetText(context.CancellationToken);
|
||||||
string filePath = templateSyntax.SyntaxTree.FilePath;
|
string filePath = templateSyntax.SyntaxTree.FilePath;
|
||||||
CSharpParseOptions baseParseOptions = (CSharpParseOptions)templateSyntax.SyntaxTree.Options;
|
CSharpParseOptions baseParseOptions = (CSharpParseOptions)templateSyntax.SyntaxTree.Options;
|
||||||
|
SyntaxTree originalTree = templateSyntax.SyntaxTree;
|
||||||
|
|
||||||
foreach (string enumValueName in template.EnumValues)
|
foreach (string enumValueName in template.EnumValues)
|
||||||
{
|
{
|
||||||
@@ -166,6 +170,8 @@ public sealed class DeviceDependentGenerator : IIncrementalGenerator
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReportDeviceSpecificTemplateErrors(context, compilation, originalTree, deviceTree, templateSyntax.Identifier.GetLocation(), enumValueName);
|
||||||
|
|
||||||
string generatedTypeName = baseName + enumValueName + template.Suffix;
|
string generatedTypeName = baseName + enumValueName + template.Suffix;
|
||||||
TypeDeclarationSyntax generatedTypeSyntax = TransformTemplateType(deviceTemplateSyntax, generatedTypeName);
|
TypeDeclarationSyntax generatedTypeSyntax = TransformTemplateType(deviceTemplateSyntax, generatedTypeName);
|
||||||
|
|
||||||
@@ -186,6 +192,45 @@ public sealed class DeviceDependentGenerator : IIncrementalGenerator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ReportDeviceSpecificTemplateErrors(
|
||||||
|
SourceProductionContext context,
|
||||||
|
Compilation compilation,
|
||||||
|
SyntaxTree originalTree,
|
||||||
|
SyntaxTree deviceTree,
|
||||||
|
Location fallbackLocation,
|
||||||
|
string enumValueName)
|
||||||
|
{
|
||||||
|
foreach (Diagnostic diagnostic in deviceTree.GetDiagnostics(context.CancellationToken))
|
||||||
|
{
|
||||||
|
if (diagnostic.Severity == DiagnosticSeverity.Error)
|
||||||
|
{
|
||||||
|
context.ReportDiagnostic(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compilation is not CSharpCompilation csharpCompilation)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSharpCompilation deviceCompilation = csharpCompilation.ReplaceSyntaxTree(originalTree, deviceTree);
|
||||||
|
foreach (Diagnostic diagnostic in deviceCompilation.GetDiagnostics(context.CancellationToken))
|
||||||
|
{
|
||||||
|
if (diagnostic.Severity != DiagnosticSeverity.Error)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (diagnostic.Location is { Kind: LocationKind.SourceFile } location
|
||||||
|
&& location.SourceTree != deviceTree)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.ReportDiagnostic(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsTopLevel(TypeDeclarationSyntax typeDeclaration)
|
private static bool IsTopLevel(TypeDeclarationSyntax typeDeclaration)
|
||||||
=> typeDeclaration.Parent is NamespaceDeclarationSyntax
|
=> typeDeclaration.Parent is NamespaceDeclarationSyntax
|
||||||
|| typeDeclaration.Parent is FileScopedNamespaceDeclarationSyntax
|
|| typeDeclaration.Parent is FileScopedNamespaceDeclarationSyntax
|
||||||
|
|||||||
@@ -5,8 +5,14 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>12.0</LangVersion>
|
<LangVersion>12.0</LangVersion>
|
||||||
|
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
||||||
|
<CompilerGeneratedFilesOutputPath>$(IntermediateOutputPath)generated</CompilerGeneratedFilesOutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="**/*.generated.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="PeterO.Numbers" Version="1.8.1" />
|
<PackageReference Include="PeterO.Numbers" Version="1.8.1" />
|
||||||
<PackageReference Include="Open.Numeric.Primes" Version="4.0.4" />
|
<PackageReference Include="Open.Numeric.Primes" Version="4.0.4" />
|
||||||
@@ -28,4 +34,15 @@
|
|||||||
<InternalsVisibleTo Include="EvenPerfectBitScanner.Benchmarks" />
|
<InternalsVisibleTo Include="EvenPerfectBitScanner.Benchmarks" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="CopyDeviceDependentGeneratedToProjectDir"
|
||||||
|
AfterTargets="CoreCompile"
|
||||||
|
Condition="'$(DeviceDependentGenerator_CopyGeneratedToProjectDir)' == 'true' Or '$(BuildingInsideVisualStudio)' == 'true'">
|
||||||
|
<ItemGroup>
|
||||||
|
<_DeviceDependentGeneratedFiles Include="$(CompilerGeneratedFilesOutputPath)\DeviceDependentGenerator\PerfectNumbers.Core.Generators.DeviceDependentGenerator\**\*.generated.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Copy SourceFiles="@(_DeviceDependentGeneratedFiles)"
|
||||||
|
DestinationFiles="@(_DeviceDependentGeneratedFiles->'$(ProjectDir)%(RecursiveDir)%(Filename)%(Extension)')"
|
||||||
|
SkipUnchangedFiles="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in new issue
Block a user