From a825162665d17049b785da5b3d6b2fb49dc6ed12 Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Wed, 20 Sep 2017 13:32:30 -0700 Subject: [PATCH] addressed PR feedbacks --- .../CSharp/Portable/BoundTree/Expression.cs | 10 ++----- .../Compilation/MemberSemanticModel.cs | 27 +++++++------------ .../Operations/CSharpOperationFactory.cs | 7 ++--- .../CSharpOperationFactory_Methods.cs | 6 ++--- 4 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Compilers/CSharp/Portable/BoundTree/Expression.cs b/src/Compilers/CSharp/Portable/BoundTree/Expression.cs index 0232a3e639f..c14f0cdfbd8 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Expression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Expression.cs @@ -141,13 +141,7 @@ internal partial class BoundSequence internal partial class BoundStatementList { - protected override ImmutableArray Children - { - get - { - System.Diagnostics.Debug.Assert(this.Kind == BoundKind.StatementList || this.Kind == BoundKind.Scope); - return StaticCast.From(this.Statements); - } - } + protected override ImmutableArray Children => + (this.Kind == BoundKind.StatementList || this.Kind == BoundKind.Scope) ? StaticCast.From(this.Statements) : ImmutableArray.Empty; } } diff --git a/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs b/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs index 655666816c2..2cd7d960ef5 100644 --- a/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs +++ b/src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs @@ -980,38 +980,34 @@ private CSharpSyntaxNode GetBindingRootOrInitializer(CSharpSyntaxNode node) // if binding root is parameter, make it equal value // we need to do this since node map doesn't contain bound node for parameter - var parameter = bindingRoot as ParameterSyntax; - if (parameter != null && parameter.Default?.FullSpan.Contains(node.Span) == true) + if (bindingRoot is ParameterSyntax parameter && parameter.Default?.FullSpan.Contains(node.Span) == true) { - bindingRoot = parameter.Default; + return parameter.Default; } // if binding root is field variable declarator, make it initializer // we need to do this since node map doesn't contain bound node for field/event variable declarator - var variableDeclarator = bindingRoot as VariableDeclaratorSyntax; - if (variableDeclarator != null && variableDeclarator.Initializer?.FullSpan.Contains(node.Span) == true) + if (bindingRoot is VariableDeclaratorSyntax variableDeclarator && variableDeclarator.Initializer?.FullSpan.Contains(node.Span) == true) { if (variableDeclarator.Parent?.Parent.IsKind(SyntaxKind.FieldDeclaration) == true || variableDeclarator.Parent?.Parent.IsKind(SyntaxKind.EventFieldDeclaration) == true) { - bindingRoot = variableDeclarator.Initializer; + return variableDeclarator.Initializer; } } // if binding root is enum member decleration, make it equal value // we need to do this since node map doesn't contain bound node for enum member decl - var enumMember = bindingRoot as EnumMemberDeclarationSyntax; - if (enumMember != null && enumMember.EqualsValue?.FullSpan.Contains(node.Span) == true) + if (bindingRoot is EnumMemberDeclarationSyntax enumMember && enumMember.EqualsValue?.FullSpan.Contains(node.Span) == true) { - bindingRoot = enumMember.EqualsValue; + return enumMember.EqualsValue; } // if binding root is property member decleration, make it equal value // we need to do this since node map doesn't contain bound node for property initializer - var propertyMember = bindingRoot as PropertyDeclarationSyntax; - if (propertyMember != null && propertyMember.Initializer?.FullSpan.Contains(node.Span) == true) + if (bindingRoot is PropertyDeclarationSyntax propertyMember && propertyMember.Initializer?.FullSpan.Contains(node.Span) == true) { - bindingRoot = propertyMember.Initializer; + return propertyMember.Initializer; } return bindingRoot; @@ -1336,8 +1332,6 @@ private CSharpSyntaxNode GetBindingRoot(CSharpSyntaxNode node) { Debug.Assert(node != null); - StatementSyntax enclosingStatement = null; - #if DEBUG for (CSharpSyntaxNode current = node; current != this.Root; current = current.ParentOrStructuredTriviaParent) { @@ -1348,10 +1342,9 @@ private CSharpSyntaxNode GetBindingRoot(CSharpSyntaxNode node) for (CSharpSyntaxNode current = node; current != this.Root; current = current.ParentOrStructuredTriviaParent) { - enclosingStatement = current as StatementSyntax; - if (enclosingStatement != null) + if (current is StatementSyntax) { - return enclosingStatement; + return current; } } diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs index a9d33db709b..6dcd57ba9aa 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs @@ -241,13 +241,14 @@ private IOperation CreateInternal(BoundNode boundNode) private ImmutableArray GetIOperationChildren(BoundNode boundNode) { var boundNodeWithChildren = (IBoundNodeWithIOperationChildren)boundNode; - if (boundNodeWithChildren.Children.IsDefaultOrEmpty) + var children = boundNodeWithChildren.Children; + if (children.IsDefaultOrEmpty) { return ImmutableArray.Empty; } - var builder = ArrayBuilder.GetInstance(boundNodeWithChildren.Children.Length); - foreach (BoundNode childNode in boundNodeWithChildren.Children) + var builder = ArrayBuilder.GetInstance(children.Length); + foreach (BoundNode childNode in children) { IOperation operation = Create(childNode); if (operation == null) diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs index 5ef17328414..f25bcddc9e3 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs @@ -38,17 +38,17 @@ internal IArgument CreateArgumentOperation(ArgumentKind kind, IParameterSymbol p var value = Create(expression); // put argument syntax to argument operation - var argumentExist = value.Syntax?.Parent is ArgumentSyntax; + var argument = value.Syntax?.Parent as ArgumentSyntax; // if argument syntax doesn't exist, this operation is implicit return new CSharpArgument(kind, parameter, value, semanticModel: _semanticModel, - syntax: argumentExist ? value.Syntax.Parent : value.Syntax, + syntax: argument ?? value.Syntax, type: value.Type, constantValue: default, - isImplicit: expression.WasCompilerGenerated || !argumentExist); + isImplicit: expression.WasCompilerGenerated || argument == null); } private IVariableDeclaration CreateVariableDeclaration(BoundLocalDeclaration boundLocalDeclaration, SyntaxNode syntax) -- GitLab