提交 4609f60d 编写于 作者: W wochae

Update VB tests for EnC StateMachines (changeset 1389653)

上级 b2126a6d
......@@ -119,7 +119,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Select Case GeneratedNames.GetKind(name)
Case GeneratedNameKind.StateMachineAwaiterField
If GeneratedNames.TryParseSlotIndex(name, slotIndex) Then
If GeneratedNames.TryParseSlotIndex(StringConstants.StateMachineAwaiterFieldPrefix, name, slotIndex) Then
Dim field = TryCast(member, IFieldSymbol)
' Correct metadata won't contain duplicates, but malformed might, ignore the duplicate:
......@@ -130,8 +131,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
End If
End If
Case GeneratedNameKind.HoistedSynthesizedLocalField
If GeneratedNames.TryParseSlotIndex(name, slotIndex) Then
Case GeneratedNameKind.HoistedSynthesizedLocalField,
GeneratedNameKind.StateMachineHoistedUserVariableField
Dim _name As String = Nothing
If GeneratedNames.TryParseSlotIndex(StringConstants.HoistedSynthesizedLocalPrefix, name, slotIndex) OrElse
GeneratedNames.TryParseStateMachineHoistedUserVariableName(name, _name, slotIndex) Then
Dim field = TryCast(member, IFieldSymbol)
If slotIndex >= localSlotDebugInfo.Length Then
' Invalid metadata
......@@ -149,6 +154,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
hoistedLocalMap = hoistedLocals
awaiterMap = awaiters
awaiterSlotCount = maxAwaiterSlotIndex + 1
End Sub
Protected Overrides Function TryGetLocalSlotMapFromMetadata(handle As MethodDefinitionHandle, debugInfo As EditAndContinueMethodDebugInformation) As ImmutableArray(Of EncLocalInfo)
......
......@@ -296,7 +296,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
id = New LocalDebugId(syntaxOffset, ordinal)
If SlotAllocatorOpt IsNot Nothing Then
slotIndex = SlotAllocatorOpt.GetPreviousHoistedLocalSlotIndex(declaratorSyntax, DirectCast(fieldType, Cci.ITypeDefinition), local.SynthesizedKind, id)
slotIndex = SlotAllocatorOpt.GetPreviousHoistedLocalSlotIndex(declaratorSyntax, DirectCast(fieldType, Cci.ITypeReference), local.SynthesizedKind, id)
End If
End If
......
......@@ -14,13 +14,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
IteratorInitialThreadIdField
IteratorParameterProxyField
StateMachineAwaiterField
StateMachineStateField
StateMachineHoistedUserVariableField
StaticLocalField
End Enum
Partial Friend Class GeneratedNames
Friend Shared Function GetKind(name As String) As GeneratedNameKind
If name.StartsWith(StringConstants.HoistedMeName, StringComparison.Ordinal) Then
Return GeneratedNameKind.HoistedMeField
ElseIf name.StartsWith(StringConstants.StateMachineStateFieldName, StringComparison.Ordinal) Then
Return GeneratedNameKind.StateMachineStateField
ElseIf name.StartsWith(StringConstants.StaticLocalFieldNamePrefix, StringComparison.Ordinal) Then
Return GeneratedNameKind.StaticLocalField
ElseIf name.StartsWith(StringConstants.HoistedSynthesizedLocalPrefix, StringComparison.Ordinal) Then
Return GeneratedNameKind.HoistedSynthesizedLocalField
ElseIf name.StartsWith(StringConstants.HoistedUserVariablePrefix, StringComparison.Ordinal) Then
......
......@@ -273,20 +273,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Function
' Extracts the slot index from a name of a field that stores hoisted variables Or awaiters.
' Such a name ends with "__{slot index + 1}".
' Such a name ends with "$prefix{slot index}".
' Returned slot index Is >= 0.
Friend Shared Function TryParseSlotIndex(fieldName As String, <Out> ByRef slotIndex As Integer) As Boolean
Dim lastUnder = fieldName.LastIndexOf("_"c)
If lastUnder - 1 < 0 OrElse lastUnder = fieldName.Length OrElse fieldName(lastUnder - 1) <> "_"c Then
slotIndex = -1
Return False
End If
If Integer.TryParse(fieldName.Substring(lastUnder + 1), slotIndex) AndAlso slotIndex >= 1 Then
slotIndex = slotIndex - 1
Friend Shared Function TryParseSlotIndex(prefix As String, fieldName As String, <Out> ByRef slotIndex As Integer) As Boolean
If fieldName.StartsWith(prefix, StringComparison.Ordinal) AndAlso
Integer.TryParse(fieldName.Substring(prefix.Length), NumberStyles.None, CultureInfo.InvariantCulture, slotIndex) Then
Return True
End If
slotIndex = -1
Return False
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册