提交 276a34e2 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #13154 from CyrusNajmabadi/syntaxNodeLambdas

Remove EnC specific methods from the Syntax API.
...@@ -286,6 +286,7 @@ ...@@ -286,6 +286,7 @@
<Compile Include="DocumentationComments\PEDocumentationCommentUtils.cs" /> <Compile Include="DocumentationComments\PEDocumentationCommentUtils.cs" />
<Compile Include="DocumentationComments\SourceDocumentationCommentUtils.cs" /> <Compile Include="DocumentationComments\SourceDocumentationCommentUtils.cs" />
<Compile Include="Emitter\EditAndContinue\CSharpDefinitionMap.cs" /> <Compile Include="Emitter\EditAndContinue\CSharpDefinitionMap.cs" />
<Compile Include="Emitter\EditAndContinue\CSharpLambdaSyntaxFacts.cs" />
<Compile Include="Emitter\EditAndContinue\EmitHelpers.cs" /> <Compile Include="Emitter\EditAndContinue\EmitHelpers.cs" />
<Compile Include="Emitter\EditAndContinue\PEDeltaAssemblyBuilder.cs" /> <Compile Include="Emitter\EditAndContinue\PEDeltaAssemblyBuilder.cs" />
<Compile Include="Emitter\EditAndContinue\CSharpSymbolMatcher.cs" /> <Compile Include="Emitter\EditAndContinue\CSharpSymbolMatcher.cs" />
...@@ -925,4 +926,4 @@ ...@@ -925,4 +926,4 @@
<ImportGroup Label="Targets"> <ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" /> <Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
...@@ -35,6 +35,8 @@ internal sealed partial class CSharpDefinitionMap : DefinitionMap<CSharpSymbolMa ...@@ -35,6 +35,8 @@ internal sealed partial class CSharpDefinitionMap : DefinitionMap<CSharpSymbolMa
internal override CommonMessageProvider MessageProvider => CSharp.MessageProvider.Instance; internal override CommonMessageProvider MessageProvider => CSharp.MessageProvider.Instance;
protected override LambdaSyntaxFacts GetLambdaSyntaxFacts() => CSharpLambdaSyntaxFacts.Instance;
internal bool TryGetAnonymousTypeName(NamedTypeSymbol template, out string name, out int index) internal bool TryGetAnonymousTypeName(NamedTypeSymbol template, out string name, out int index)
{ {
return this.mapToPrevious.TryGetAnonymousTypeName(template, out name, out index); return this.mapToPrevious.TryGetAnonymousTypeName(template, out name, out index);
......
// 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.Emit;
namespace Microsoft.CodeAnalysis.CSharp.Emit
{
internal class CSharpLambdaSyntaxFacts : LambdaSyntaxFacts
{
public static readonly LambdaSyntaxFacts Instance = new CSharpLambdaSyntaxFacts();
private CSharpLambdaSyntaxFacts()
{
}
public override SyntaxNode GetLambda(SyntaxNode lambdaOrLambdaBodySyntax)
{
return LambdaUtilities.GetLambda(lambdaOrLambdaBodySyntax);
}
public override SyntaxNode TryGetCorrespondingLambdaBody(
SyntaxNode previousLambdaSyntax,
SyntaxNode lambdaOrLambdaBodySyntax)
{
return LambdaUtilities.TryGetCorrespondingLambdaBody(
lambdaOrLambdaBodySyntax, previousLambdaSyntax);
}
}
}
\ No newline at end of file
...@@ -447,16 +447,6 @@ public new IEnumerable<Diagnostic> GetDiagnostics() ...@@ -447,16 +447,6 @@ public new IEnumerable<Diagnostic> GetDiagnostics()
return this.SyntaxTree.GetDiagnostics(this); return this.SyntaxTree.GetDiagnostics(this);
} }
internal sealed override SyntaxNode TryGetCorrespondingLambdaBody(SyntaxNode body)
{
return LambdaUtilities.TryGetCorrespondingLambdaBody(body, this);
}
internal override SyntaxNode GetLambda()
{
return LambdaUtilities.GetLambda(this);
}
#region Directives #region Directives
internal IList<DirectiveTriviaSyntax> GetDirectives(Func<DirectiveTriviaSyntax, bool> filter = null) internal IList<DirectiveTriviaSyntax> GetDirectives(Func<DirectiveTriviaSyntax, bool> filter = null)
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
<Compile Include="CodeGen\ItemTokenMap.cs" /> <Compile Include="CodeGen\ItemTokenMap.cs" />
<Compile Include="Emit\DebugDocumentsBuilder.cs" /> <Compile Include="Emit\DebugDocumentsBuilder.cs" />
<Compile Include="EmbeddedText.cs" /> <Compile Include="EmbeddedText.cs" />
<Compile Include="Emit\EditAndContinue\LambdaSyntaxFacts.cs" />
<Compile Include="InternalUtilities\EncodingExtensions.cs" /> <Compile Include="InternalUtilities\EncodingExtensions.cs" />
<Compile Include="InternalUtilities\BlobBuildingStream.cs" /> <Compile Include="InternalUtilities\BlobBuildingStream.cs" />
<Compile Include="GlobalSuppressions.cs" /> <Compile Include="GlobalSuppressions.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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;
using System.Reflection.Metadata;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Symbols; using Microsoft.CodeAnalysis.Symbols;
using System.Reflection.Metadata.Ecma335;
using Roslyn.Utilities; using Roslyn.Utilities;
using System.IO;
namespace Microsoft.CodeAnalysis.Emit namespace Microsoft.CodeAnalysis.Emit
{ {
...@@ -314,9 +314,12 @@ internal VariableSlotAllocator TryCreateVariableSlotAllocator(EmitBaseline basel ...@@ -314,9 +314,12 @@ internal VariableSlotAllocator TryCreateVariableSlotAllocator(EmitBaseline basel
hoistedLocalSlotCount, hoistedLocalSlotCount,
hoistedLocalMap, hoistedLocalMap,
awaiterSlotCount, awaiterSlotCount,
awaiterMap); awaiterMap,
GetLambdaSyntaxFacts());
} }
protected abstract LambdaSyntaxFacts GetLambdaSyntaxFacts();
private void ReportMissingStateMachineAttribute(DiagnosticBag diagnostics, IMethodSymbolInternal method, string stateMachineAttributeFullName) private void ReportMissingStateMachineAttribute(DiagnosticBag diagnostics, IMethodSymbolInternal method, string stateMachineAttributeFullName)
{ {
diagnostics.Add(MessageProvider.CreateDiagnostic( diagnostics.Add(MessageProvider.CreateDiagnostic(
......
...@@ -36,6 +36,8 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator ...@@ -36,6 +36,8 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator
private readonly IReadOnlyDictionary<int, KeyValuePair<DebugId, int>> _lambdaMapOpt; // SyntaxOffset -> (Lambda Id, Closure Ordinal) private readonly IReadOnlyDictionary<int, KeyValuePair<DebugId, int>> _lambdaMapOpt; // SyntaxOffset -> (Lambda Id, Closure Ordinal)
private readonly IReadOnlyDictionary<int, DebugId> _closureMapOpt; // SyntaxOffset -> Id private readonly IReadOnlyDictionary<int, DebugId> _closureMapOpt; // SyntaxOffset -> Id
private readonly LambdaSyntaxFacts _lambdaSyntaxFacts;
public EncVariableSlotAllocator( public EncVariableSlotAllocator(
SymbolMatcher symbolMap, SymbolMatcher symbolMap,
Func<SyntaxNode, SyntaxNode> syntaxMapOpt, Func<SyntaxNode, SyntaxNode> syntaxMapOpt,
...@@ -48,7 +50,8 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator ...@@ -48,7 +50,8 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator
int hoistedLocalSlotCount, int hoistedLocalSlotCount,
IReadOnlyDictionary<EncHoistedLocalInfo, int> hoistedLocalSlotsOpt, IReadOnlyDictionary<EncHoistedLocalInfo, int> hoistedLocalSlotsOpt,
int awaiterCount, int awaiterCount,
IReadOnlyDictionary<Cci.ITypeReference, int> awaiterMapOpt) IReadOnlyDictionary<Cci.ITypeReference, int> awaiterMapOpt,
LambdaSyntaxFacts lambdaSyntaxFacts)
{ {
Debug.Assert(symbolMap != null); Debug.Assert(symbolMap != null);
Debug.Assert(previousTopLevelMethod != null); Debug.Assert(previousTopLevelMethod != null);
...@@ -66,6 +69,7 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator ...@@ -66,6 +69,7 @@ internal sealed class EncVariableSlotAllocator : VariableSlotAllocator
_awaiterMapOpt = awaiterMapOpt; _awaiterMapOpt = awaiterMapOpt;
_lambdaMapOpt = lambdaMapOpt; _lambdaMapOpt = lambdaMapOpt;
_closureMapOpt = closureMapOpt; _closureMapOpt = closureMapOpt;
_lambdaSyntaxFacts = lambdaSyntaxFacts;
// Create a map from local info to slot. // Create a map from local info to slot.
var previousLocalInfoToSlot = new Dictionary<EncLocalInfo, int>(); var previousLocalInfoToSlot = new Dictionary<EncLocalInfo, int>();
...@@ -249,7 +253,9 @@ private bool TryGetPreviousLambdaSyntaxOffset(SyntaxNode lambdaOrLambdaBodySynta ...@@ -249,7 +253,9 @@ private bool TryGetPreviousLambdaSyntaxOffset(SyntaxNode lambdaOrLambdaBodySynta
{ {
// Syntax map contains mapping for lambdas, but not their bodies. // Syntax map contains mapping for lambdas, but not their bodies.
// Map the lambda first and then determine the corresponding body. // Map the lambda first and then determine the corresponding body.
var currentLambdaSyntax = isLambdaBody ? lambdaOrLambdaBodySyntax.GetLambda() : lambdaOrLambdaBodySyntax; var currentLambdaSyntax = isLambdaBody
? _lambdaSyntaxFacts.GetLambda(lambdaOrLambdaBodySyntax)
: lambdaOrLambdaBodySyntax;
// no syntax map // no syntax map
// => the source of the current method is the same as the source of the previous method // => the source of the current method is the same as the source of the previous method
...@@ -265,7 +271,7 @@ private bool TryGetPreviousLambdaSyntaxOffset(SyntaxNode lambdaOrLambdaBodySynta ...@@ -265,7 +271,7 @@ private bool TryGetPreviousLambdaSyntaxOffset(SyntaxNode lambdaOrLambdaBodySynta
SyntaxNode previousSyntax; SyntaxNode previousSyntax;
if (isLambdaBody) if (isLambdaBody)
{ {
previousSyntax = previousLambdaSyntax.TryGetCorrespondingLambdaBody(lambdaOrLambdaBodySyntax); previousSyntax = _lambdaSyntaxFacts.TryGetCorrespondingLambdaBody(previousLambdaSyntax, lambdaOrLambdaBodySyntax);
if (previousSyntax == null) if (previousSyntax == null)
{ {
previousSyntaxOffset = 0; previousSyntaxOffset = 0;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Emit
{
internal abstract class LambdaSyntaxFacts
{
public abstract SyntaxNode GetLambda(SyntaxNode lambdaOrLambdaBodySyntax);
/// <summary>
/// When invoked on a node that represents an anonymous function or a query clause [1]
/// with a <paramref name="lambdaOrLambdaBodySyntax"/> of another anonymous function or a query clause of the same kind [2],
/// returns the body of the [1] that positionally corresponds to the specified <paramref name="lambdaOrLambdaBodySyntax"/>.
///
/// E.g. join clause declares left expression and right expression -- each of these expressions is a lambda body.
/// JoinClause1.GetCorrespondingLambdaBody(JoinClause2.RightExpression) returns JoinClause1.RightExpression.
/// </summary>
public abstract SyntaxNode TryGetCorrespondingLambdaBody(SyntaxNode previousLambdaSyntax, SyntaxNode lambdaOrLambdaBodySyntax);
}
}
\ No newline at end of file
...@@ -551,18 +551,6 @@ public SyntaxReference GetReference() ...@@ -551,18 +551,6 @@ public SyntaxReference GetReference()
return this.SyntaxTree.GetReference(this); return this.SyntaxTree.GetReference(this);
} }
/// <summary>
/// When invoked on a node that represents an anonymous function or a query clause [1]
/// with a <paramref name="body"/> of another anonymous function or a query clause of the same kind [2],
/// returns the body of the [1] that positionally corresponds to the specified <paramref name="body"/>.
///
/// E.g. join clause declares left expression and right expression -- each of these expressions is a lambda body.
/// JoinClause1.GetCorrespondingLambdaBody(JoinClause2.RightExpression) returns JoinClause1.RightExpression.
/// </summary>
internal abstract SyntaxNode TryGetCorrespondingLambdaBody(SyntaxNode body);
internal abstract SyntaxNode GetLambda();
#region Node Lookup #region Node Lookup
/// <summary> /// <summary>
......
...@@ -350,6 +350,7 @@ ...@@ -350,6 +350,7 @@
<Compile Include="Emit\EditAndContinue\VisualBasicDefinitionMap.vb" /> <Compile Include="Emit\EditAndContinue\VisualBasicDefinitionMap.vb" />
<Compile Include="Emit\EditAndContinue\EmitHelpers.vb" /> <Compile Include="Emit\EditAndContinue\EmitHelpers.vb" />
<Compile Include="Emit\EditAndContinue\PEDeltaAssemblyBuilder.vb" /> <Compile Include="Emit\EditAndContinue\PEDeltaAssemblyBuilder.vb" />
<Compile Include="Emit\EditAndContinue\VisualBasicLambdaSyntaxFacts.vb" />
<Compile Include="Emit\EditAndContinue\VisualBasicSymbolMatcher.vb" /> <Compile Include="Emit\EditAndContinue\VisualBasicSymbolMatcher.vb" />
<Compile Include="Emit\EventSymbolAdapter.vb" /> <Compile Include="Emit\EventSymbolAdapter.vb" />
<Compile Include="Emit\FieldSymbolAdapter.vb" /> <Compile Include="Emit\FieldSymbolAdapter.vb" />
...@@ -1016,4 +1017,4 @@ ...@@ -1016,4 +1017,4 @@
<ImportGroup Label="Targets"> <ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" /> <Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Imports System.Collections.Immutable Imports System.Collections.Immutable
Imports System.Reflection.Metadata Imports System.Reflection.Metadata
Imports System.Reflection.Metadata.Ecma335
Imports System.Runtime.InteropServices Imports System.Runtime.InteropServices
Imports Microsoft.CodeAnalysis.CodeGen Imports Microsoft.CodeAnalysis.CodeGen
Imports Microsoft.CodeAnalysis.Emit Imports Microsoft.CodeAnalysis.Emit
...@@ -38,6 +37,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit ...@@ -38,6 +37,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
End Get End Get
End Property End Property
Protected Overrides Function GetLambdaSyntaxFacts() As LambdaSyntaxFacts
Return VisualBasicLambdaSyntaxFacts.Instance
End Function
Friend Function TryGetAnonymousTypeName(template As NamedTypeSymbol, <Out> ByRef name As String, <Out> ByRef index As Integer) As Boolean Friend Function TryGetAnonymousTypeName(template As NamedTypeSymbol, <Out> ByRef name As String, <Out> ByRef index As Integer) As Boolean
Return Me.mapToPrevious.TryGetAnonymousTypeName(template, name, index) Return Me.mapToPrevious.TryGetAnonymousTypeName(template, name, index)
End Function End Function
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Emit
Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Friend Class VisualBasicLambdaSyntaxFacts
Inherits LambdaSyntaxFacts
Public Shared ReadOnly Instance As LambdaSyntaxFacts = New VisualBasicLambdaSyntaxFacts()
Private Sub New()
End Sub
Public Overrides Function GetLambda(lambdaOrLambdaBodySyntax As SyntaxNode) As SyntaxNode
Return LambdaUtilities.GetLambda(lambdaOrLambdaBodySyntax)
End Function
Public Overrides Function TryGetCorrespondingLambdaBody(previousLambdaSyntax As SyntaxNode, lambdaOrLambdaBodySyntax As SyntaxNode) As SyntaxNode
Return LambdaUtilities.GetCorrespondingLambdaBody(lambdaOrLambdaBodySyntax, previousLambdaSyntax)
End Function
End Class
End Namespace
\ No newline at end of file
...@@ -616,13 +616,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ...@@ -616,13 +616,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Protected Overrides Function IsEquivalentToCore(node As SyntaxNode, Optional topLevel As Boolean = False) As Boolean Protected Overrides Function IsEquivalentToCore(node As SyntaxNode, Optional topLevel As Boolean = False) As Boolean
Return SyntaxFactory.AreEquivalent(Me, DirectCast(node, VisualBasicSyntaxNode), topLevel) Return SyntaxFactory.AreEquivalent(Me, DirectCast(node, VisualBasicSyntaxNode), topLevel)
End Function End Function
Friend Overrides Function TryGetCorrespondingLambdaBody(body As SyntaxNode) As SyntaxNode
Return LambdaUtilities.GetCorrespondingLambdaBody(body, Me)
End Function
Friend Overrides Function GetLambda() As SyntaxNode
Return LambdaUtilities.GetLambda(Me)
End Function
End Class End Class
End Namespace End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册