-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Parsing Using Var #28315
Parsing Using Var #28315
Changes from 8 commits
7fb24dc
b4608e6
81632c1
50779d4
3d73621
686f245
249b490
68426cf
208e8db
a2b5d0f
70bfd1f
81d4440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12284,14 +12284,20 @@ static LocalFunctionStatementSyntax() | |
|
||
internal sealed partial class LocalDeclarationStatementSyntax : StatementSyntax | ||
{ | ||
internal readonly SyntaxToken usingKeyword; | ||
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. i'm not s huge fan of repurposing this node in this manner. It feels more appropriate as a new sort of node. 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. 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. This is usually what we do when we augment nodes. For instance, when we added 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. Yeah, i'm on the fence. Something feels... 'wonky' here. Perhaps because 'using' bridges between two things (using-statements, and local-var-statements). That's unlike 'ref'. That said, this may just need some time on my part to get used to it. So this is not at all strong pushback. If the team feels like this is "good", then i have no objection. #Resolved 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. Could it be parsed into |
||
internal readonly GreenNode modifiers; | ||
internal readonly VariableDeclarationSyntax declaration; | ||
internal readonly SyntaxToken semicolonToken; | ||
|
||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) | ||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, SyntaxToken usingKeyword, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) | ||
: base(kind, diagnostics, annotations) | ||
{ | ||
this.SlotCount = 3; | ||
this.SlotCount = 4; | ||
if (usingKeyword != null) | ||
{ | ||
this.AdjustFlagsAndWidth(usingKeyword); | ||
this.usingKeyword = usingKeyword; | ||
} | ||
if (modifiers != null) | ||
{ | ||
this.AdjustFlagsAndWidth(modifiers); | ||
|
@@ -12304,11 +12310,16 @@ internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, V | |
} | ||
|
||
|
||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken, SyntaxFactoryContext context) | ||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, SyntaxToken usingKeyword, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken, SyntaxFactoryContext context) | ||
: base(kind) | ||
{ | ||
this.SetFactoryContext(context); | ||
this.SlotCount = 3; | ||
this.SlotCount = 4; | ||
if (usingKeyword != null) | ||
{ | ||
this.AdjustFlagsAndWidth(usingKeyword); | ||
this.usingKeyword = usingKeyword; | ||
} | ||
if (modifiers != null) | ||
{ | ||
this.AdjustFlagsAndWidth(modifiers); | ||
|
@@ -12321,10 +12332,15 @@ internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, V | |
} | ||
|
||
|
||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
internal LocalDeclarationStatementSyntax(SyntaxKind kind, SyntaxToken usingKeyword, GreenNode modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
: base(kind) | ||
{ | ||
this.SlotCount = 3; | ||
this.SlotCount = 4; | ||
if (usingKeyword != null) | ||
{ | ||
this.AdjustFlagsAndWidth(usingKeyword); | ||
this.usingKeyword = usingKeyword; | ||
} | ||
if (modifiers != null) | ||
{ | ||
this.AdjustFlagsAndWidth(modifiers); | ||
|
@@ -12336,6 +12352,7 @@ internal LocalDeclarationStatementSyntax(SyntaxKind kind, GreenNode modifiers, V | |
this.semicolonToken = semicolonToken; | ||
} | ||
|
||
public SyntaxToken UsingKeyword { get { return this.usingKeyword; } } | ||
/// <summary>Gets the modifier list.</summary> | ||
public Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> Modifiers { get { return new Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken>(this.modifiers); } } | ||
public VariableDeclarationSyntax Declaration { get { return this.declaration; } } | ||
|
@@ -12345,9 +12362,10 @@ internal override GreenNode GetSlot(int index) | |
{ | ||
switch (index) | ||
{ | ||
case 0: return this.modifiers; | ||
case 1: return this.declaration; | ||
case 2: return this.semicolonToken; | ||
case 0: return this.usingKeyword; | ||
case 1: return this.modifiers; | ||
case 2: return this.declaration; | ||
case 3: return this.semicolonToken; | ||
default: return null; | ||
} | ||
} | ||
|
@@ -12367,11 +12385,11 @@ public override void Accept(CSharpSyntaxVisitor visitor) | |
visitor.VisitLocalDeclarationStatement(this); | ||
} | ||
|
||
public LocalDeclarationStatementSyntax Update(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
public LocalDeclarationStatementSyntax Update(SyntaxToken usingKeyword, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
{ | ||
if (modifiers != this.Modifiers || declaration != this.Declaration || semicolonToken != this.SemicolonToken) | ||
if (usingKeyword != this.UsingKeyword || modifiers != this.Modifiers || declaration != this.Declaration || semicolonToken != this.SemicolonToken) | ||
{ | ||
var newNode = SyntaxFactory.LocalDeclarationStatement(modifiers, declaration, semicolonToken); | ||
var newNode = SyntaxFactory.LocalDeclarationStatement(usingKeyword, modifiers, declaration, semicolonToken); | ||
var diags = this.GetDiagnostics(); | ||
if (diags != null && diags.Length > 0) | ||
newNode = newNode.WithDiagnosticsGreen(diags); | ||
|
@@ -12386,18 +12404,24 @@ public LocalDeclarationStatementSyntax Update(Microsoft.CodeAnalysis.Syntax.Inte | |
|
||
internal override GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics) | ||
{ | ||
return new LocalDeclarationStatementSyntax(this.Kind, this.modifiers, this.declaration, this.semicolonToken, diagnostics, GetAnnotations()); | ||
return new LocalDeclarationStatementSyntax(this.Kind, this.usingKeyword, this.modifiers, this.declaration, this.semicolonToken, diagnostics, GetAnnotations()); | ||
} | ||
|
||
internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations) | ||
{ | ||
return new LocalDeclarationStatementSyntax(this.Kind, this.modifiers, this.declaration, this.semicolonToken, GetDiagnostics(), annotations); | ||
return new LocalDeclarationStatementSyntax(this.Kind, this.usingKeyword, this.modifiers, this.declaration, this.semicolonToken, GetDiagnostics(), annotations); | ||
} | ||
|
||
internal LocalDeclarationStatementSyntax(ObjectReader reader) | ||
: base(reader) | ||
{ | ||
this.SlotCount = 3; | ||
this.SlotCount = 4; | ||
var usingKeyword = (SyntaxToken)reader.ReadValue(); | ||
if (usingKeyword != null) | ||
{ | ||
AdjustFlagsAndWidth(usingKeyword); | ||
this.usingKeyword = usingKeyword; | ||
} | ||
var modifiers = (GreenNode)reader.ReadValue(); | ||
if (modifiers != null) | ||
{ | ||
|
@@ -12421,6 +12445,7 @@ internal LocalDeclarationStatementSyntax(ObjectReader reader) | |
internal override void WriteTo(ObjectWriter writer) | ||
{ | ||
base.WriteTo(writer); | ||
writer.WriteValue(this.usingKeyword); | ||
writer.WriteValue(this.modifiers); | ||
writer.WriteValue(this.declaration); | ||
writer.WriteValue(this.semicolonToken); | ||
|
@@ -36512,10 +36537,11 @@ public override CSharpSyntaxNode VisitLocalFunctionStatement(LocalFunctionStatem | |
|
||
public override CSharpSyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) | ||
{ | ||
var usingKeyword = (SyntaxToken)this.Visit(node.UsingKeyword); | ||
var modifiers = this.VisitList(node.Modifiers); | ||
var declaration = (VariableDeclarationSyntax)this.Visit(node.Declaration); | ||
var semicolonToken = (SyntaxToken)this.Visit(node.SemicolonToken); | ||
return node.Update(modifiers, declaration, semicolonToken); | ||
return node.Update(usingKeyword, modifiers, declaration, semicolonToken); | ||
} | ||
|
||
public override CSharpSyntaxNode VisitVariableDeclaration(VariableDeclarationSyntax node) | ||
|
@@ -40348,9 +40374,20 @@ public LocalFunctionStatementSyntax LocalFunctionStatement(Microsoft.CodeAnalysi | |
return new LocalFunctionStatementSyntax(SyntaxKind.LocalFunctionStatement, modifiers.Node, returnType, identifier, typeParameterList, parameterList, constraintClauses.Node, body, expressionBody, semicolonToken, this.context); | ||
} | ||
|
||
public LocalDeclarationStatementSyntax LocalDeclarationStatement(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
public LocalDeclarationStatementSyntax LocalDeclarationStatement(SyntaxToken usingKeyword, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
{ | ||
#if DEBUG | ||
if (usingKeyword != null) | ||
{ | ||
switch (usingKeyword.Kind) | ||
{ | ||
case SyntaxKind.UsingKeyword: | ||
case SyntaxKind.None: | ||
break; | ||
default: | ||
throw new ArgumentException("usingKeyword"); | ||
} | ||
} | ||
if (declaration == null) | ||
throw new ArgumentNullException(nameof(declaration)); | ||
if (semicolonToken == null) | ||
|
@@ -40364,17 +40401,7 @@ public LocalDeclarationStatementSyntax LocalDeclarationStatement(Microsoft.CodeA | |
} | ||
#endif | ||
|
||
int hash; | ||
var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.LocalDeclarationStatement, modifiers.Node, declaration, semicolonToken, this.context, out hash); | ||
if (cached != null) return (LocalDeclarationStatementSyntax)cached; | ||
|
||
var result = new LocalDeclarationStatementSyntax(SyntaxKind.LocalDeclarationStatement, modifiers.Node, declaration, semicolonToken, this.context); | ||
if (hash >= 0) | ||
{ | ||
SyntaxNodeCache.AddNode(result, hash); | ||
} | ||
|
||
return result; | ||
return new LocalDeclarationStatementSyntax(SyntaxKind.LocalDeclarationStatement, usingKeyword, modifiers.Node, declaration, semicolonToken, this.context); | ||
} | ||
|
||
public VariableDeclarationSyntax VariableDeclaration(TypeSyntax type, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList<VariableDeclaratorSyntax> variables) | ||
|
@@ -47311,9 +47338,20 @@ public static LocalFunctionStatementSyntax LocalFunctionStatement(Microsoft.Code | |
return new LocalFunctionStatementSyntax(SyntaxKind.LocalFunctionStatement, modifiers.Node, returnType, identifier, typeParameterList, parameterList, constraintClauses.Node, body, expressionBody, semicolonToken); | ||
} | ||
|
||
public static LocalDeclarationStatementSyntax LocalDeclarationStatement(Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
public static LocalDeclarationStatementSyntax LocalDeclarationStatement(SyntaxToken usingKeyword, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SyntaxList<SyntaxToken> modifiers, VariableDeclarationSyntax declaration, SyntaxToken semicolonToken) | ||
{ | ||
#if DEBUG | ||
if (usingKeyword != null) | ||
{ | ||
switch (usingKeyword.Kind) | ||
{ | ||
case SyntaxKind.UsingKeyword: | ||
case SyntaxKind.None: | ||
break; | ||
default: | ||
throw new ArgumentException("usingKeyword"); | ||
} | ||
} | ||
if (declaration == null) | ||
throw new ArgumentNullException(nameof(declaration)); | ||
if (semicolonToken == null) | ||
|
@@ -47327,17 +47365,7 @@ public static LocalDeclarationStatementSyntax LocalDeclarationStatement(Microsof | |
} | ||
#endif | ||
|
||
int hash; | ||
var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.LocalDeclarationStatement, modifiers.Node, declaration, semicolonToken, out hash); | ||
if (cached != null) return (LocalDeclarationStatementSyntax)cached; | ||
|
||
var result = new LocalDeclarationStatementSyntax(SyntaxKind.LocalDeclarationStatement, modifiers.Node, declaration, semicolonToken); | ||
if (hash >= 0) | ||
{ | ||
SyntaxNodeCache.AddNode(result, hash); | ||
} | ||
|
||
return result; | ||
return new LocalDeclarationStatementSyntax(SyntaxKind.LocalDeclarationStatement, usingKeyword, modifiers.Node, declaration, semicolonToken); | ||
} | ||
|
||
public static VariableDeclarationSyntax VariableDeclaration(TypeSyntax type, Microsoft.CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList<VariableDeclaratorSyntax> variables) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look necessary.