提交 1f743475 编写于 作者: N Neal Gafter

Add contextual keyword "var" for use in the *var-pattern*.

上级 7e09ace3
...@@ -270,7 +270,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy ...@@ -270,7 +270,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
var boundDeclType = BindPatternType(typeSyntax, operandType, ref hasErrors, out bool isVar, diagnostics); var boundDeclType = BindPatternType(typeSyntax, operandType, ref hasErrors, out bool isVar, diagnostics);
if (typeSyntax.ToString() == "var" && !isVar) if (typeSyntax.ToString() == "var" && !isVar)
{ {
// For compatibility, we temporarily parse the var pattern with a simple designator as a declaration pattern. // PROTOTYPE(patterns2): For compatibility, we temporarily parse the var pattern with a simple designator as a declaration pattern.
// So we implement the semantics of the var pattern here, forbidding "var" to bind to a user-declared type. // So we implement the semantics of the var pattern here, forbidding "var" to bind to a user-declared type.
if (!hasErrors) if (!hasErrors)
{ {
...@@ -474,11 +474,11 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node, ...@@ -474,11 +474,11 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
private BoundPattern BindVarPattern(VarPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics) private BoundPattern BindVarPattern(VarPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics)
{ {
TypeSymbol declType = operandType; TypeSymbol declType = operandType;
var foundType = BindVarType(node.VarIdentifier, diagnostics, out bool isVar, null); var foundType = BindVarType(node.VarKeyword, diagnostics, out bool isVar, null);
if (!isVar) if (!isVar)
{ {
// Give an error if there is a bindable type "var" in scope // Give an error if there is a bindable type "var" in scope
diagnostics.Add(ErrorCode.ERR_VarMayNotBindToType, node.VarIdentifier.GetLocation(), foundType.ToDisplayString()); diagnostics.Add(ErrorCode.ERR_VarMayNotBindToType, node.VarKeyword.GetLocation(), foundType.ToDisplayString());
hasErrors = true; hasErrors = true;
} }
......
...@@ -10964,50 +10964,50 @@ static DeclarationPatternSyntax() ...@@ -10964,50 +10964,50 @@ static DeclarationPatternSyntax()
internal sealed partial class VarPatternSyntax : PatternSyntax internal sealed partial class VarPatternSyntax : PatternSyntax
{ {
internal readonly SyntaxToken varIdentifier; internal readonly SyntaxToken varKeyword;
internal readonly VariableDesignationSyntax designation; internal readonly VariableDesignationSyntax designation;
internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varIdentifier, VariableDesignationSyntax designation, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varKeyword, VariableDesignationSyntax designation, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations)
: base(kind, diagnostics, annotations) : base(kind, diagnostics, annotations)
{ {
this.SlotCount = 2; this.SlotCount = 2;
this.AdjustFlagsAndWidth(varIdentifier); this.AdjustFlagsAndWidth(varKeyword);
this.varIdentifier = varIdentifier; this.varKeyword = varKeyword;
this.AdjustFlagsAndWidth(designation); this.AdjustFlagsAndWidth(designation);
this.designation = designation; this.designation = designation;
} }
internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varIdentifier, VariableDesignationSyntax designation, SyntaxFactoryContext context) internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varKeyword, VariableDesignationSyntax designation, SyntaxFactoryContext context)
: base(kind) : base(kind)
{ {
this.SetFactoryContext(context); this.SetFactoryContext(context);
this.SlotCount = 2; this.SlotCount = 2;
this.AdjustFlagsAndWidth(varIdentifier); this.AdjustFlagsAndWidth(varKeyword);
this.varIdentifier = varIdentifier; this.varKeyword = varKeyword;
this.AdjustFlagsAndWidth(designation); this.AdjustFlagsAndWidth(designation);
this.designation = designation; this.designation = designation;
} }
internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varIdentifier, VariableDesignationSyntax designation) internal VarPatternSyntax(SyntaxKind kind, SyntaxToken varKeyword, VariableDesignationSyntax designation)
: base(kind) : base(kind)
{ {
this.SlotCount = 2; this.SlotCount = 2;
this.AdjustFlagsAndWidth(varIdentifier); this.AdjustFlagsAndWidth(varKeyword);
this.varIdentifier = varIdentifier; this.varKeyword = varKeyword;
this.AdjustFlagsAndWidth(designation); this.AdjustFlagsAndWidth(designation);
this.designation = designation; this.designation = designation;
} }
public SyntaxToken VarIdentifier { get { return this.varIdentifier; } } public SyntaxToken VarKeyword { get { return this.varKeyword; } }
public VariableDesignationSyntax Designation { get { return this.designation; } } public VariableDesignationSyntax Designation { get { return this.designation; } }
internal override GreenNode GetSlot(int index) internal override GreenNode GetSlot(int index)
{ {
switch (index) switch (index)
{ {
case 0: return this.varIdentifier; case 0: return this.varKeyword;
case 1: return this.designation; case 1: return this.designation;
default: return null; default: return null;
} }
...@@ -11028,11 +11028,11 @@ public override void Accept(CSharpSyntaxVisitor visitor) ...@@ -11028,11 +11028,11 @@ public override void Accept(CSharpSyntaxVisitor visitor)
visitor.VisitVarPattern(this); visitor.VisitVarPattern(this);
} }
public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyntax designation) public VarPatternSyntax Update(SyntaxToken varKeyword, VariableDesignationSyntax designation)
{ {
if (varIdentifier != this.VarIdentifier || designation != this.Designation) if (varKeyword != this.VarKeyword || designation != this.Designation)
{ {
var newNode = SyntaxFactory.VarPattern(varIdentifier, designation); var newNode = SyntaxFactory.VarPattern(varKeyword, designation);
var diags = this.GetDiagnostics(); var diags = this.GetDiagnostics();
if (diags != null && diags.Length > 0) if (diags != null && diags.Length > 0)
newNode = newNode.WithDiagnosticsGreen(diags); newNode = newNode.WithDiagnosticsGreen(diags);
...@@ -11047,23 +11047,23 @@ public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyn ...@@ -11047,23 +11047,23 @@ public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyn
internal override GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics) internal override GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics)
{ {
return new VarPatternSyntax(this.Kind, this.varIdentifier, this.designation, diagnostics, GetAnnotations()); return new VarPatternSyntax(this.Kind, this.varKeyword, this.designation, diagnostics, GetAnnotations());
} }
internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations) internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations)
{ {
return new VarPatternSyntax(this.Kind, this.varIdentifier, this.designation, GetDiagnostics(), annotations); return new VarPatternSyntax(this.Kind, this.varKeyword, this.designation, GetDiagnostics(), annotations);
} }
internal VarPatternSyntax(ObjectReader reader) internal VarPatternSyntax(ObjectReader reader)
: base(reader) : base(reader)
{ {
this.SlotCount = 2; this.SlotCount = 2;
var varIdentifier = (SyntaxToken)reader.ReadValue(); var varKeyword = (SyntaxToken)reader.ReadValue();
if (varIdentifier != null) if (varKeyword != null)
{ {
AdjustFlagsAndWidth(varIdentifier); AdjustFlagsAndWidth(varKeyword);
this.varIdentifier = varIdentifier; this.varKeyword = varKeyword;
} }
var designation = (VariableDesignationSyntax)reader.ReadValue(); var designation = (VariableDesignationSyntax)reader.ReadValue();
if (designation != null) if (designation != null)
...@@ -11076,7 +11076,7 @@ internal VarPatternSyntax(ObjectReader reader) ...@@ -11076,7 +11076,7 @@ internal VarPatternSyntax(ObjectReader reader)
internal override void WriteTo(ObjectWriter writer) internal override void WriteTo(ObjectWriter writer)
{ {
base.WriteTo(writer); base.WriteTo(writer);
writer.WriteValue(this.varIdentifier); writer.WriteValue(this.varKeyword);
writer.WriteValue(this.designation); writer.WriteValue(this.designation);
} }
...@@ -37569,9 +37569,9 @@ public override CSharpSyntaxNode VisitDeclarationPattern(DeclarationPatternSynta ...@@ -37569,9 +37569,9 @@ public override CSharpSyntaxNode VisitDeclarationPattern(DeclarationPatternSynta
public override CSharpSyntaxNode VisitVarPattern(VarPatternSyntax node) public override CSharpSyntaxNode VisitVarPattern(VarPatternSyntax node)
{ {
var varIdentifier = (SyntaxToken)this.Visit(node.VarIdentifier); var varKeyword = (SyntaxToken)this.Visit(node.VarKeyword);
var designation = (VariableDesignationSyntax)this.Visit(node.Designation); var designation = (VariableDesignationSyntax)this.Visit(node.Designation);
return node.Update(varIdentifier, designation); return node.Update(varKeyword, designation);
} }
public override CSharpSyntaxNode VisitDeconstructionPattern(DeconstructionPatternSyntax node) public override CSharpSyntaxNode VisitDeconstructionPattern(DeconstructionPatternSyntax node)
...@@ -41305,27 +41305,27 @@ public DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, VariableDesi ...@@ -41305,27 +41305,27 @@ public DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, VariableDesi
return result; return result;
} }
public VarPatternSyntax VarPattern(SyntaxToken varIdentifier, VariableDesignationSyntax designation) public VarPatternSyntax VarPattern(SyntaxToken varKeyword, VariableDesignationSyntax designation)
{ {
#if DEBUG #if DEBUG
if (varIdentifier == null) if (varKeyword == null)
throw new ArgumentNullException(nameof(varIdentifier)); throw new ArgumentNullException(nameof(varKeyword));
switch (varIdentifier.Kind) switch (varKeyword.Kind)
{ {
case SyntaxKind.IdentifierToken: case SyntaxKind.VarKeyword:
break; break;
default: default:
throw new ArgumentException("varIdentifier"); throw new ArgumentException("varKeyword");
} }
if (designation == null) if (designation == null)
throw new ArgumentNullException(nameof(designation)); throw new ArgumentNullException(nameof(designation));
#endif #endif
int hash; int hash;
var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.VarPattern, varIdentifier, designation, this.context, out hash); var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.VarPattern, varKeyword, designation, this.context, out hash);
if (cached != null) return (VarPatternSyntax)cached; if (cached != null) return (VarPatternSyntax)cached;
var result = new VarPatternSyntax(SyntaxKind.VarPattern, varIdentifier, designation, this.context); var result = new VarPatternSyntax(SyntaxKind.VarPattern, varKeyword, designation, this.context);
if (hash >= 0) if (hash >= 0)
{ {
SyntaxNodeCache.AddNode(result, hash); SyntaxNodeCache.AddNode(result, hash);
...@@ -48446,27 +48446,27 @@ public static DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, Varia ...@@ -48446,27 +48446,27 @@ public static DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, Varia
return result; return result;
} }
public static VarPatternSyntax VarPattern(SyntaxToken varIdentifier, VariableDesignationSyntax designation) public static VarPatternSyntax VarPattern(SyntaxToken varKeyword, VariableDesignationSyntax designation)
{ {
#if DEBUG #if DEBUG
if (varIdentifier == null) if (varKeyword == null)
throw new ArgumentNullException(nameof(varIdentifier)); throw new ArgumentNullException(nameof(varKeyword));
switch (varIdentifier.Kind) switch (varKeyword.Kind)
{ {
case SyntaxKind.IdentifierToken: case SyntaxKind.VarKeyword:
break; break;
default: default:
throw new ArgumentException("varIdentifier"); throw new ArgumentException("varKeyword");
} }
if (designation == null) if (designation == null)
throw new ArgumentNullException(nameof(designation)); throw new ArgumentNullException(nameof(designation));
#endif #endif
int hash; int hash;
var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.VarPattern, varIdentifier, designation, out hash); var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.VarPattern, varKeyword, designation, out hash);
if (cached != null) return (VarPatternSyntax)cached; if (cached != null) return (VarPatternSyntax)cached;
var result = new VarPatternSyntax(SyntaxKind.VarPattern, varIdentifier, designation); var result = new VarPatternSyntax(SyntaxKind.VarPattern, varKeyword, designation);
if (hash >= 0) if (hash >= 0)
{ {
SyntaxNodeCache.AddNode(result, hash); SyntaxNodeCache.AddNode(result, hash);
...@@ -3153,9 +3153,9 @@ public override SyntaxNode VisitDeclarationPattern(DeclarationPatternSyntax node ...@@ -3153,9 +3153,9 @@ public override SyntaxNode VisitDeclarationPattern(DeclarationPatternSyntax node
public override SyntaxNode VisitVarPattern(VarPatternSyntax node) public override SyntaxNode VisitVarPattern(VarPatternSyntax node)
{ {
var varIdentifier = this.VisitToken(node.VarIdentifier); var varKeyword = this.VisitToken(node.VarKeyword);
var designation = (VariableDesignationSyntax)this.Visit(node.Designation); var designation = (VariableDesignationSyntax)this.Visit(node.Designation);
return node.Update(varIdentifier, designation); return node.Update(varKeyword, designation);
} }
public override SyntaxNode VisitDeconstructionPattern(DeconstructionPatternSyntax node) public override SyntaxNode VisitDeconstructionPattern(DeconstructionPatternSyntax node)
...@@ -6715,21 +6715,27 @@ public static DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, Varia ...@@ -6715,21 +6715,27 @@ public static DeclarationPatternSyntax DeclarationPattern(TypeSyntax type, Varia
/// <summary>Creates a new VarPatternSyntax instance.</summary> /// <summary>Creates a new VarPatternSyntax instance.</summary>
public static VarPatternSyntax VarPattern(SyntaxToken varIdentifier, VariableDesignationSyntax designation) public static VarPatternSyntax VarPattern(SyntaxToken varKeyword, VariableDesignationSyntax designation)
{ {
switch (varIdentifier.Kind()) switch (varKeyword.Kind())
{ {
case SyntaxKind.IdentifierToken: case SyntaxKind.VarKeyword:
break; break;
default: default:
throw new ArgumentException("varIdentifier"); throw new ArgumentException("varKeyword");
} }
if (designation == null) if (designation == null)
throw new ArgumentNullException(nameof(designation)); throw new ArgumentNullException(nameof(designation));
return (VarPatternSyntax)Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.VarPattern((Syntax.InternalSyntax.SyntaxToken)varIdentifier.Node, designation == null ? null : (Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VariableDesignationSyntax)designation.Green).CreateRed(); return (VarPatternSyntax)Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.VarPattern((Syntax.InternalSyntax.SyntaxToken)varKeyword.Node, designation == null ? null : (Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VariableDesignationSyntax)designation.Green).CreateRed();
} }
/// <summary>Creates a new VarPatternSyntax instance.</summary>
public static VarPatternSyntax VarPattern(VariableDesignationSyntax designation)
{
return SyntaxFactory.VarPattern(SyntaxFactory.Token(SyntaxKind.VarKeyword), designation);
}
/// <summary>Creates a new DeconstructionPatternSyntax instance.</summary> /// <summary>Creates a new DeconstructionPatternSyntax instance.</summary>
public static DeconstructionPatternSyntax DeconstructionPattern(TypeSyntax type, SyntaxToken openParenToken, SeparatedSyntaxList<SubpatternElementSyntax> subPatterns, SyntaxToken closeParenToken, PropertySubpatternSyntax propertySubpattern, VariableDesignationSyntax designation) public static DeconstructionPatternSyntax DeconstructionPattern(TypeSyntax type, SyntaxToken openParenToken, SeparatedSyntaxList<SubpatternElementSyntax> subPatterns, SyntaxToken closeParenToken, PropertySubpatternSyntax propertySubpattern, VariableDesignationSyntax designation)
{ {
......
...@@ -6857,9 +6857,9 @@ internal VarPatternSyntax(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.CS ...@@ -6857,9 +6857,9 @@ internal VarPatternSyntax(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.CS
{ {
} }
public SyntaxToken VarIdentifier public SyntaxToken VarKeyword
{ {
get { return new SyntaxToken(this, ((Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VarPatternSyntax)this.Green).varIdentifier, this.Position, 0); } get { return new SyntaxToken(this, ((Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VarPatternSyntax)this.Green).varKeyword, this.Position, 0); }
} }
public VariableDesignationSyntax Designation public VariableDesignationSyntax Designation
...@@ -6897,11 +6897,11 @@ public override void Accept(CSharpSyntaxVisitor visitor) ...@@ -6897,11 +6897,11 @@ public override void Accept(CSharpSyntaxVisitor visitor)
visitor.VisitVarPattern(this); visitor.VisitVarPattern(this);
} }
public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyntax designation) public VarPatternSyntax Update(SyntaxToken varKeyword, VariableDesignationSyntax designation)
{ {
if (varIdentifier != this.VarIdentifier || designation != this.Designation) if (varKeyword != this.VarKeyword || designation != this.Designation)
{ {
var newNode = SyntaxFactory.VarPattern(varIdentifier, designation); var newNode = SyntaxFactory.VarPattern(varKeyword, designation);
var annotations = this.GetAnnotations(); var annotations = this.GetAnnotations();
if (annotations != null && annotations.Length > 0) if (annotations != null && annotations.Length > 0)
return newNode.WithAnnotations(annotations); return newNode.WithAnnotations(annotations);
...@@ -6911,14 +6911,14 @@ public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyn ...@@ -6911,14 +6911,14 @@ public VarPatternSyntax Update(SyntaxToken varIdentifier, VariableDesignationSyn
return this; return this;
} }
public VarPatternSyntax WithVarIdentifier(SyntaxToken varIdentifier) public VarPatternSyntax WithVarKeyword(SyntaxToken varKeyword)
{ {
return this.Update(varIdentifier, this.Designation); return this.Update(varKeyword, this.Designation);
} }
public VarPatternSyntax WithDesignation(VariableDesignationSyntax designation) public VarPatternSyntax WithDesignation(VariableDesignationSyntax designation)
{ {
return this.Update(this.VarIdentifier, designation); return this.Update(this.VarKeyword, designation);
} }
} }
......
...@@ -7071,7 +7071,7 @@ private bool IsPossibleNewExpression() ...@@ -7071,7 +7071,7 @@ private bool IsPossibleNewExpression()
return null; return null;
case SyntaxKind.OpenParenToken: case SyntaxKind.OpenParenToken:
if (current.IsVar()) if (current.IsIdentifierVar())
{ {
// potentially either a tuple type in a local declaration (true), or // potentially either a tuple type in a local declaration (true), or
// a tuple lvalue in a deconstruction assignment (false). // a tuple lvalue in a deconstruction assignment (false).
...@@ -9303,7 +9303,7 @@ private ExpressionSyntax ParseTerm(Precedence precedence) ...@@ -9303,7 +9303,7 @@ private ExpressionSyntax ParseTerm(Precedence precedence)
/// </summary> /// </summary>
private bool IsPossibleDeconstructionLeft(Precedence precedence) private bool IsPossibleDeconstructionLeft(Precedence precedence)
{ {
if (precedence > Precedence.Assignment || !(this.CurrentToken.IsVar() || IsPredefinedType(this.CurrentToken.Kind))) if (precedence > Precedence.Assignment || !(this.CurrentToken.IsIdentifierVar() || IsPredefinedType(this.CurrentToken.Kind)))
{ {
return false; return false;
} }
......
...@@ -211,7 +211,7 @@ private bool IsPossibleDeclarationExpression(ParseTypeMode mode, bool permitTupl ...@@ -211,7 +211,7 @@ private bool IsPossibleDeclarationExpression(ParseTypeMode mode, bool permitTupl
/// </summary> /// </summary>
private bool IsVarType() private bool IsVarType()
{ {
if (!this.CurrentToken.IsVar()) if (!this.CurrentToken.IsIdentifierVar())
{ {
return false; return false;
} }
...@@ -410,22 +410,22 @@ bool looksLikeCast() ...@@ -410,22 +410,22 @@ bool looksLikeCast()
{ {
var typeIdentifier = (IdentifierNameSyntax)type; var typeIdentifier = (IdentifierNameSyntax)type;
var typeIdentifierToken = typeIdentifier.Identifier; var typeIdentifierToken = typeIdentifier.Identifier;
if (typeIdentifierToken.Text == "var") if (typeIdentifierToken.ContextualKind == SyntaxKind.VarKeyword)
{ {
// we have a "var" pattern; "var" is not permitted to be a stand-in for a type (or a constant) in a pattern. // we have a "var" pattern; "var" is not permitted to be a stand-in for a type (or a constant) in a pattern.
var varIdentifier = typeIdentifierToken; var varToken = ConvertToKeyword(typeIdentifierToken);
var wasTupleDesignator = this.CurrentToken.Kind == SyntaxKind.OpenParenToken; var wasTupleDesignator = this.CurrentToken.Kind == SyntaxKind.OpenParenToken;
var varDesignation = ParseDesignation(); var varDesignation = ParseDesignation();
if (wasTupleDesignator) if (wasTupleDesignator)
{ {
return _syntaxFactory.VarPattern(varIdentifier, varDesignation); return _syntaxFactory.VarPattern(varToken, varDesignation);
} }
else else
{ {
// PROTOTYPE(patterns2): we parse it as a declaration pattern when we have simple designation, for compatibility. // PROTOTYPE(patterns2): we parse it as a declaration pattern when we have simple designation, for compatibility.
// PROTOTYPE(patterns2): can we change it to use a var pattern in all cases? // PROTOTYPE(patterns2): can we change it to use a var pattern in all cases?
//return _syntaxFactory.VarPattern(varIdentifier, varDesignation); //return _syntaxFactory.VarPattern(varIdentifier, varDesignation);
return _syntaxFactory.DeclarationPattern(_syntaxFactory.IdentifierName(varIdentifier), varDesignation); return _syntaxFactory.DeclarationPattern(_syntaxFactory.IdentifierName(typeIdentifierToken), varDesignation);
} }
} }
} }
......
...@@ -73,10 +73,10 @@ Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax.WithOpenBraceToken(M ...@@ -73,10 +73,10 @@ Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax.WithOpenBraceToken(M
Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax.WithSwitchKeyword(Microsoft.CodeAnalysis.SyntaxToken switchKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax.WithSwitchKeyword(Microsoft.CodeAnalysis.SyntaxToken switchKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.Designation.get -> Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.Designation.get -> Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken varIdentifier, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken varKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.VarIdentifier.get -> Microsoft.CodeAnalysis.SyntaxToken Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.VarKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.WithDesignation(Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.WithDesignation(Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.WithVarIdentifier(Microsoft.CodeAnalysis.SyntaxToken varIdentifier) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax.WithVarKeyword(Microsoft.CodeAnalysis.SyntaxToken varKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
Microsoft.CodeAnalysis.CSharp.SyntaxKind.DeconstructionPattern = 9023 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.DeconstructionPattern = 9023 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.DiscardPattern = 9024 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.DiscardPattern = 9024 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.PropertyPattern = 9020 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.PropertyPattern = 9020 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
...@@ -84,6 +84,7 @@ Microsoft.CodeAnalysis.CSharp.SyntaxKind.PropertySubpattern = 9021 -> Microsoft. ...@@ -84,6 +84,7 @@ Microsoft.CodeAnalysis.CSharp.SyntaxKind.PropertySubpattern = 9021 -> Microsoft.
Microsoft.CodeAnalysis.CSharp.SyntaxKind.SubpatternElement = 9022 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.SubpatternElement = 9022 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.SwitchExpression = 9025 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.SwitchExpression = 9025 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.SwitchExpressionArm = 9026 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.SwitchExpressionArm = 9026 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.VarKeyword = 8486 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
Microsoft.CodeAnalysis.CSharp.SyntaxKind.VarPattern = 9027 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind Microsoft.CodeAnalysis.CSharp.SyntaxKind.VarPattern = 9027 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitDeconstructionPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DeconstructionPatternSyntax node) -> Microsoft.CodeAnalysis.SyntaxNode override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitDeconstructionPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DeconstructionPatternSyntax node) -> Microsoft.CodeAnalysis.SyntaxNode
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitDiscardPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DiscardPatternSyntax node) -> Microsoft.CodeAnalysis.SyntaxNode override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitDiscardPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DiscardPatternSyntax node) -> Microsoft.CodeAnalysis.SyntaxNode
...@@ -127,7 +128,8 @@ static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpression(Microsoft.Co ...@@ -127,7 +128,8 @@ static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpression(Microsoft.Co
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax whenClause, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax whenClause, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax whenClause, Microsoft.CodeAnalysis.SyntaxToken equalsGreaterThanToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SwitchExpressionArm(Microsoft.CodeAnalysis.CSharp.Syntax.PatternSyntax pattern, Microsoft.CodeAnalysis.CSharp.Syntax.WhenClauseSyntax whenClause, Microsoft.CodeAnalysis.SyntaxToken equalsGreaterThanToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.SwitchExpressionArmSyntax
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.VarPattern(Microsoft.CodeAnalysis.SyntaxToken varIdentifier, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.VarPattern(Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.VarPattern(Microsoft.CodeAnalysis.SyntaxToken varKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDesignationSyntax designation) -> Microsoft.CodeAnalysis.CSharp.Syntax.VarPatternSyntax
virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitDeconstructionPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DeconstructionPatternSyntax node) -> void virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitDeconstructionPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DeconstructionPatternSyntax node) -> void
virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitDiscardPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DiscardPatternSyntax node) -> void virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitDiscardPattern(Microsoft.CodeAnalysis.CSharp.Syntax.DiscardPatternSyntax node) -> void
virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitPropertyPattern(Microsoft.CodeAnalysis.CSharp.Syntax.PropertyPatternSyntax node) -> void virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitPropertyPattern(Microsoft.CodeAnalysis.CSharp.Syntax.PropertyPatternSyntax node) -> void
......
...@@ -1734,8 +1734,8 @@ ...@@ -1734,8 +1734,8 @@
</Node> </Node>
<Node Name="VarPatternSyntax" Base="PatternSyntax"> <Node Name="VarPatternSyntax" Base="PatternSyntax">
<Kind Name="VarPattern" /> <Kind Name="VarPattern" />
<Field Name="VarIdentifier" Type="SyntaxToken"> <Field Name="VarKeyword" Type="SyntaxToken">
<Kind Name="IdentifierToken"/> <Kind Name="VarKeyword"/>
</Field> </Field>
<Field Name="Designation" Type="VariableDesignationSyntax"/> <Field Name="Designation" Type="VariableDesignationSyntax"/>
</Node> </Node>
......
...@@ -404,14 +404,14 @@ public static bool IsLambdaBody(SyntaxNode node) ...@@ -404,14 +404,14 @@ public static bool IsLambdaBody(SyntaxNode node)
return LambdaUtilities.IsLambdaBody(node); return LambdaUtilities.IsLambdaBody(node);
} }
internal static bool IsVar(this Syntax.InternalSyntax.SyntaxToken node) internal static bool IsIdentifierVar(this Syntax.InternalSyntax.SyntaxToken node)
{ {
return node.Kind == SyntaxKind.IdentifierToken && node.ValueText == "var"; return node.ContextualKind == SyntaxKind.VarKeyword;
} }
internal static bool IsVarOrPredefinedType(this Syntax.InternalSyntax.SyntaxToken node) internal static bool IsIdentifierVarOrPredefinedType(this Syntax.InternalSyntax.SyntaxToken node)
{ {
return node.IsVar() || IsPredefinedType(node.Kind); return node.IsIdentifierVar() || IsPredefinedType(node.Kind);
} }
internal static bool IsDeclarationExpressionType(SyntaxNode node, out DeclarationExpressionSyntax parent) internal static bool IsDeclarationExpressionType(SyntaxNode node, out DeclarationExpressionSyntax parent)
......
...@@ -210,6 +210,7 @@ public enum SyntaxKind : ushort ...@@ -210,6 +210,7 @@ public enum SyntaxKind : ushort
RestoreKeyword = 8480, RestoreKeyword = 8480,
ReferenceKeyword = 8481, ReferenceKeyword = 8481,
LoadKeyword = 8485, LoadKeyword = 8485,
VarKeyword = 8486,
InterpolatedStringStartToken = 8482, // $" InterpolatedStringStartToken = 8482, // $"
InterpolatedStringEndToken = 8483, // " InterpolatedStringEndToken = 8483, // "
......
...@@ -1092,6 +1092,7 @@ public static bool IsContextualKeyword(SyntaxKind kind) ...@@ -1092,6 +1092,7 @@ public static bool IsContextualKeyword(SyntaxKind kind)
case SyntaxKind.AwaitKeyword: case SyntaxKind.AwaitKeyword:
case SyntaxKind.WhenKeyword: case SyntaxKind.WhenKeyword:
case SyntaxKind.UnderscoreToken: case SyntaxKind.UnderscoreToken:
case SyntaxKind.VarKeyword:
return true; return true;
default: default:
return false; return false;
...@@ -1193,6 +1194,8 @@ public static SyntaxKind GetContextualKeywordKind(string text) ...@@ -1193,6 +1194,8 @@ public static SyntaxKind GetContextualKeywordKind(string text)
return SyntaxKind.NameOfKeyword; return SyntaxKind.NameOfKeyword;
case "_": case "_":
return SyntaxKind.UnderscoreToken; return SyntaxKind.UnderscoreToken;
case "var":
return SyntaxKind.VarKeyword;
default: default:
return SyntaxKind.None; return SyntaxKind.None;
} }
...@@ -1598,6 +1601,8 @@ public static string GetText(SyntaxKind kind) ...@@ -1598,6 +1601,8 @@ public static string GetText(SyntaxKind kind)
return "\""; return "\"";
case SyntaxKind.UnderscoreToken: case SyntaxKind.UnderscoreToken:
return "_"; return "_";
case SyntaxKind.VarKeyword:
return "var";
default: default:
return string.Empty; return string.Empty;
} }
......
...@@ -386,7 +386,7 @@ private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.DeclarationPa ...@@ -386,7 +386,7 @@ private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.DeclarationPa
private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VarPatternSyntax GenerateVarPattern() private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.VarPatternSyntax GenerateVarPattern()
{ {
return Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.VarPattern(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.Identifier("VarIdentifier"), GenerateSingleVariableDesignation()); return Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.VarPattern(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.SyntaxFactory.Token(SyntaxKind.VarKeyword), GenerateSingleVariableDesignation());
} }
private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.DeconstructionPatternSyntax GenerateDeconstructionPattern() private static Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.DeconstructionPatternSyntax GenerateDeconstructionPattern()
...@@ -1961,7 +1961,7 @@ public void TestVarPatternFactoryAndProperties() ...@@ -1961,7 +1961,7 @@ public void TestVarPatternFactoryAndProperties()
{ {
var node = GenerateVarPattern(); var node = GenerateVarPattern();
Assert.Equal(SyntaxKind.IdentifierToken, node.VarIdentifier.Kind); Assert.Equal(SyntaxKind.VarKeyword, node.VarKeyword.Kind);
Assert.NotNull(node.Designation); Assert.NotNull(node.Designation);
AttachAndCheckDiagnostics(node); AttachAndCheckDiagnostics(node);
...@@ -9651,7 +9651,7 @@ private static DeclarationPatternSyntax GenerateDeclarationPattern() ...@@ -9651,7 +9651,7 @@ private static DeclarationPatternSyntax GenerateDeclarationPattern()
private static VarPatternSyntax GenerateVarPattern() private static VarPatternSyntax GenerateVarPattern()
{ {
return SyntaxFactory.VarPattern(SyntaxFactory.Identifier("VarIdentifier"), GenerateSingleVariableDesignation()); return SyntaxFactory.VarPattern(SyntaxFactory.Token(SyntaxKind.VarKeyword), GenerateSingleVariableDesignation());
} }
private static DeconstructionPatternSyntax GenerateDeconstructionPattern() private static DeconstructionPatternSyntax GenerateDeconstructionPattern()
...@@ -11226,9 +11226,9 @@ public void TestVarPatternFactoryAndProperties() ...@@ -11226,9 +11226,9 @@ public void TestVarPatternFactoryAndProperties()
{ {
var node = GenerateVarPattern(); var node = GenerateVarPattern();
Assert.Equal(SyntaxKind.IdentifierToken, node.VarIdentifier.Kind()); Assert.Equal(SyntaxKind.VarKeyword, node.VarKeyword.Kind());
Assert.NotNull(node.Designation); Assert.NotNull(node.Designation);
var newNode = node.WithVarIdentifier(node.VarIdentifier).WithDesignation(node.Designation); var newNode = node.WithVarKeyword(node.VarKeyword).WithDesignation(node.Designation);
Assert.Equal(node, newNode); Assert.Equal(node, newNode);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册