-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial regex source generator (#59186)
* Add RegexGeneratorAttribute Adds the new RegexGenerator attribute that's a signal to the regex generator to generate code for the specified regex. * Implement RegexGenerator Add a source generator for generating C# code for Regex. This is primarily a port of RegexCompiler.cs, generating C# code instead of MSIL. * Add generator test project Adds tests dedicated to the mechanics of the source generator, e.g. that appropriate diagnostics are issued for improper use of RegexGenerator. * Integrate source generator into many regex tests Start integrating the source generator into the regex test suite, so that many existing tests also validate the generated code. * Address PR feedback * Improve cachability of source generator Changing the generator to not collect all regexes together means we don't need to reprocess/regenerate all regexes every time any one of them is changed. * Use closest matching ctor from GetRegexAsync To better test the appropriate ctor usage. * Improve a few of the polyfills * Address PR feedback * Fully qualify types and remove unnecessary $s Also fixed one place where the IL we were generating wasn't as good as the reflection emit code. * Suppress a couple more warnings * Fix stray ! * Fix TODO about unrolling multi comparisons Also clean up generated code in a few places to make it more readable / concise. * Update resources per PR feedback * Add more tests, clean up parser code, and allow instance/interface methods * Fix test suppression on mobile
- Loading branch information
1 parent
072cbae
commit 00aa651
Showing
55 changed files
with
10,017 additions
and
975 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
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
56 changes: 56 additions & 0 deletions
56
src/libraries/System.Text.RegularExpressions/gen/DiagnosticDescriptors.cs
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,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace System.Text.RegularExpressions.Generator | ||
{ | ||
internal static class DiagnosticDescriptors | ||
{ | ||
public static DiagnosticDescriptor InvalidRegexGeneratorAttribute { get; } = new DiagnosticDescriptor( | ||
id: "SYSLIB1040", | ||
title: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
messageFormat: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeMessage), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
category: "RegexGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true, | ||
customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
|
||
public static DiagnosticDescriptor MultipleRegexGeneratorAttributes { get; } = new DiagnosticDescriptor( | ||
id: "SYSLIB1041", | ||
title: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
messageFormat: new LocalizableResourceString(nameof(SR.MultipleRegexGeneratorAttributesMessage), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
category: "RegexGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true, | ||
customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
|
||
public static DiagnosticDescriptor InvalidRegexArguments { get; } = new DiagnosticDescriptor( | ||
id: "SYSLIB1042", | ||
title: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
messageFormat: new LocalizableResourceString(nameof(SR.InvalidRegexArgumentsMessage), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
category: "RegexGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true, | ||
customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
|
||
public static DiagnosticDescriptor RegexMethodMustHaveValidSignature { get; } = new DiagnosticDescriptor( | ||
id: "SYSLIB1043", | ||
title: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
messageFormat: new LocalizableResourceString(nameof(SR.RegexMethodMustHaveValidSignatureMessage), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
category: "RegexGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true, | ||
customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
|
||
public static DiagnosticDescriptor InvalidLangVersion { get; } = new DiagnosticDescriptor( | ||
id: "SYSLIB1044", | ||
title: new LocalizableResourceString(nameof(SR.InvalidRegexGeneratorAttributeTitle), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
messageFormat: new LocalizableResourceString(nameof(SR.InvalidLangVersionMessage), SR.ResourceManager, typeof(FxResources.System.Text.RegularExpressions.Generator.SR)), | ||
category: "RegexGenerator", | ||
DiagnosticSeverity.Error, | ||
isEnabledByDefault: true, | ||
customTags: WellKnownDiagnosticTags.NotConfigurable); | ||
} | ||
} |
Oops, something went wrong.