-
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
Conversion expression rewrite #21040
Merged
333fred
merged 27 commits into
dotnet:features/ioperation
from
333fred:conversion-expression-rewrite
Aug 8, 2017
Merged
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
bc55977
Adds initial IConverisonExpression API rewrite.
333fred f2c328d
Updated documentation, added ThrowsExceptionOnFailure field
333fred 0158878
Moved fromm an interface IConversion to a CommonConversion struct.
333fred c850505
Added IsChecked bool property
333fred 9815e73
Use TryCast for cleaner code
333fred eb9fdb7
Remove period from error message
333fred fcae24e
Addressed minor feedback items.
333fred ac70ad0
Removed virtual from MethodName property, made Conversion a synthesiz…
333fred 2be4107
Move Language to IOperation root.
333fred 62c84ab
Move ThrowsExceptionOnFailure to IsTryCast, invert logic for this.
333fred 1094d2b
Updated test infrastructure code.
333fred 08b5bc3
Updated expected tests output for all tests involving IConversionExpr…
333fred 28ac13f
Merge remote-tracking branch 'dotnet/features/ioperation' into conver…
333fred 90d781e
Moved OperationCloner to semantic model, fixed non-Compilers.sln comp…
333fred 4d1573a
Revert resources change
333fred f00bd83
More test updates. Added checked tests and fixed checked bug.
333fred 34a897e
Moved GetCSharp/VBConversion to GetConversion, into CSharp/VBExtensio…
333fred c1b0ca3
Removed LanguageName from ConversionExpression
333fred aed4959
Revert case changes in VBOperationFactory, make VBOperationCloner Rea…
333fred 9c0a391
Move CloneOperation to not be generic calls all the way down.
333fred 65f5f24
Removed boxing HasFlag usage from CommonConversion.
333fred 5d2ffcb
Fixed IConversionExpression comment.
333fred ee30c32
Fixed failing unit tests, sorted and removed unnecessary usings in Co…
333fred 8a61410
Merge remote-tracking branch 'dotnet/features/ioperation' into conver…
333fred 901b072
Merge remote-tracking branch 'dotnet/features/ioperation' into conver…
333fred d4d8834
Merge remote-tracking branch 'dotnet/features/ioperation' into conver…
333fred f2d8739
Tagged new unit tests with IOperation tag.
333fred File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Compilers/CSharp/Portable/Operations/CSharpConversionExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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; | ||
using Microsoft.CodeAnalysis.Semantics; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp | ||
{ | ||
internal abstract class BaseCSharpConversionExpression : BaseConversionExpression | ||
{ | ||
protected BaseCSharpConversionExpression(Conversion conversion, bool isExplicitInCode, bool isTryCast, bool isChecked, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : | ||
base(isExplicitInCode, isTryCast, isChecked, semanticModel, syntax, type, constantValue) | ||
{ | ||
ConversionInternal = conversion; | ||
} | ||
|
||
internal Conversion ConversionInternal { get; } | ||
|
||
public override CommonConversion Conversion => ConversionInternal.ToCommonConversion(); | ||
} | ||
|
||
internal sealed partial class CSharpConversionExpression : BaseCSharpConversionExpression | ||
{ | ||
public CSharpConversionExpression(IOperation operand, Conversion conversion, bool isExplicit, bool isTryCast, bool isChecked, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : | ||
base(conversion, isExplicit, isTryCast, isChecked, semanticModel, syntax, type, constantValue) | ||
{ | ||
OperandImpl = operand; | ||
} | ||
|
||
public override IOperation OperandImpl { get; } | ||
} | ||
|
||
internal sealed partial class LazyCSharpConversionExpression : BaseCSharpConversionExpression | ||
{ | ||
private readonly Lazy<IOperation> _operand; | ||
public LazyCSharpConversionExpression(Lazy<IOperation> operand, Conversion conversion, bool isExplicit, bool isTryCast, bool isChecked, SemanticModel semanticModel,SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue) : | ||
base(conversion, isExplicit, isTryCast, isChecked, semanticModel, syntax, type, constantValue) | ||
{ | ||
_operand = operand; | ||
} | ||
|
||
public override IOperation OperandImpl => _operand.Value; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Compilers/CSharp/Portable/Operations/CSharpOperationCloner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 Microsoft.CodeAnalysis.Semantics; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp | ||
{ | ||
internal class CSharpOperationCloner : OperationCloner | ||
{ | ||
public static OperationCloner Instance { get; } = new CSharpOperationCloner(); | ||
|
||
public override IOperation VisitConversionExpression(IConversionExpression operation, object argument) | ||
{ | ||
return new CSharpConversionExpression(Visit(operation.Operand), operation.GetConversion(), operation.IsExplicitInCode, operation.IsTryCast, operation.IsChecked, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Microsoft.CodeAnalysis.CSharp.Conversion.ToCommonConversion() -> Microsoft.CodeAnalysis.Semantics.CommonConversion | ||
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp7_2 = 702 -> Microsoft.CodeAnalysis.CSharp.LanguageVersion | ||
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetConversion(this Microsoft.CodeAnalysis.Semantics.IConversionExpression conversionExpression) -> Microsoft.CodeAnalysis.CSharp.Conversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@cston style question: is the preferred strategy to have both the
CommonConversion
andConversion
struct around, or to perform the conversion when requested? iepublic CommonConversion Conversion => (CommonConversion)ConversionInternal;
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.
If creating the
struct
is sufficiently lightweight, then it's reasonable to create it when requested. But either way, please use an explicit method rather than a conversion operator.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.
I left it as is for now. If you'd prefer to have it created on demand, let me know and I'll change it.