提交 f5aa024c 编写于 作者: C Charles Stoner

Remove WellKnownType.Last

上级 0317409e
......@@ -77,7 +77,7 @@ internal Symbol GetWellKnownTypeMember(WellKnownMember member)
internal NamedTypeSymbol GetWellKnownType(WellKnownType type)
{
Debug.Assert(type >= WellKnownType.First && type <= WellKnownType.Last && type != WellKnownType.ExtSentinel);
Debug.Assert(type.IsValid());
int index = (int)type - (int)WellKnownType.First;
if (_lazyWellKnownTypes == null || (object)_lazyWellKnownTypes[index] == null)
......@@ -778,7 +778,7 @@ public WellKnownMembersSignatureComparer(CSharpCompilation compilation)
protected override bool MatchTypeToTypeId(TypeSymbol type, int typeId)
{
WellKnownType wellKnownId = (WellKnownType)typeId;
if (wellKnownId >= WellKnownType.First && wellKnownId <= WellKnownType.Last)
if (wellKnownId.IsWellKnownType())
{
return (type == _compilation.GetWellKnownType(wellKnownId));
}
......
......@@ -548,7 +548,7 @@ public void AllWellKnownTypes()
}.Concat(WinRtRefs).ToArray();
var comp = CreateCompilation("", refs);
for (var wkt = WellKnownType.First; wkt <= WellKnownType.Last; wkt++)
for (var wkt = WellKnownType.First; wkt < WellKnownType.NextAvailable; wkt++)
{
switch (wkt)
{
......@@ -572,7 +572,7 @@ public void AllWellKnownTypes()
}
[Fact]
public void AllWellKnowTypesBeforeCSharp7()
public void AllWellKnownTypesBeforeCSharp7()
{
foreach (var type in new[] {
WellKnownType.System_Math,
......
......@@ -260,8 +260,7 @@ internal enum WellKnownType
System_ValueTuple_T7,
System_ValueTuple_TRest,
Available,
Last = Available - 1,
NextAvailable,
}
internal static class WellKnownTypes
......@@ -269,7 +268,7 @@ internal static class WellKnownTypes
/// <summary>
/// Number of well known types in WellKnownType enum
/// </summary>
internal const int Count = WellKnownType.Last - WellKnownType.First + 1;
internal const int Count = WellKnownType.NextAvailable - WellKnownType.First;
/// <summary>
/// Array of names for types.
......@@ -537,31 +536,49 @@ private static void AssertEnumAndTableInSync()
var typeId = (WellKnownType)(i + WellKnownType.First);
string typeIdName;
if (typeId == WellKnownType.First)
switch (typeId)
{
typeIdName = "System.Math";
case WellKnownType.First:
typeIdName = "System.Math";
break;
case WellKnownType.Microsoft_VisualBasic_CompilerServices_ObjectFlowControl_ForLoopControl:
typeIdName = "Microsoft.VisualBasic.CompilerServices.ObjectFlowControl+ForLoopControl";
break;
case WellKnownType.CSharp7Sentinel:
typeIdName = "System.IFormatProvider";
break;
case WellKnownType.ExtSentinel:
typeIdName = "";
continue;
default:
typeIdName = typeId.ToString().Replace("__", "+").Replace('_', '.');
break;
}
else if (typeId == WellKnownType.Last)
{
typeIdName = "System.ValueTuple`8";
}
else if (typeId == WellKnownType.ExtSentinel)
{
Debug.Assert(name == "");
continue;
}
else
int separator = name.IndexOf('`');
if (separator >= 0)
{
typeIdName = typeId.ToString().Replace("__", "+").Replace('_', '.');
// Ignore type parameter qualifier for generic types.
name = name.Substring(0, separator);
typeIdName = typeIdName.Substring(0, separator);
}
Debug.Assert(name == "Microsoft.VisualBasic.CompilerServices.ObjectFlowControl+ForLoopControl"
|| name.IndexOf('`') > 0 // a generic type
|| name == typeIdName);
Debug.Assert(name == typeIdName);
}
Debug.Assert((int)WellKnownType.ExtSentinel == 255);
Debug.Assert((int)WellKnownType.Last < 512);
Debug.Assert((int)WellKnownType.NextAvailable <= 512);
}
public static bool IsWellKnownType(this WellKnownType typeId)
{
Debug.Assert(typeId != WellKnownType.ExtSentinel);
return typeId >= WellKnownType.First && typeId < WellKnownType.NextAvailable;
}
public static bool IsValid(this WellKnownType typeId)
{
return typeId >= WellKnownType.First && typeId < WellKnownType.NextAvailable && typeId != WellKnownType.ExtSentinel;
}
public static string GetMetadataName(this WellKnownType id)
......
......@@ -341,7 +341,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Friend Function GetWellKnownType(type As WellKnownType) As NamedTypeSymbol
Debug.Assert(type >= WellKnownType.First AndAlso type <= WellKnownType.Last AndAlso type <> WellKnownType.ExtSentinel)
Debug.Assert(type.IsWellKnownType())
Dim index As Integer = type - WellKnownType.First
If _lazyWellKnownTypes Is Nothing OrElse _lazyWellKnownTypes(index) Is Nothing Then
......@@ -639,15 +639,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub
Protected Overrides Function MatchTypeToTypeId(type As TypeSymbol, typeId As Integer) As Boolean
Dim result As Boolean = False
If typeId >= WellKnownType.First AndAlso typeId <= WellKnownType.Last Then
result = (type Is _compilation.GetWellKnownType(CType(typeId, WellKnownType)))
Else
result = MyBase.MatchTypeToTypeId(type, typeId)
Dim wellKnownId = CType(typeId, WellKnownType)
If wellKnownId.IsWellKnownType() Then
Return type Is _compilation.GetWellKnownType(wellKnownId)
End If
Return result
Return MyBase.MatchTypeToTypeId(type, typeId)
End Function
End Class
End Class
......
......@@ -493,8 +493,9 @@ End Namespace
ValueTupleRef
}.Concat(WinRtRefs).ToArray()
Dim lastType = CType(WellKnownType.NextAvailable - 1, WellKnownType)
Dim comp = CreateCompilationWithReferences((<compilation/>), refs.Concat(MsvbRef_v4_0_30319_17929).ToArray())
For wkt = WellKnownType.First To WellKnownType.Last
For wkt = WellKnownType.First To lastType
Select Case wkt
Case WellKnownType.Microsoft_VisualBasic_CompilerServices_EmbeddedOperators
' Only present when embedding VB Core.
......@@ -514,7 +515,7 @@ End Namespace
Next
comp = CreateCompilationWithReferences(<compilation/>, refs, TestOptions.ReleaseDll.WithEmbedVbCoreRuntime(True))
For wkt = WellKnownType.First To WellKnownType.Last
For wkt = WellKnownType.First To lastType
Select Case wkt
Case WellKnownType.Microsoft_VisualBasic_CallType,
WellKnownType.Microsoft_VisualBasic_CompilerServices_Operators,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册