Skip to content

Commit

Permalink
Moving IsDeconstructionDeclarationLeft method
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Nov 8, 2016
1 parent d5bede6 commit 7e4ea6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
24 changes: 1 addition & 23 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7541,7 +7541,7 @@ private StatementSyntax ParseEmbeddedStatement(bool complexCheck)
if (expression.Kind == SyntaxKind.SimpleAssignmentExpression)
{
var assignment = (AssignmentExpressionSyntax)expression;
if (IsDeconstructionDeclarationLeft(assignment.Left))
if (assignment.Left.IsDeconstructionDeclarationLeft())
{
statement = this.AddError(statement, ErrorCode.ERR_BadEmbeddedStmt);
}
Expand Down Expand Up @@ -8667,28 +8667,6 @@ private static bool TypeFoundInDeconstructionDeclarationVariables(ExpressionSynt
}
}

/// <summary>
/// Returns true if the expression is composed only of nested tuple and declaration expressions.
/// </summary>
private static bool IsDeconstructionDeclarationLeft(ExpressionSyntax node)
{
switch (node.Kind)
{
case SyntaxKind.TupleExpression:
var arguments = ((TupleExpressionSyntax)node).Arguments;
for (int i = 0; i < arguments.Count; i++)
{
if (!IsDeconstructionDeclarationLeft(arguments[i].Expression)) return false;
}

return true;
case SyntaxKind.DeclarationExpression:
return true;
default:
return false;
}
}

private VariableDesignationSyntax ParseDeconstructionDesignation(bool topLevel = false)
{
// the two forms of designation are
Expand Down
22 changes: 22 additions & 0 deletions src/Compilers/CSharp/Portable/Syntax/SyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ private static bool IsDeconstructionDeclarationLeft(this ExpressionSyntax self)
}
}

/// <summary>
/// Returns true if the expression is composed only of nested tuple and declaration expressions.
/// </summary>
internal static bool IsDeconstructionDeclarationLeft(this Syntax.InternalSyntax.ExpressionSyntax node)
{
switch (node.Kind)
{
case SyntaxKind.TupleExpression:
var arguments = ((Syntax.InternalSyntax.TupleExpressionSyntax)node).Arguments;
for (int i = 0; i < arguments.Count; i++)
{
if (!IsDeconstructionDeclarationLeft(arguments[i].Expression)) return false;
}

return true;
case SyntaxKind.DeclarationExpression:
return true;
default:
return false;
}
}

internal static bool IsDeconstructionDeclaration(this AssignmentExpressionSyntax self)
{
return self.Left.IsDeconstructionDeclarationLeft();
Expand Down

0 comments on commit 7e4ea6e

Please sign in to comment.