-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Allow parsing ref readonly parameters in cref
#69104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jjonescz
merged 9 commits into
dotnet:features/RefReadonly
from
jjonescz:RefReadonly-17-CrefParsing
Jul 26, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d2c7205
Allow parsing `ref readonly` parameters in `cref`
jjonescz 4ec46b2
Test `readonly ref` in `cref`
jjonescz 3cf3671
Attach unexpected readonly in cref as trivia
jjonescz c64e631
Preserve previous Update method
jjonescz ad4962d
Remove assert to support manually created invalid nodes
jjonescz c10bd30
Check feature availability when binding `cref`
jjonescz 01edf55
Test more invalid cref permutations
jjonescz e630934
Turn errors into warnings for doc comments
jjonescz e1a7480
Assert that errors are not added to missing nodes via the new overload
jjonescz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -30195,62 +30195,81 @@ static CrefBracketedParameterListSyntax() | |
|
|
||
| /// <summary> | ||
| /// An element of a BaseCrefParameterListSyntax. | ||
| /// Unlike a regular parameter, a cref parameter has only an optional ref or out keyword and a type - | ||
| /// Unlike a regular parameter, a cref parameter has only an optional ref, in, out keyword, | ||
| /// an optional readonly keyword, and a type - | ||
| /// there is no name and there are no attributes or other modifiers. | ||
| /// </summary> | ||
| internal sealed partial class CrefParameterSyntax : CSharpSyntaxNode | ||
| { | ||
| internal readonly SyntaxToken? refKindKeyword; | ||
| internal readonly SyntaxToken? readOnlyKeyword; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another, possibly cleaner, way to do this is to just changet this to a TokenList of Modifiers. |
||
| internal readonly TypeSyntax type; | ||
|
|
||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, TypeSyntax type, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) | ||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, SyntaxToken? readOnlyKeyword, TypeSyntax type, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) | ||
| : base(kind, diagnostics, annotations) | ||
| { | ||
| this.SlotCount = 2; | ||
| this.SlotCount = 3; | ||
| if (refKindKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(refKindKeyword); | ||
| this.refKindKeyword = refKindKeyword; | ||
| } | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(readOnlyKeyword); | ||
| this.readOnlyKeyword = readOnlyKeyword; | ||
| } | ||
| this.AdjustFlagsAndWidth(type); | ||
| this.type = type; | ||
| } | ||
|
|
||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, TypeSyntax type, SyntaxFactoryContext context) | ||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, SyntaxToken? readOnlyKeyword, TypeSyntax type, SyntaxFactoryContext context) | ||
| : base(kind) | ||
| { | ||
| this.SetFactoryContext(context); | ||
| this.SlotCount = 2; | ||
| this.SlotCount = 3; | ||
| if (refKindKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(refKindKeyword); | ||
| this.refKindKeyword = refKindKeyword; | ||
| } | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(readOnlyKeyword); | ||
| this.readOnlyKeyword = readOnlyKeyword; | ||
| } | ||
| this.AdjustFlagsAndWidth(type); | ||
| this.type = type; | ||
| } | ||
|
|
||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, TypeSyntax type) | ||
| internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, SyntaxToken? readOnlyKeyword, TypeSyntax type) | ||
| : base(kind) | ||
| { | ||
| this.SlotCount = 2; | ||
| this.SlotCount = 3; | ||
| if (refKindKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(refKindKeyword); | ||
| this.refKindKeyword = refKindKeyword; | ||
| } | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| this.AdjustFlagsAndWidth(readOnlyKeyword); | ||
| this.readOnlyKeyword = readOnlyKeyword; | ||
| } | ||
| this.AdjustFlagsAndWidth(type); | ||
| this.type = type; | ||
| } | ||
|
|
||
| public SyntaxToken? RefKindKeyword => this.refKindKeyword; | ||
| public SyntaxToken? ReadOnlyKeyword => this.readOnlyKeyword; | ||
| public TypeSyntax Type => this.type; | ||
|
|
||
| internal override GreenNode? GetSlot(int index) | ||
| => index switch | ||
| { | ||
| 0 => this.refKindKeyword, | ||
| 1 => this.type, | ||
| 1 => this.readOnlyKeyword, | ||
| 2 => this.type, | ||
| _ => null, | ||
| }; | ||
|
|
||
|
|
@@ -30259,11 +30278,11 @@ internal CrefParameterSyntax(SyntaxKind kind, SyntaxToken? refKindKeyword, TypeS | |
| public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitCrefParameter(this); | ||
| public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor) => visitor.VisitCrefParameter(this); | ||
|
|
||
| public CrefParameterSyntax Update(SyntaxToken refKindKeyword, TypeSyntax type) | ||
| public CrefParameterSyntax Update(SyntaxToken refKindKeyword, SyntaxToken readOnlyKeyword, TypeSyntax type) | ||
| { | ||
| if (refKindKeyword != this.RefKindKeyword || type != this.Type) | ||
| if (refKindKeyword != this.RefKindKeyword || readOnlyKeyword != this.ReadOnlyKeyword || type != this.Type) | ||
| { | ||
| var newNode = SyntaxFactory.CrefParameter(refKindKeyword, type); | ||
| var newNode = SyntaxFactory.CrefParameter(refKindKeyword, readOnlyKeyword, type); | ||
| var diags = GetDiagnostics(); | ||
| if (diags?.Length > 0) | ||
| newNode = newNode.WithDiagnosticsGreen(diags); | ||
|
|
@@ -30277,21 +30296,27 @@ public CrefParameterSyntax Update(SyntaxToken refKindKeyword, TypeSyntax type) | |
| } | ||
|
|
||
| internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics) | ||
| => new CrefParameterSyntax(this.Kind, this.refKindKeyword, this.type, diagnostics, GetAnnotations()); | ||
| => new CrefParameterSyntax(this.Kind, this.refKindKeyword, this.readOnlyKeyword, this.type, diagnostics, GetAnnotations()); | ||
|
|
||
| internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations) | ||
| => new CrefParameterSyntax(this.Kind, this.refKindKeyword, this.type, GetDiagnostics(), annotations); | ||
| => new CrefParameterSyntax(this.Kind, this.refKindKeyword, this.readOnlyKeyword, this.type, GetDiagnostics(), annotations); | ||
|
|
||
| internal CrefParameterSyntax(ObjectReader reader) | ||
| : base(reader) | ||
| { | ||
| this.SlotCount = 2; | ||
| this.SlotCount = 3; | ||
| var refKindKeyword = (SyntaxToken?)reader.ReadValue(); | ||
| if (refKindKeyword != null) | ||
| { | ||
| AdjustFlagsAndWidth(refKindKeyword); | ||
| this.refKindKeyword = refKindKeyword; | ||
| } | ||
| var readOnlyKeyword = (SyntaxToken?)reader.ReadValue(); | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| AdjustFlagsAndWidth(readOnlyKeyword); | ||
| this.readOnlyKeyword = readOnlyKeyword; | ||
| } | ||
| var type = (TypeSyntax)reader.ReadValue(); | ||
| AdjustFlagsAndWidth(type); | ||
| this.type = type; | ||
|
|
@@ -30301,6 +30326,7 @@ internal override void WriteTo(ObjectWriter writer) | |
| { | ||
| base.WriteTo(writer); | ||
| writer.WriteValue(this.refKindKeyword); | ||
| writer.WriteValue(this.readOnlyKeyword); | ||
| writer.WriteValue(this.type); | ||
| } | ||
|
|
||
|
|
@@ -35985,7 +36011,7 @@ public override CSharpSyntaxNode VisitCrefBracketedParameterList(CrefBracketedPa | |
| => node.Update((SyntaxToken)Visit(node.OpenBracketToken), VisitList(node.Parameters), (SyntaxToken)Visit(node.CloseBracketToken)); | ||
|
|
||
| public override CSharpSyntaxNode VisitCrefParameter(CrefParameterSyntax node) | ||
| => node.Update((SyntaxToken)Visit(node.RefKindKeyword), (TypeSyntax)Visit(node.Type)); | ||
| => node.Update((SyntaxToken)Visit(node.RefKindKeyword), (SyntaxToken)Visit(node.ReadOnlyKeyword), (TypeSyntax)Visit(node.Type)); | ||
|
|
||
| public override CSharpSyntaxNode VisitXmlElement(XmlElementSyntax node) | ||
| => node.Update((XmlElementStartTagSyntax)Visit(node.StartTag), VisitList(node.Content), (XmlElementEndTagSyntax)Visit(node.EndTag)); | ||
|
|
@@ -40645,7 +40671,7 @@ public CrefBracketedParameterListSyntax CrefBracketedParameterList(SyntaxToken o | |
| return result; | ||
| } | ||
|
|
||
| public CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, TypeSyntax type) | ||
| public CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, SyntaxToken? readOnlyKeyword, TypeSyntax type) | ||
| { | ||
| #if DEBUG | ||
| if (refKindKeyword != null) | ||
|
|
@@ -40659,14 +40685,23 @@ public CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, TypeSyntax | |
| default: throw new ArgumentException(nameof(refKindKeyword)); | ||
| } | ||
| } | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| switch (readOnlyKeyword.Kind) | ||
| { | ||
| case SyntaxKind.ReadOnlyKeyword: | ||
| case SyntaxKind.None: break; | ||
| default: throw new ArgumentException(nameof(readOnlyKeyword)); | ||
| } | ||
| } | ||
| if (type == null) throw new ArgumentNullException(nameof(type)); | ||
| #endif | ||
|
|
||
| int hash; | ||
| var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.CrefParameter, refKindKeyword, type, this.context, out hash); | ||
| var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.CrefParameter, refKindKeyword, readOnlyKeyword, type, this.context, out hash); | ||
| if (cached != null) return (CrefParameterSyntax)cached; | ||
|
|
||
| var result = new CrefParameterSyntax(SyntaxKind.CrefParameter, refKindKeyword, type, this.context); | ||
| var result = new CrefParameterSyntax(SyntaxKind.CrefParameter, refKindKeyword, readOnlyKeyword, type, this.context); | ||
| if (hash >= 0) | ||
| { | ||
| SyntaxNodeCache.AddNode(result, hash); | ||
|
|
@@ -45852,7 +45887,7 @@ public static CrefBracketedParameterListSyntax CrefBracketedParameterList(Syntax | |
| return result; | ||
| } | ||
|
|
||
| public static CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, TypeSyntax type) | ||
| public static CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, SyntaxToken? readOnlyKeyword, TypeSyntax type) | ||
| { | ||
| #if DEBUG | ||
| if (refKindKeyword != null) | ||
|
|
@@ -45866,14 +45901,23 @@ public static CrefParameterSyntax CrefParameter(SyntaxToken? refKindKeyword, Typ | |
| default: throw new ArgumentException(nameof(refKindKeyword)); | ||
| } | ||
| } | ||
| if (readOnlyKeyword != null) | ||
| { | ||
| switch (readOnlyKeyword.Kind) | ||
| { | ||
| case SyntaxKind.ReadOnlyKeyword: | ||
| case SyntaxKind.None: break; | ||
| default: throw new ArgumentException(nameof(readOnlyKeyword)); | ||
| } | ||
| } | ||
| if (type == null) throw new ArgumentNullException(nameof(type)); | ||
| #endif | ||
|
|
||
| int hash; | ||
| var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.CrefParameter, refKindKeyword, type, out hash); | ||
| var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.CrefParameter, refKindKeyword, readOnlyKeyword, type, out hash); | ||
| if (cached != null) return (CrefParameterSyntax)cached; | ||
|
|
||
| var result = new CrefParameterSyntax(SyntaxKind.CrefParameter, refKindKeyword, type); | ||
| var result = new CrefParameterSyntax(SyntaxKind.CrefParameter, refKindKeyword, readOnlyKeyword, type); | ||
| if (hash >= 0) | ||
| { | ||
| SyntaxNodeCache.AddNode(result, hash); | ||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.