提交 553de58a 编写于 作者: N Neal Gafter

Change `var` to an explicit type in some compiler sources.

Replace "TODO(patterns2)" with "PROTOTYPE(patterns2)"
上级 1caceccb
......@@ -141,7 +141,7 @@ internal InContainerBinder GetImportsBinder(CSharpSyntaxNode unit, bool inUsing
{
BinderFactoryVisitor visitor = _binderFactoryVisitorPool.Allocate();
visitor.Initialize(0, null, null);
var result = visitor.VisitNamespaceDeclaration((NamespaceDeclarationSyntax)unit, unit.SpanStart, inBody: true, inUsing: inUsing);
InContainerBinder result = visitor.VisitNamespaceDeclaration((NamespaceDeclarationSyntax)unit, unit.SpanStart, inBody: true, inUsing: inUsing);
_binderFactoryVisitorPool.Free(visitor);
return result;
}
......@@ -151,7 +151,7 @@ internal InContainerBinder GetImportsBinder(CSharpSyntaxNode unit, bool inUsing
{
BinderFactoryVisitor visitor = _binderFactoryVisitorPool.Allocate();
visitor.Initialize(0, null, null);
var result = visitor.VisitCompilationUnit((CompilationUnitSyntax)unit, inUsing: inUsing, inScript: InScript);
InContainerBinder result = visitor.VisitCompilationUnit((CompilationUnitSyntax)unit, inUsing: inUsing, inScript: InScript);
_binderFactoryVisitorPool.Free(visitor);
return result;
}
......
......@@ -15,9 +15,9 @@ partial class Binder
{
private BoundExpression BindIsPatternExpression(IsPatternExpressionSyntax node, DiagnosticBag diagnostics)
{
var expression = BindValue(node.Expression, diagnostics, BindValueKind.RValue);
var hasErrors = IsOperandErrors(node, ref expression, diagnostics);
var expressionType = expression.Type;
BoundExpression expression = BindValue(node.Expression, diagnostics, BindValueKind.RValue);
bool hasErrors = IsOperandErrors(node, ref expression, diagnostics);
TypeSymbol expressionType = expression.Type;
if ((object)expressionType == null || expressionType.SpecialType == SpecialType.System_Void)
{
expressionType = CreateErrorType();
......@@ -29,7 +29,7 @@ private BoundExpression BindIsPatternExpression(IsPatternExpressionSyntax node,
}
}
var pattern = BindPattern(node.Pattern, expressionType, hasErrors, diagnostics);
BoundPattern pattern = BindPattern(node.Pattern, expressionType, hasErrors, diagnostics);
if (!hasErrors && pattern is BoundDeclarationPattern p && !p.IsVar && expression.ConstantValue == ConstantValue.Null)
{
diagnostics.Add(ErrorCode.WRN_IsAlwaysFalse, node.Location, p.DeclaredType.Type);
......@@ -84,7 +84,7 @@ internal virtual BoundExpression BindSwitchExpressionCore(SwitchExpressionSyntax
private BoundPattern BindDiscardPattern(DiscardPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics)
{
// TODO(patterns2): give an error if there is a bindable `_` in scope.
// PROTOTYPE(patterns2): give an error if there is a bindable `_` in scope.
return new BoundDiscardPattern(node);
}
......@@ -94,7 +94,7 @@ private BoundPattern BindDiscardPattern(DiscardPatternSyntax node, TypeSymbol op
bool hasErrors,
DiagnosticBag diagnostics)
{
var innerExpression = node.Expression.SkipParens();
SyntaxNode innerExpression = node.Expression.SkipParens();
if (innerExpression.Kind() == SyntaxKind.DefaultLiteralExpression)
{
diagnostics.Add(ErrorCode.ERR_DefaultPattern, innerExpression.Location);
......@@ -112,9 +112,9 @@ private BoundPattern BindDiscardPattern(DiscardPatternSyntax node, TypeSymbol op
DiagnosticBag diagnostics,
out bool wasExpression)
{
var expression = BindValue(patternExpression, diagnostics, BindValueKind.RValue);
BoundExpression expression = BindValue(patternExpression, diagnostics, BindValueKind.RValue);
ConstantValue constantValueOpt = null;
var convertedExpression = ConvertPatternExpression(operandType, patternExpression, expression, ref constantValueOpt, diagnostics);
BoundExpression convertedExpression = ConvertPatternExpression(operandType, patternExpression, expression, ref constantValueOpt, diagnostics);
wasExpression = expression.Type?.IsErrorType() != true;
if (!convertedExpression.HasErrors && constantValueOpt == null)
{
......@@ -135,7 +135,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
if (convertedExpression.Kind == BoundKind.Conversion)
{
var conversion = (BoundConversion)convertedExpression;
var operand = conversion.Operand;
BoundExpression operand = conversion.Operand;
if (inputType.IsNullableType() && (convertedExpression.ConstantValue == null || !convertedExpression.ConstantValue.IsNull))
{
// Null is a special case here because we want to compare null to the Nullable<T> itself, not to the underlying type.
......@@ -201,7 +201,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
var matchPossible = ExpressionOfTypeMatchesPatternType(Conversions, operandType, patternType, ref useSiteDiagnostics, out Conversion conversion, operandConstantValue: null, operandCouldBeNull: true);
bool? matchPossible = ExpressionOfTypeMatchesPatternType(Conversions, operandType, patternType, ref useSiteDiagnostics, out Conversion conversion, operandConstantValue: null, operandCouldBeNull: true);
diagnostics.Add(typeSyntax, useSiteDiagnostics);
if (matchPossible != false)
{
......@@ -252,7 +252,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
}
conversion = conversions.ClassifyConversionFromType(expressionType, patternType, ref useSiteDiagnostics);
var result = Binder.GetIsOperatorConstantResult(expressionType, patternType, conversion.Kind, operandConstantValue, operandCouldBeNull);
ConstantValue result = Binder.GetIsOperatorConstantResult(expressionType, patternType, conversion.Kind, operandConstantValue, operandCouldBeNull);
return
(result == null) ? (bool?)null :
(result == ConstantValue.True) ? true :
......@@ -266,9 +266,9 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
bool hasErrors,
DiagnosticBag diagnostics)
{
var typeSyntax = node.Type;
var boundDeclType = BindPatternType(typeSyntax, operandType, ref hasErrors, out bool isVar, diagnostics);
if (typeSyntax.ToString() == "var" && !isVar)
TypeSyntax typeSyntax = node.Type;
BoundTypeExpression boundDeclType = BindPatternType(typeSyntax, operandType, ref hasErrors, out bool isVar, diagnostics);
if (typeSyntax.IsVar && !isVar)
{
// 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.
......@@ -280,7 +280,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
boundDeclType = new BoundTypeExpression(typeSyntax, null, inferredType: true, type: operandType, hasErrors: true);
}
var declType = boundDeclType.Type;
TypeSymbol declType = boundDeclType.Type;
BindPatternDesignation(node, node.Designation, declType, typeSyntax, diagnostics, ref hasErrors, out Symbol variableSymbol, out BoundExpression variableAccess);
// PROTOTYPE(patterns2): We could bind the "var" declaration pattern as a var pattern in preparation for changing the parser to parse it as a var pattern.
// PROTOTYPE(patterns2): Eventually we will want to remove "isVar" from the declaration pattern.
......@@ -309,7 +309,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
declType = this.CreateErrorType("var");
}
var boundDeclType = new BoundTypeExpression(typeSyntax, aliasOpt, inferredType: isVar, type: declType);
BoundTypeExpression boundDeclType = new BoundTypeExpression(typeSyntax, aliasOpt, inferredType: isVar, type: declType);
if (IsOperatorErrors(typeSyntax, operandType, boundDeclType, diagnostics))
{
hasErrors = true;
......@@ -336,7 +336,7 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
switch (designation)
{
case SingleVariableDesignationSyntax singleVariableDesignation:
var identifier = singleVariableDesignation.Identifier;
SyntaxToken identifier = singleVariableDesignation.Identifier;
SourceLocalSymbol localSymbol = this.LookupLocal(identifier);
if (localSymbol != (object)null)
......@@ -412,7 +412,7 @@ TypeSymbol BindRecursivePatternType(TypeSyntax typeSyntax, TypeSymbol operandTyp
private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics)
{
var typeSyntax = node.Type;
TypeSyntax typeSyntax = node.Type;
TypeSymbol declType = BindRecursivePatternType(typeSyntax, operandType, ref hasErrors, out BoundTypeExpression boundDeclType, diagnostics);
var patterns = ArrayBuilder<BoundPattern>.GetInstance();
......@@ -420,7 +420,7 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
if (declType.IsTupleType)
{
// It is a tuple type. Work according to its elements
var elementTypes = declType.TupleElementTypes;
ImmutableArray<TypeSymbol> elementTypes = declType.TupleElementTypes;
if (elementTypes.Length != node.SubPatterns.Count && !hasErrors)
{
var location = new SourceLocation(node.SyntaxTree, new Text.TextSpan(node.OpenParenToken.SpanStart, node.CloseParenToken.Span.End - node.OpenParenToken.SpanStart));
......@@ -430,9 +430,9 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
for (int i = 0; i < node.SubPatterns.Count; i++)
{
bool isError = i >= elementTypes.Length;
var elementType = isError ? CreateErrorType() : elementTypes[i];
TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i];
// PROTOTYPE(patterns2): Check that node.SubPatterns[i].NameColon?.Name corresponds to tuple element i of declType.
var boundSubpattern = BindPattern(node.SubPatterns[i].Pattern, elementType, isError, diagnostics);
BoundPattern boundSubpattern = BindPattern(node.SubPatterns[i].Pattern, elementType, isError, diagnostics);
patterns.Add(boundSubpattern);
}
}
......@@ -440,7 +440,7 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
{
// It is not a tuple type. Seek an appropriate Deconstruct method.
var inputPlaceholder = new BoundImplicitReceiver(node, declType); // A fake receiver expression to permit us to reuse binding logic
var deconstruct = MakeDeconstructInvocationExpression(
BoundExpression deconstruct = MakeDeconstructInvocationExpression(
node.SubPatterns.Count, inputPlaceholder, node, diagnostics, out ImmutableArray<BoundDeconstructValuePlaceholder> outPlaceholders, requireTwoOrMoreElements: false);
deconstructMethod = deconstruct.ExpressionSymbol as MethodSymbol;
// PROTOTYPE(patterns2): Set and check the deconstructMethod
......@@ -448,11 +448,11 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
for (int i = 0; i < node.SubPatterns.Count; i++)
{
bool isError = outPlaceholders.IsDefaultOrEmpty || i >= outPlaceholders.Length;
var elementType = isError ? CreateErrorType() : outPlaceholders[i].Type;
TypeSymbol elementType = isError ? CreateErrorType() : outPlaceholders[i].Type;
// PROTOTYPE(patterns2): Check that node.SubPatterns[i].NameColon?.Name corresponds to parameter i of the method. Or,
// better yet, include those names in the AnalyzedArguments used in MakeDeconstructInvocationExpression so they are
// used to disambiguate.
var boundSubpattern = BindPattern(node.SubPatterns[i].Pattern, elementType, isError, diagnostics);
BoundPattern boundSubpattern = BindPattern(node.SubPatterns[i].Pattern, elementType, isError, diagnostics);
patterns.Add(boundSubpattern);
}
......@@ -474,7 +474,7 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
private BoundPattern BindVarPattern(VarPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics)
{
TypeSymbol declType = operandType;
var foundType = BindVarType(node.VarKeyword, diagnostics, out bool isVar, null);
Symbol foundType = BindVarType(node.VarKeyword, diagnostics, out bool isVar, null);
if (!isVar)
{
// Give an error if there is a bindable type "var" in scope
......@@ -511,7 +511,7 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
if (operandType.IsTupleType)
{
// It is a tuple type. Work according to its elements
var elementTypes = operandType.TupleElementTypes;
ImmutableArray<TypeSymbol> elementTypes = operandType.TupleElementTypes;
if (elementTypes.Length != tupleDesignation.Variables.Count && !hasErrors)
{
var location = new SourceLocation(node.SyntaxTree, new Text.TextSpan(tupleDesignation.OpenParenToken.SpanStart, tupleDesignation.CloseParenToken.Span.End - tupleDesignation.OpenParenToken.SpanStart));
......@@ -521,8 +521,8 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
for (int i = 0; i < tupleDesignation.Variables.Count; i++)
{
bool isError = i >= elementTypes.Length;
var elementType = isError ? CreateErrorType() : elementTypes[i];
var boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics);
TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i];
BoundPattern boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics);
patterns.Add(boundSubpattern);
}
}
......@@ -530,7 +530,7 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
{
// It is not a tuple type. Seek an appropriate Deconstruct method.
var inputPlaceholder = new BoundImplicitReceiver(node, operandType); // A fake receiver expression to permit us to reuse binding logic
var deconstruct = MakeDeconstructInvocationExpression(
BoundExpression deconstruct = MakeDeconstructInvocationExpression(
tupleDesignation.Variables.Count, inputPlaceholder, node, diagnostics, out ImmutableArray<BoundDeconstructValuePlaceholder> outPlaceholders, requireTwoOrMoreElements: false);
deconstructMethod = deconstruct.ExpressionSymbol as MethodSymbol;
// PROTOTYPE(patterns2): Set and check the deconstructMethod
......@@ -538,8 +538,8 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
for (int i = 0; i < tupleDesignation.Variables.Count; i++)
{
bool isError = outPlaceholders.IsDefaultOrEmpty || i >= outPlaceholders.Length;
var elementType = isError ? CreateErrorType() : outPlaceholders[i].Type;
var boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics);
TypeSymbol elementType = isError ? CreateErrorType() : outPlaceholders[i].Type;
BoundPattern boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics);
patterns.Add(boundSubpattern);
}
......@@ -559,7 +559,7 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol operandType, bool hasErrors, DiagnosticBag diagnostics)
{
var typeSyntax = node.Type;
TypeSyntax typeSyntax = node.Type;
TypeSymbol declType = BindRecursivePatternType(typeSyntax, operandType, ref hasErrors, out BoundTypeExpression boundDeclType, diagnostics);
ImmutableArray<(Symbol property, BoundPattern pattern)> propertiesOpt = BindPropertySubpattern(node.PropertySubpattern, declType, diagnostics, ref hasErrors);
BindPatternDesignation(node, node.Designation, declType, typeSyntax, diagnostics, ref hasErrors, out Symbol variableSymbol, out BoundExpression variableAccess);
......@@ -575,10 +575,10 @@ private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol
ref bool hasErrors)
{
var builder = ArrayBuilder<(Symbol property, BoundPattern pattern)>.GetInstance();
foreach (var p in node.SubPatterns)
foreach (SubpatternElementSyntax p in node.SubPatterns)
{
var name = p.NameColon?.Name;
var pattern = p.Pattern;
IdentifierNameSyntax name = p.NameColon?.Name;
PatternSyntax pattern = p.Pattern;
Symbol property = null;
TypeSymbol propertyType;
if (name == null)
......@@ -596,7 +596,7 @@ private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol
property = LookupPropertyForPattern(inputType, name, out propertyType, ref hasErrors, diagnostics);
}
var boundPattern = BindPattern(pattern, propertyType, hasErrors, diagnostics);
BoundPattern boundPattern = BindPattern(pattern, propertyType, hasErrors, diagnostics);
builder.Add((property, boundPattern));
}
......@@ -605,7 +605,7 @@ private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol
private Symbol LookupPropertyForPattern(TypeSymbol inputType, IdentifierNameSyntax name, out TypeSymbol propertyType, ref bool hasErrors, DiagnosticBag diagnostics)
{
var symbol = BindPropertyPatternMember(inputType, name, ref hasErrors, diagnostics);
Symbol symbol = BindPropertyPatternMember(inputType, name, ref hasErrors, diagnostics);
if (inputType.IsErrorType() || hasErrors)
{
......
......@@ -316,7 +316,7 @@ out ImmutableArray<(BoundExpression, BoundDagTemp)> bindings)
}
else
{
// TODO(patterns2): This should not occur except in error cases. Perhaps this will be used to handle the ITuple case.
// PROTOTYPE(patterns2): This should not occur except in error cases. Perhaps this will be used to handle the ITuple case.
Debug.Assert(recursive.HasAnyErrors);
}
}
......
......@@ -75,7 +75,7 @@ public override void VisitSwitchExpression(SwitchExpressionSyntax node)
public override void VisitSwitchExpressionArm(SwitchExpressionArmSyntax node)
{
var previousNodeToBind = _nodeToBind;
SyntaxNode previousNodeToBind = _nodeToBind;
_nodeToBind = node;
Visit(node.Pattern);
Visit(node.WhenClause?.Condition);
......@@ -87,7 +87,7 @@ public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
{
if (node.ArgumentList != null)
{
foreach (var arg in node.ArgumentList.Arguments)
foreach (ArgumentSyntax arg in node.ArgumentList.Arguments)
{
Visit(arg.Expression);
}
......@@ -98,7 +98,7 @@ public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
private void VisitNodeToBind(CSharpSyntaxNode node)
{
var previousNodeToBind = _nodeToBind;
SyntaxNode previousNodeToBind = _nodeToBind;
_nodeToBind = node;
Visit(node);
_nodeToBind = previousNodeToBind;
......@@ -112,7 +112,7 @@ private void VisitNodeToBind(CSharpSyntaxNode node)
ArrayBuilder<TFieldOrLocalSymbol> save = _variablesBuilder;
_variablesBuilder = builder;
foreach (var n in nodes)
foreach (ExpressionSyntax n in nodes)
{
VisitNodeToBind(n);
}
......@@ -132,14 +132,14 @@ public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node
public override void VisitSwitchSection(SwitchSectionSyntax node)
{
foreach (var label in node.Labels)
foreach (SwitchLabelSyntax label in node.Labels)
{
switch (label.Kind())
{
case SyntaxKind.CasePatternSwitchLabel:
{
var switchLabel = (CasePatternSwitchLabelSyntax)label;
var previousNodeToBind = _nodeToBind;
SyntaxNode previousNodeToBind = _nodeToBind;
_nodeToBind = switchLabel;
Visit(switchLabel.Pattern);
if (switchLabel.WhenClause != null)
......@@ -164,7 +164,7 @@ public override void VisitAttribute(AttributeSyntax node)
{
if (node.ArgumentList != null)
{
foreach (var argument in node.ArgumentList.Arguments)
foreach (AttributeArgumentSyntax argument in node.ArgumentList.Arguments)
{
VisitNodeToBind(argument.Expression);
}
......@@ -210,7 +210,7 @@ public override void VisitDeclarationPattern(DeclarationPatternSyntax node)
{
if (node.Designation?.Kind() == SyntaxKind.SingleVariableDesignation)
{
var variable = MakePatternVariable(node.Type, (SingleVariableDesignationSyntax)node.Designation, _nodeToBind);
TFieldOrLocalSymbol variable = MakePatternVariable(node.Type, (SingleVariableDesignationSyntax)node.Designation, _nodeToBind);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -236,7 +236,7 @@ private void VisitPatternDesignation(VariableDesignationSyntax node)
switch (node.Kind())
{
case SyntaxKind.SingleVariableDesignation:
var variable = MakePatternVariable(null, (SingleVariableDesignationSyntax)node, _nodeToBind);
TFieldOrLocalSymbol variable = MakePatternVariable(null, (SingleVariableDesignationSyntax)node, _nodeToBind);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -258,7 +258,7 @@ private void VisitPatternDesignation(VariableDesignationSyntax node)
public override void VisitDeconstructionPattern(DeconstructionPatternSyntax node)
{
var variable = MakePatternVariable(node, _nodeToBind);
TFieldOrLocalSymbol variable = MakePatternVariable(node, _nodeToBind);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -269,7 +269,7 @@ public override void VisitDeconstructionPattern(DeconstructionPatternSyntax node
public override void VisitPropertyPattern(PropertyPatternSyntax node)
{
var variable = MakePatternVariable(node, _nodeToBind);
TFieldOrLocalSymbol variable = MakePatternVariable(node, _nodeToBind);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -298,7 +298,7 @@ public override void VisitQueryBody(QueryBodySyntax node)
{
// Variables declared in [in] expressions of top level from clause and
// join clauses are in scope
foreach (var clause in node.Clauses)
foreach (QueryClauseSyntax clause in node.Clauses)
{
if (clause.Kind() == SyntaxKind.JoinClause)
{
......@@ -348,7 +348,7 @@ private void VisitDeclarationExpressionDesignation(DeclarationExpressionSyntax n
switch (designation.Kind())
{
case SyntaxKind.SingleVariableDesignation:
var variable = MakeDeclarationExpressionVariable(node, (SingleVariableDesignationSyntax)designation, argumentListSyntaxOpt, _nodeToBind);
TFieldOrLocalSymbol variable = MakeDeclarationExpressionVariable(node, (SingleVariableDesignationSyntax)designation, argumentListSyntaxOpt, _nodeToBind);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -393,7 +393,7 @@ public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
case SyntaxKind.TupleExpression:
{
var tuple = (TupleExpressionSyntax)possibleTupleDeclaration;
foreach (var arg in tuple.Arguments)
foreach (ArgumentSyntax arg in tuple.Arguments)
{
CollectVariablesFromDeconstruction(arg.Expression, deconstruction);
}
......@@ -423,7 +423,7 @@ public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
case SyntaxKind.SingleVariableDesignation:
{
var single = (SingleVariableDesignationSyntax)designation;
var variable = MakeDeconstructionVariable(closestTypeSyntax, single, deconstruction);
TFieldOrLocalSymbol variable = MakeDeconstructionVariable(closestTypeSyntax, single, deconstruction);
if ((object)variable != null)
{
_variablesBuilder.Add(variable);
......@@ -433,7 +433,7 @@ public override void VisitAssignmentExpression(AssignmentExpressionSyntax node)
case SyntaxKind.ParenthesizedVariableDesignation:
{
var tuple = (ParenthesizedVariableDesignationSyntax)designation;
foreach (var d in tuple.Variables)
foreach (VariableDesignationSyntax d in tuple.Variables)
{
CollectVariablesFromDeconstruction(d, closestTypeSyntax, deconstruction);
}
......@@ -480,7 +480,7 @@ internal class ExpressionVariableFinder : ExpressionVariableFinder<LocalSymbol>
return;
}
var finder = s_poolInstance.Allocate();
ExpressionVariableFinder finder = s_poolInstance.Allocate();
finder._scopeBinder = scopeBinder;
finder._enclosingBinder = enclosingBinderOpt ?? scopeBinder;
......@@ -501,7 +501,7 @@ internal class ExpressionVariableFinder : ExpressionVariableFinder<LocalSymbol>
return;
}
var finder = s_poolInstance.Allocate();
ExpressionVariableFinder finder = s_poolInstance.Allocate();
finder._scopeBinder = binder;
finder._enclosingBinder = binder;
......@@ -629,7 +629,7 @@ internal class ExpressionFieldFinder : ExpressionVariableFinder<Symbol>
return;
}
var finder = s_poolInstance.Allocate();
ExpressionFieldFinder finder = s_poolInstance.Allocate();
finder._containingType = containingType;
finder._modifiers = modifiers;
finder._containingFieldOpt = containingFieldOpt;
......
......@@ -208,7 +208,7 @@ public override void VisitLocalFunctionStatement(LocalFunctionStatementSyntax no
if (possibleScopeBinder != null)
{
foreach (var candidate in possibleScopeBinder.LocalFunctions)
foreach (LocalFunctionSymbol candidate in possibleScopeBinder.LocalFunctions)
{
if (candidate.Locations[0] == node.Identifier.GetLocation())
{
......@@ -222,7 +222,7 @@ public override void VisitLocalFunctionStatement(LocalFunctionStatementSyntax no
if (match != null)
{
var oldMethod = _containingMemberOrLambda;
Symbol oldMethod = _containingMemberOrLambda;
_containingMemberOrLambda = match;
if (body != null)
......@@ -278,7 +278,7 @@ public override void VisitAttribute(AttributeSyntax node)
if (node.ArgumentList?.Arguments.Count > 0)
{
foreach (var argument in node.ArgumentList.Arguments)
foreach (AttributeArgumentSyntax argument in node.ArgumentList.Arguments)
{
Visit(argument.Expression, attrBinder);
}
......@@ -294,7 +294,7 @@ public override void VisitArgumentList(ArgumentListSyntax node)
var argBinder = new ExpressionVariableBinder(node, _enclosing);
AddToMap(node, argBinder);
foreach (var arg in node.Arguments)
foreach (ArgumentSyntax arg in node.Arguments)
{
Visit(arg.Expression, argBinder);
}
......@@ -389,17 +389,17 @@ public override void VisitForStatement(ForStatementSyntax node)
Binder binder = new ForLoopBinder(_enclosing, node);
AddToMap(node, binder);
var declaration = node.Declaration;
VariableDeclarationSyntax declaration = node.Declaration;
if (declaration != null)
{
foreach (var variable in declaration.Variables)
foreach (VariableDeclaratorSyntax variable in declaration.Variables)
{
Visit(variable, binder);
}
}
else
{
foreach (var initializer in node.Initializers)
foreach (ExpressionSyntax initializer in node.Initializers)
{
Visit(initializer, binder);
}
......@@ -418,7 +418,7 @@ public override void VisitForStatement(ForStatementSyntax node)
{
var incrementorsBinder = new ExpressionListVariableBinder(incrementors, binder);
AddToMap(incrementors.First(), incrementorsBinder);
foreach (var incrementor in incrementors)
foreach (ExpressionSyntax incrementor in incrementors)
{
Visit(incrementor, incrementorsBinder);
}
......@@ -453,7 +453,7 @@ public override void VisitForEachVariableStatement(ForEachVariableStatementSynta
public override void VisitCheckedStatement(CheckedStatementSyntax node)
{
var binder = _enclosing.WithCheckedOrUncheckedRegion(@checked: node.Kind() == SyntaxKind.CheckedStatement);
Binder binder = _enclosing.WithCheckedOrUncheckedRegion(@checked: node.Kind() == SyntaxKind.CheckedStatement);
AddToMap(node, binder);
Visit(node.Block, binder);
......@@ -461,7 +461,7 @@ public override void VisitCheckedStatement(CheckedStatementSyntax node)
public override void VisitUnsafeStatement(UnsafeStatementSyntax node)
{
var binder = _enclosing.WithAdditionalFlags(BinderFlags.UnsafeRegion);
Binder binder = _enclosing.WithAdditionalFlags(BinderFlags.UnsafeRegion);
AddToMap(node, binder);
Visit(node.Block, binder); // This will create the block binder for the block.
......@@ -492,7 +492,7 @@ public override void VisitLockStatement(LockStatementSyntax node)
Visit(node.Expression, lockBinder);
StatementSyntax statement = node.Statement;
var statementBinder = lockBinder.WithAdditionalFlags(BinderFlags.InLockBody);
Binder statementBinder = lockBinder.WithAdditionalFlags(BinderFlags.InLockBody);
if (statementBinder != lockBinder)
{
AddToMap(statement, statementBinder);
......@@ -521,7 +521,7 @@ public override void VisitSwitchSection(SwitchSectionSyntax node)
var patternBinder = new ExpressionVariableBinder(node, _enclosing);
AddToMap(node, patternBinder);
foreach (var label in node.Labels)
foreach (SwitchLabelSyntax label in node.Labels)
{
switch (label.Kind())
{
......@@ -555,7 +555,7 @@ public override void VisitSwitchExpression(SwitchExpressionSyntax node)
var switchExpressionBinder = new SwitchExpressionBinder(node, _enclosing);
AddToMap(node, switchExpressionBinder);
Visit(node.GoverningExpression, switchExpressionBinder);
foreach (var arm in node.Arms)
foreach (SwitchExpressionArmSyntax arm in node.Arms)
{
var armScopeBinder = new ExpressionVariableBinder(arm, switchExpressionBinder);
var armBinder = new SwitchExpressionArmBinder(arm, armScopeBinder, switchExpressionBinder);
......@@ -602,7 +602,7 @@ public override void VisitTryStatement(TryStatementSyntax node)
Visit(node.Block, _enclosing);
}
foreach (var c in node.Catches)
foreach (CatchClauseSyntax c in node.Catches)
{
Visit(c, _enclosing);
}
......@@ -621,7 +621,7 @@ public override void VisitCatchClause(CatchClauseSyntax node)
if (node.Filter != null)
{
var filterBinder = clauseBinder.WithAdditionalFlags(BinderFlags.InCatchFilter);
Binder filterBinder = clauseBinder.WithAdditionalFlags(BinderFlags.InCatchFilter);
AddToMap(node.Filter, filterBinder);
Visit(node.Filter, filterBinder);
}
......@@ -675,7 +675,7 @@ public override void VisitExpressionStatement(ExpressionStatementSyntax node)
public override void VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
{
foreach (var decl in node.Declaration.Variables)
foreach (VariableDeclaratorSyntax decl in node.Declaration.Variables)
{
Visit(decl);
}
......@@ -822,7 +822,7 @@ public override void VisitQueryExpression(QueryExpressionSyntax node)
public override void VisitQueryBody(QueryBodySyntax node)
{
foreach (var clause in node.Clauses)
foreach (QueryClauseSyntax clause in node.Clauses)
{
if (clause.Kind() == SyntaxKind.JoinClause)
{
......
......@@ -46,18 +46,18 @@ internal override BoundStatement BindSwitchStatementCore(SwitchStatementSyntax n
Debug.Assert(SwitchSyntax.Equals(node));
// Bind switch expression and set the switch governing type.
var boundSwitchGoverningExpression = SwitchGoverningExpression;
BoundExpression boundSwitchGoverningExpression = SwitchGoverningExpression;
diagnostics.AddRange(SwitchGoverningDiagnostics);
ImmutableArray<BoundPatternSwitchSection> switchSections = BindPatternSwitchSections(originalBinder, diagnostics, out BoundPatternSwitchLabel defaultLabel);
var locals = GetDeclaredLocalsForScope(node);
var functions = GetDeclaredLocalFunctionsForScope(node);
ImmutableArray<LocalSymbol> locals = GetDeclaredLocalsForScope(node);
ImmutableArray<LocalFunctionSymbol> functions = GetDeclaredLocalFunctionsForScope(node);
BoundDecisionDag decisionDag = new DecisionDagBuilder(this.Compilation).CreateDecisionDag(
syntax: node,
switchExpression: boundSwitchGoverningExpression,
switchSections: switchSections,
defaultLabel: defaultLabel?.Label ?? BreakLabel);
var hasErrors = CheckSwitchErrors(node, boundSwitchGoverningExpression, switchSections, decisionDag, diagnostics);
bool hasErrors = CheckSwitchErrors(node, boundSwitchGoverningExpression, switchSections, decisionDag, diagnostics);
return new BoundPatternSwitchStatement2(
syntax: node,
expression: boundSwitchGoverningExpression,
......@@ -78,10 +78,10 @@ internal override BoundStatement BindSwitchStatementCore(SwitchStatementSyntax n
DiagnosticBag diagnostics)
{
bool reported = false;
var reachableLabels = decisionDag.ReachableLabels;
foreach (var section in switchSections)
HashSet<LabelSymbol> reachableLabels = decisionDag.ReachableLabels;
foreach (BoundPatternSwitchSection section in switchSections)
{
foreach (var label in section.SwitchLabels)
foreach (BoundPatternSwitchLabel label in section.SwitchLabels)
{
if (!label.HasErrors && !reachableLabels.Contains(label.Label))
{
......@@ -129,9 +129,9 @@ internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabel
// Bind match sections
var boundPatternSwitchSectionsBuilder = ArrayBuilder<BoundPatternSwitchSection>.GetInstance();
defaultLabel = null;
foreach (var sectionSyntax in SwitchSyntax.Sections)
foreach (SwitchSectionSyntax sectionSyntax in SwitchSyntax.Sections)
{
var section = BindPatternSwitchSection(sectionSyntax, originalBinder, ref defaultLabel, diagnostics);
BoundPatternSwitchSection section = BindPatternSwitchSection(sectionSyntax, originalBinder, ref defaultLabel, diagnostics);
boundPatternSwitchSectionsBuilder.Add(section);
}
......@@ -149,11 +149,11 @@ internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabel
{
// Bind match section labels
var boundLabelsBuilder = ArrayBuilder<BoundPatternSwitchLabel>.GetInstance();
var sectionBinder = originalBinder.GetBinder(node); // this binder can bind pattern variables from the section.
Binder sectionBinder = originalBinder.GetBinder(node); // this binder can bind pattern variables from the section.
Debug.Assert(sectionBinder != null);
var labelsByNode = LabelsByNode;
Dictionary<SyntaxNode, LabelSymbol> labelsByNode = LabelsByNode;
foreach (var labelSyntax in node.Labels)
foreach (SwitchLabelSyntax labelSyntax in node.Labels)
{
LabelSymbol label = labelsByNode[labelSyntax];
BoundPatternSwitchLabel boundLabel = BindPatternSwitchSectionLabel(sectionBinder, labelSyntax, label, ref defaultLabel, diagnostics);
......@@ -162,7 +162,7 @@ internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabel
// Bind switch section statements
var boundStatementsBuilder = ArrayBuilder<BoundStatement>.GetInstance();
foreach (var statement in node.Statements)
foreach (StatementSyntax statement in node.Statements)
{
boundStatementsBuilder.Add(sectionBinder.BindStatement(statement, diagnostics));
}
......@@ -187,10 +187,10 @@ internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabel
{
var caseLabelSyntax = (CaseSwitchLabelSyntax)node;
bool wasExpression;
var pattern = sectionBinder.BindConstantPattern(
BoundConstantPattern pattern = sectionBinder.BindConstantPattern(
node, SwitchGoverningType, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression);
bool hasErrors = pattern.HasErrors;
var constantValue = pattern.ConstantValue;
ConstantValue constantValue = pattern.ConstantValue;
if (!hasErrors &&
(object)constantValue != null &&
pattern.Value.Type == SwitchGoverningType &&
......@@ -227,7 +227,7 @@ internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabel
case SyntaxKind.CasePatternSwitchLabel:
{
var matchLabelSyntax = (CasePatternSwitchLabelSyntax)node;
var pattern = sectionBinder.BindPattern(
BoundPattern pattern = sectionBinder.BindPattern(
matchLabelSyntax.Pattern, SwitchGoverningType, node.HasErrors, diagnostics);
return new BoundPatternSwitchLabel(node, label, pattern,
matchLabelSyntax.WhenClause != null ? sectionBinder.BindBooleanExpression(matchLabelSyntax.WhenClause.Condition, diagnostics) : null,
......
......@@ -9102,7 +9102,7 @@ private ExpressionSyntax ParseSubExpressionCore(Precedence precedence)
else if (tk == SyntaxKind.SwitchKeyword && precedence < Precedence.Coalescing)
{
// TODO(patterns2): for better error recovery when an expression is typed on a line before
// PROTOTYPE(patterns2): for better error recovery when an expression is typed on a line before
// a switch statement, we should check if the cases between the parens look like cases with
// arrows, and whether the
// switch keyword is on the same line as the end of the expression. If those are not satisfied,
......@@ -9112,7 +9112,7 @@ private ExpressionSyntax ParseSubExpressionCore(Precedence precedence)
var switchKeyword = this.EatToken();
var openBrace = this.EatToken(SyntaxKind.OpenBraceToken);
var arms = this.ParseSwitchExpressionArms();
// TODO(patterns2): Should skip any unexpected tokens up through the close brace token.
// PROTOTYPE(patterns2): Should skip any unexpected tokens up through the close brace token.
var closeBrace = this.EatToken(SyntaxKind.CloseBraceToken);
leftOperand = _syntaxFactory.SwitchExpression(governingExpression, switchKeyword, openBrace, arms, closeBrace);
leftOperand = this.CheckFeatureAvailability(leftOperand, MessageID.IDS_FeatureRecursivePatterns);
......@@ -9123,7 +9123,7 @@ private ExpressionSyntax ParseSubExpressionCore(Precedence precedence)
private SeparatedSyntaxList<SwitchExpressionArmSyntax> ParseSwitchExpressionArms()
{
// TODO(patterns2): Error recovery here leaves much to be desired.
// PROTOTYPE(patterns2): Error recovery here leaves much to be desired.
var arms = _pool.AllocateSeparated<SwitchExpressionArmSyntax>();
do
{
......
......@@ -237,7 +237,7 @@ private bool ScanDesignation(bool permitTuple)
default:
return false;
case SyntaxKind.IdentifierToken:
var result = this.IsTrueIdentifier();
bool result = this.IsTrueIdentifier();
this.EatToken();
return result;
case SyntaxKind.OpenParenToken:
......@@ -335,7 +335,7 @@ private CSharpSyntaxNode ParseExpressionOrPattern(bool forCase, Precedence prece
// type of a declaration or recursive pattern, nor as a type in an in-type expression starting
// in C# 7. The binder will give a diagnostic if
// there is a usable symbol in scope by that name. You can always escape it, using `@_`.
// TODO(patterns2): Should we use the "contextual keyword" infrastructure for this?
// PROTOTYPE(patterns2): Should we use the "contextual keyword" infrastructure for this?
return _syntaxFactory.DiscardPattern(this.EatToken(SyntaxKind.IdentifierToken));
}
......@@ -414,7 +414,7 @@ bool looksLikeCast()
{
// we have a "var" pattern; "var" is not permitted to be a stand-in for a type (or a constant) in a pattern.
var varToken = ConvertToKeyword(typeIdentifierToken);
var wasTupleDesignator = this.CurrentToken.Kind == SyntaxKind.OpenParenToken;
bool wasTupleDesignator = this.CurrentToken.Kind == SyntaxKind.OpenParenToken;
var varDesignation = ParseDesignation();
if (wasTupleDesignator)
{
......
......@@ -311,7 +311,7 @@ public bool IsVar
if (_typeSyntax.IsVar)
{
TypeSymbol declType = this.TypeSyntaxBinder.BindType(_typeSyntax, new DiagnosticBag(), out var isVar);
TypeSymbol declType = this.TypeSyntaxBinder.BindType(_typeSyntax, new DiagnosticBag(), out bool isVar);
return isVar;
}
......@@ -528,7 +528,7 @@ private sealed class LocalWithInitializer : SourceLocalSymbol
protected override TypeSymbol InferTypeOfVarVariable(DiagnosticBag diagnostics)
{
var initializerOpt = this._initializerBinder.BindInferredVariableInitializer(diagnostics, RefKind, _initializer, _initializer);
BoundExpression initializerOpt = this._initializerBinder.BindInferredVariableInitializer(diagnostics, RefKind, _initializer, _initializer);
return initializerOpt?.Type;
}
......@@ -545,10 +545,10 @@ private void MakeConstantTuple(LocalSymbol inProgress, BoundExpression boundInit
if (this.IsConst && _constantTuple == null)
{
var value = Microsoft.CodeAnalysis.ConstantValue.Bad;
var initValueNodeLocation = _initializer.Value.Location;
Location initValueNodeLocation = _initializer.Value.Location;
var diagnostics = DiagnosticBag.GetInstance();
Debug.Assert(inProgress != this);
var type = this.Type;
TypeSymbol type = this.Type;
if (boundInitValue == null)
{
var inProgressBinder = new LocalInProgressBinder(this, this._initializerBinder);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册