-
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
Add IOperation support for ILocalFunctionStatement #20177
Changes from 2 commits
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 |
---|---|---|
|
@@ -171,6 +171,8 @@ private static IOperation CreateInternal(BoundNode boundNode) | |
return CreateBoundInterpolatedStringExpressionOperation((BoundInterpolatedString)boundNode); | ||
case BoundKind.StringInsert: | ||
return CreateBoundInterpolationOperation((BoundStringInsert)boundNode); | ||
case BoundKind.LocalFunctionStatement: | ||
return CreateBoundLocalFunctionStatementOperation((BoundLocalFunctionStatement)boundNode); | ||
default: | ||
var constantValue = ConvertToOptional((boundNode as BoundExpression)?.ConstantValue); | ||
return Operation.CreateOperationNone(boundNode.HasErrors, boundNode.Syntax, constantValue, getChildren: () => GetIOperationChildren(boundNode)); | ||
|
@@ -382,6 +384,17 @@ private static ILambdaExpression CreateBoundLambdaOperation(BoundLambda boundLam | |
return new LazyLambdaExpression(signature, body, isInvalid, syntax, type, constantValue); | ||
} | ||
|
||
private static ILocalFunctionStatement CreateBoundLocalFunctionStatementOperation(BoundLocalFunctionStatement boundLocalFunctionStatement) | ||
{ | ||
IMethodSymbol localFunctionSymbol = boundLocalFunctionStatement.Symbol; | ||
Lazy<IBlockStatement> body = new Lazy<IBlockStatement>(() => (IBlockStatement)Create(boundLocalFunctionStatement.Body)); | ||
bool isInvalid = boundLocalFunctionStatement.HasErrors; | ||
SyntaxNode syntax = boundLocalFunctionStatement.Syntax; | ||
ITypeSymbol type = null; | ||
Optional<object> constantValue = default(Optional<object>); | ||
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. I have followed the general pattern used in this file. Heejae, you might want to take care of this when we checkin the generator. In reply to: 121589002 [](ancestors = 121589002) 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. @AlekseyTs Added a note to #19720 (comment) to address this review comment. |
||
return new LazyLocalFunctionStatement(localFunctionSymbol, body, isInvalid, syntax, type, constantValue); | ||
} | ||
|
||
private static IOperation CreateBoundConversionOperation(BoundConversion boundConversion) | ||
{ | ||
ConversionKind conversionKind = GetConversionKind(boundConversion.ConversionKind); | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4566,4 +4566,65 @@ public LazyWithStatement(Lazy<IOperation> body, Lazy<IOperation> value, bool isI | |
public override IOperation Value => _lazyValue.Value; | ||
} | ||
|
||
/// <summary> | ||
/// Represents a local function statement. | ||
/// </summary> | ||
internal abstract partial class BaseLocalFunctionStatement : Operation, ILocalFunctionStatement | ||
{ | ||
protected BaseLocalFunctionStatement(IMethodSymbol localFunctionSymbol, bool isInvalid, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : | ||
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. I have used the common pattern already used in this generated file. In reply to: 121588312 [](ancestors = 121588312) 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. Added a note to #19720 (comment) to address this review comment. |
||
base(OperationKind.LocalFunctionStatement, isInvalid, syntax, type, constantValue) | ||
{ | ||
LocalFunctionSymbol = localFunctionSymbol; | ||
} | ||
/// <summary> | ||
/// Local function symbol. | ||
/// </summary> | ||
public IMethodSymbol LocalFunctionSymbol { get; } | ||
/// <summary> | ||
/// Body of the local function. | ||
/// </summary> | ||
public abstract IBlockStatement Body { get; } | ||
public override void Accept(OperationVisitor visitor) | ||
{ | ||
visitor.VisitLocalFunctionStatement(this); | ||
} | ||
public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument) | ||
{ | ||
return visitor.VisitLocalFunctionStatement(this, argument); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents a local function statement. | ||
/// </summary> | ||
internal sealed partial class LocalFunctionStatement : BaseLocalFunctionStatement, ILocalFunctionStatement | ||
{ | ||
public LocalFunctionStatement(IMethodSymbol localFunctionSymbol, IBlockStatement body, bool isInvalid, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : | ||
base(localFunctionSymbol, isInvalid, syntax, type, constantValue) | ||
{ | ||
Body = body; | ||
} | ||
/// <summary> | ||
/// Body of the local function. | ||
/// </summary> | ||
public override IBlockStatement Body { get; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a local function statement. | ||
/// </summary> | ||
internal sealed partial class LazyLocalFunctionStatement : BaseLocalFunctionStatement, ILocalFunctionStatement | ||
{ | ||
private readonly Lazy<IBlockStatement> _lazyBody; | ||
|
||
public LazyLocalFunctionStatement(IMethodSymbol localFunctionSymbol, Lazy<IBlockStatement> body, bool isInvalid, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) | ||
: base(localFunctionSymbol, isInvalid, syntax, type, constantValue) | ||
{ | ||
_lazyBody = body ?? throw new System.ArgumentNullException("body"); | ||
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.
Use nameof? #Closed 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.
It looks like there was no any response to this comment (#20177 (review)). #Closed 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 have used the existing pattern in this file. @heejaechang may want to address this in the generator. #Closed 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 am confused, are you actually running a generator, or adding this code manually. If the latter, please consider addressing provided feedback. For feedback you didn't addressed because of using existing pattern, pleas open issues to follow up (applies to other similar comments). #Closed 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 didn't address feedback as this will eventually become a generated file. I can file issues so we can address them in the generator when it is eventually checked in. Does that seem fine? 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.
Yes, as long as we have issues tracking the debt. #Closed 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. @AlekseyTs Added a note to #19720 (comment) to address this review comment. |
||
} | ||
/// <summary> | ||
/// Body of the local function. | ||
/// </summary> | ||
public override IBlockStatement Body => _lazyBody.Value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Microsoft.CodeAnalysis.Semantics | ||
{ | ||
/// <summary> | ||
/// Represents a local function statement. | ||
/// </summary> | ||
/// <remarks> | ||
/// This interface is reserved for implementation by its associated APIs. We reserve the right to | ||
/// change it in the future. | ||
/// </remarks> | ||
public interface ILocalFunctionStatement : IOperation | ||
{ | ||
/// <summary> | ||
/// Local function symbol. | ||
/// </summary> | ||
IMethodSymbol LocalFunctionSymbol { get; } | ||
/// <summary> | ||
/// Body of the local function. | ||
/// </summary> | ||
IBlockStatement Body { get; } | ||
} | ||
} | ||
|
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.
Can we assert that the body is in fact a block statement before the lazy, that way if it ever fails it'll fail in a helpful location with a better stack? #ByDesign
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.
It looks like Body is statically typed as BoundBlock.
In reply to: 121546721 [](ancestors = 121546721)