Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyrest committed Aug 15, 2024
2 parents 72a802d + 13e69b3 commit 955c4d2
Show file tree
Hide file tree
Showing 24 changed files with 107 additions and 333 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
6.0.x
8.0.x
9.0.x
include-prerelease: true
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand All @@ -51,7 +50,6 @@ jobs:
6.0.x
8.0.x
9.0.x
include-prerelease: true
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
7.0.x
8.0.x
9.0.x
include-prerelease: true
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2022 Boring3
Copyright (c) 2020-2024 Boring3

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@
### Pre-Compiled Version

```powershell
dotnet add package FastGenericNew --version 3.1.0-preview1
dotnet add package FastGenericNew --version 3.3.0
```

```xml
<ItemGroup>
<PackageReference Include="FastGenericNew" Version="3.1.0-preview1" />
<PackageReference Include="FastGenericNew" Version="3.3.0" />
</ItemGroup>
```

### SourceGenerator Version

```powershell
dotnet add package FastGenericNew.SourceGenerator --version 3.1.0-preview1
dotnet add package FastGenericNew.SourceGenerator --version 3.3.0
```

```xml
<ItemGroup>
<PackageReference Include="FastGenericNew.SourceGenerator" Version="3.1.0-preview1" />
<PackageReference Include="FastGenericNew.SourceGenerator" Version="3.3.0" />
</ItemGroup>
```
#### SourceGeneratorV2 requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ private static void BuildSource(in SourceProductionContext context, Compilation
.ToArray();
BuildGeneratorOptionsConstructor(in context, symbolsWithAttrData);
BuildCodeBuilderPreProcessorDefinitions(in context, symbolsWithAttrData);
BuildCodeGeneratorExtraCheck(in context, symbolsWithAttrData);
}

public static void BuildGeneratorOptionsConstructor(in SourceProductionContext context, (IPropertySymbol symbol, AttributeData attrData)[] symbolsWithAttrData)
{
const string indent = " ";
StringBuilder sb = new StringBuilder("""
StringBuilder sb = new("""
#nullable enable
namespace FastGenericNew.SourceGenerator;
Expand Down Expand Up @@ -94,7 +93,7 @@ public GeneratorOptions(AnalyzerConfigOptionsProvider? provider)

public static void BuildCodeBuilderPreProcessorDefinitions(in SourceProductionContext context, (IPropertySymbol symbol, AttributeData attrData)[] symbolsWithAttrData)
{
StringBuilder sb = new StringBuilder("""
StringBuilder sb = new("""
#nullable enable
namespace FastGenericNew.SourceGenerator.Utilities;
Expand Down Expand Up @@ -124,41 +123,5 @@ private partial void _Write_PreProcessorDefinitions()
""");
context.AddSource("CodeBuilder.PreProcessor.g.cs", SourceText.From(sb.ToString(), Encoding.UTF8));
}

public static void BuildCodeGeneratorExtraCheck(in SourceProductionContext context, (IPropertySymbol symbol, AttributeData attrData)[] symbolsWithAttrData)
{
const string indent = " ";
StringBuilder sb = new StringBuilder("""
#nullable enable
namespace FastGenericNew.SourceGenerator;
partial class CodeGenerator
{
private static partial bool PreProcessorRelatedCheck(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
""", 4096);
bool isFirst = true;
foreach (var (symbol, attrData) in symbolsWithAttrData)
{
if (!attrData.TryGetNamedArgument(GeneratorOptionAttributeGenerator.Arg_PresentPreProcessor, out bool value) || !value)
continue;
var propertyName = symbol.Name;
sb.Append(indent);

if (!isFirst)
{
sb.Append("|| ");
}
else isFirst = false;
sb.AppendLine($"oldValue.{propertyName} != newValue.{propertyName}");
}
if (isFirst) sb.Append("false");
sb.Append("""
;
}
""");
context.AddSource("CodeGenerator.PreProcessorRelatedCheck.g.cs", SourceText.From(sb.ToString(), Encoding.UTF8));
}
}
}
18 changes: 10 additions & 8 deletions src/FastGenericNew.SourceGenerator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ public abstract partial class CodeGenerator
{
public abstract string Filename { get; }

public virtual bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
oldValue.Namespace != newValue.Namespace
|| oldValue.MaxParameterCount != newValue.MaxParameterCount
|| oldValue.AlertGeneratedFile != newValue.AlertGeneratedFile
|| oldValue.PrettyOutput != newValue.PrettyOutput
|| PreProcessorRelatedCheck(in oldValue, in newValue);

public abstract CodeGenerationResult Generate(in GeneratorOptions options);

private static partial bool PreProcessorRelatedCheck(in GeneratorOptions oldValue, in GeneratorOptions newValue);
public virtual GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return new GeneratorOptions() with
{
Namespace = options.Namespace,
MaxParameterCount = options.MaxParameterCount,
AlertGeneratedFile = options.AlertGeneratedFile,
PrettyOutput = options.PrettyOutput
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ public static T CreateInstance()
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue)
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.ShouldUpdate(oldValue, newValue) && newValue.AllowUnsafeImplementation;
return base.GetOptionsSubset(options) with
{
AllowUnsafeImplementation = options.AllowUnsafeImplementation,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ public static T NewOrDefault<
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue)
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.ShouldUpdate(oldValue, newValue) && newValue.GenerateCreateInstance;
return base.GetOptionsSubset(options) with
{
GenerateCreateInstance = options.GenerateCreateInstance,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
base.ShouldUpdate(oldValue, newValue)
|| oldValue.ForceFastNewDelegate != newValue.ForceFastNewDelegate;
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.GetOptionsSubset(options) with
{
ForceFastNewDelegate = options.ForceFastNewDelegate,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
base.ShouldUpdate(oldValue, newValue)
|| oldValue.ForceFastNewDelegate != newValue.ForceFastNewDelegate;
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.GetOptionsSubset(options) with
{
ForceFastNewDelegate = options.ForceFastNewDelegate,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
base.ShouldUpdate(oldValue, newValue)
|| oldValue.PublicFastNew != newValue.PublicFastNew;
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.GetOptionsSubset(options) with
{
PublicFastNew = options.PublicFastNew,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ public static bool TryNewOrDefault<
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue)
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.ShouldUpdate(oldValue, newValue) && newValue.GenerateTryCreateInstance;
return base.GetOptionsSubset(options) with
{
GenerateTryCreateInstance = options.GenerateTryCreateInstance,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public override CodeGenerationResult Generate(in GeneratorOptions options)
return builder.BuildAndDispose(this);
}

// Since this won't be invoked if the oldValue equals the newValue.
// So just do it.
public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) => newValue.OutputGenerationInfo;
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.GetOptionsSubset(options) with
{
OutputGenerationInfo = options.OutputGenerationInfo,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public static T SmartThrowImpl<T>()
return builder.BuildAndDispose(this);
}

public override bool ShouldUpdate(in GeneratorOptions oldValue, in GeneratorOptions newValue) =>
oldValue.Namespace != newValue.Namespace
|| oldValue.AlertGeneratedFile != newValue.AlertGeneratedFile;
public override GeneratorOptions GetOptionsSubset(GeneratorOptions options)
{
return base.GetOptionsSubset(options) with
{
AlertGeneratedFile = options.AlertGeneratedFile,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<PropertyGroup>
<PackageId>FastGenericNew.SourceGenerator</PackageId>
<DescriptionPrefix>
Configurable Source Generator of FastGenericNew
Minimum required: .NET Standard 2.0 &amp; C# 8.0
Configurable Source Generator
Minimum requirement: .NET Standard 2.0 &amp; C# 8.0
</DescriptionPrefix>
<PackageTagsPostfix>Roslyn, DotNetAnalyzers, Analyzer, SourceGenerator, SourceGeneratorV2, IncrementalGenerator</PackageTagsPostfix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
<CompilerVisibleProperty Include="FastNew_Namespace" />
<CompilerVisibleProperty Include="FastNew_ForceFastNewDelegate" />
<CompilerVisibleProperty Include="FastNew_AlertGeneratedFile" />
<CompilerVisibleProperty Include="FastNew_DisableGeneratorCache" />
<CompilerVisibleProperty Include="FastNew_PrettyOutput" />
<CompilerVisibleProperty Include="FastNew_MultiThreadedGeneration" />
<CompilerVisibleProperty Include="FastNew_OutputGenerationInfo" />
<CompilerVisibleProperty Include="FastNew_AllowUnsafeImplementation" />
<CompilerVisibleProperty Include="FastNew_PublicFastNew" />
Expand Down
Loading

0 comments on commit 955c4d2

Please sign in to comment.