提交 5a65d521 编写于 作者: A acasey

DevDiv #1084059: Custom Debug Info for static type imports

New format "TStaticType" indicates the presence of "using StaticType;" in source.

Interaction is between the compiler and the expression compiler, so no VS integration test is required.

CR: VSadov; AlekseyT (changeset 1376703)
上级 96dbcebb
......@@ -93,22 +93,17 @@ private ImmutableArray<Cci.NamespaceScope> BuildNamespaceScopes(ConsList<Imports
foreach (var nsOrType in usings)
{
NamespaceOrTypeSymbol namespaceOrType = nsOrType.NamespaceOrType;
string namespaceOrTypeString = GetNamespaceOrTypeString(namespaceOrType);
if (namespaceOrType.IsNamespace)
{
NamespaceSymbol @namespace = (NamespaceSymbol)namespaceOrType;
string namespaceString = GetNamespaceOrTypeString(@namespace);
string externAlias = GuessExternAlias(@namespace, validExternAliases);
usedNamespaces.Add(Cci.UsedNamespaceOrType.CreateCSharpNamespace(namespaceString, externAlias));
string externAlias = GuessExternAlias((NamespaceSymbol)namespaceOrType, validExternAliases);
usedNamespaces.Add(Cci.UsedNamespaceOrType.CreateCSharpNamespace(namespaceOrTypeString, externAlias));
}
else
{
// This is possible in C# scripts, but the EE doesn't support the meaning intended by script files.
// Specifically, when a script includes "using System.Console;" the intended meaning is that the
// static methods of System.Console are available but System.Console itself is not. Even if we output
// "TSystem.Console" - which the EE may or may not support - we would only see System.Console become
// available.
Debug.Assert(namespaceOrType is TypeSymbol);
Debug.Assert(namespaceOrType.IsStatic);
usedNamespaces.Add(Cci.UsedNamespaceOrType.CreateCSharpType(namespaceOrTypeString));
}
}
}
......
......@@ -1988,5 +1988,46 @@ static void Main()
result.Diagnostics.Verify(
Diagnostic(ErrorCode.WRN_DebugFullNameTooLong, "Main").WithArguments("AACT TSystem.Action`7[[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
}
[WorkItem(1084059, "DevDiv")]
[Fact]
public void StaticType()
{
var source = @"
using System.Math;
class D
{
static void Main()
{
Max(1, 2);
}
}
";
var comp = CreateCompilationWithMscorlib(source);
var expectedXml = @"
<symbols>
<methods>
<method containingType=""D"" name=""Main"" parameterNames="""">
<customDebugInfo version=""4"" count=""1"">
<using version=""4"" kind=""UsingInfo"" size=""12"" namespaceCount=""1"">
<namespace usingCount=""1""/>
</using>
</customDebugInfo>
<sequencepoints total=""2"">
<entry il_offset=""0x0"" start_row=""8"" start_column=""9"" end_row=""8"" end_column=""19"" file_ref=""0""/>
<entry il_offset=""0x8"" start_row=""9"" start_column=""5"" end_row=""9"" end_column=""6"" file_ref=""0""/>
</sequencepoints>
<locals/>
<scope startOffset=""0x0"" endOffset=""0x9"">
<type name=""System.Math, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""/>
</scope>
</method>
</methods>
</symbols>";
AssertXmlEqual(expectedXml, GetPdbXml(comp, "D.Main"));
}
}
}
\ No newline at end of file
......@@ -46,6 +46,15 @@ internal static UsedNamespaceOrType CreateCSharpExternNamespace(string externAli
return new UsedNamespaceOrType(UsedNamespaceOrTypeKind.CSExternNamespace, name: null, alias: null, externAlias: externAlias);
}
/// <remarks>
/// <paramref name="name"/> is an assembly-qualified name so the extern alias, if any, can be dropped.
/// </remarks>
internal static UsedNamespaceOrType CreateCSharpType(string name)
{
Debug.Assert(name != null);
return new UsedNamespaceOrType(UsedNamespaceOrTypeKind.CSType, name, alias: null, externAlias: null);
}
/// <remarks>
/// <paramref name="name"/> is an assembly-qualified name so the extern alias, if any, can be dropped.
/// </remarks>
......@@ -156,6 +165,10 @@ public string Encode()
case UsedNamespaceOrTypeKind.CSExternNamespace:
return "X" + this.externAlias;
case UsedNamespaceOrTypeKind.CSType:
Debug.Assert(this.externAlias == null);
return "T" + this.name;
case UsedNamespaceOrTypeKind.CSTypeAlias:
Debug.Assert(this.externAlias == null);
return "A" + this.alias + " T" + this.name;
......
......@@ -7,6 +7,7 @@ internal enum UsedNamespaceOrTypeKind
CSNamespace, // e.g. using System;
CSNamespaceAlias, // e.g. using S = System;
CSExternNamespace, //e.g. extern alias CorLib;
CSType, // e.g. using System.Math;
CSTypeAlias, // e.g. using IntList = System.Collections.Generic.List<int>;
VBNamespace, // e.g. Imports System.Collection
VBType, // e.g. Imports System.Collection.ArrayList
......
......@@ -202,8 +202,8 @@ Imports typefile1 = System.String
Imports ignoredAliasFile1 = System.Collections.Generic.Dictionary(Of String, String) ' ignored
Imports System.Collections.Generic.List(Of String) ' ignored
Imports TheDefaultNamespace.NS1.NS2.C1.C2
Imports C3ALIAS=TheDefaultNamespace.NS1.NS2.C1.C2.C3
Imports DefaultNamespace.NS1.NS2.C1.C2
Imports C3ALIAS=DefaultNamespace.NS1.NS2.C1.C2.C3
Namespace Boo
......@@ -272,19 +272,19 @@ End Namespace
"typeproj1=System.Int64",
"prjlevelIgnored=System.Collections.Generic.List(Of String)",
"System.Collections.Generic.List(Of String)",
"System.Collections.ArrayList"})).WithRootNamespace("TheDefaultNamespace"))
"System.Collections.ArrayList"})).WithRootNamespace("DefaultNamespace"))
Dim actual = PDBTests.GetPdbXml(compilation)
Dim expected =
<symbols>
<files>
<file id="1" name="a.vb" language="3a12d0b8-c26c-11d0-b442-00a0244a1dd2" languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1" documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" checkSumAlgorithmId="ff1816ec-aa5e-4d10-87f7-6f4963833460" checkSum=" 9, 9F, 83, 68, F5, 54, 6F, 3F, BF, 21, 5D, BD, C9, 6A, 3B, FE, DB, 23, B, D, "/>
<file id="1" name="a.vb" language="3a12d0b8-c26c-11d0-b442-00a0244a1dd2" languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1" documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" checkSumAlgorithmId="ff1816ec-aa5e-4d10-87f7-6f4963833460" checkSum="93, 20, A5, 3E, 2C, 50, B2, E, 7C, D6, 29, 3F, E9, 9E, 33, 72, A6, 21, FD, 3F, "/>
<file id="2" name="b.vb" language="3a12d0b8-c26c-11d0-b442-00a0244a1dd2" languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1" documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" checkSumAlgorithmId="ff1816ec-aa5e-4d10-87f7-6f4963833460" checkSum="94, 7A, FB, B, 3B, B0, EF, 63, B9, ED, E8, A9, D0, 58, BA, D0, 21, 7, C2, CE, "/>
</files>
<entryPoint declaringType="TheDefaultNamespace.Boo.C1" methodName="Main" parameterNames=""/>
<entryPoint declaringType="DefaultNamespace.Boo.C1" methodName="Main" parameterNames=""/>
<methods>
<method containingType="TheDefaultNamespace.Boo.C1" name=".ctor" parameterNames="">
<method containingType="DefaultNamespace.Boo.C1" name=".ctor" parameterNames="">
<sequencepoints total="3">
<entry il_offset="0x0" hidden="true" start_row="16707566" start_column="0" end_row="16707566" end_column="0" file_ref="1"/>
<entry il_offset="0x6" start_row="22" start_column="12" end_row="22" end_column="43" file_ref="1"/>
......@@ -296,21 +296,21 @@ End Namespace
<xmlnamespace prefix="" name="http://stuff/fromFile1" importlevel="file"/>
<alias name="file1" target="System.Collections" kind="namespace" importlevel="file"/>
<alias name="typefile1" target="System.String" kind="namespace" importlevel="file"/>
<alias name="C3ALIAS" target="TheDefaultNamespace.NS1.NS2.C1.C2.C3" kind="namespace" importlevel="file"/>
<alias name="C3ALIAS" target="DefaultNamespace.NS1.NS2.C1.C2.C3" kind="namespace" importlevel="file"/>
<namespace name="System" importlevel="file"/>
<namespace name="System.Collections.Generic" importlevel="file"/>
<type name="TheDefaultNamespace.NS1.NS2.C1.C2" importlevel="file"/>
<defaultnamespace name="TheDefaultNamespace"/>
<type name="DefaultNamespace.NS1.NS2.C1.C2" importlevel="file"/>
<defaultnamespace name="DefaultNamespace"/>
<xmlnamespace prefix="prjlevel1" name="http://NewNamespace" importlevel="project"/>
<xmlnamespace prefix="" name="http://NewNamespace/prjlevel" importlevel="project"/>
<alias name="prjlevel" target="System.Collections.Generic" kind="namespace" importlevel="project"/>
<alias name="typeproj1" target="System.Int64" kind="namespace" importlevel="project"/>
<namespace name="System.Threading" importlevel="project"/>
<type name="System.Collections.ArrayList" importlevel="project"/>
<currentnamespace name="TheDefaultNamespace.Boo"/>
<currentnamespace name="DefaultNamespace.Boo"/>
</scope>
</method>
<method containingType="TheDefaultNamespace.Boo.C1" name="Main" parameterNames="">
<method containingType="DefaultNamespace.Boo.C1" name="Main" parameterNames="">
<sequencepoints total="3">
<entry il_offset="0x0" start_row="24" start_column="5" end_row="24" end_column="29" file_ref="1"/>
<entry il_offset="0x1" start_row="25" start_column="9" end_row="25" end_column="42" file_ref="1"/>
......@@ -318,10 +318,10 @@ End Namespace
</sequencepoints>
<locals/>
<scope startOffset="0x0" endOffset="0xd">
<importsforward declaringType="TheDefaultNamespace.Boo.C1" methodName=".ctor" parameterNames=""/>
<importsforward declaringType="DefaultNamespace.Boo.C1" methodName=".ctor" parameterNames=""/>
</scope>
</method>
<method containingType="TheDefaultNamespace.Boo.C1" name="DoStuff" parameterNames="">
<method containingType="DefaultNamespace.Boo.C1" name="DoStuff" parameterNames="">
<sequencepoints total="3">
<entry il_offset="0x0" start_row="28" start_column="5" end_row="28" end_column="32" file_ref="1"/>
<entry il_offset="0x1" start_row="29" start_column="9" end_row="29" end_column="48" file_ref="1"/>
......@@ -329,10 +329,10 @@ End Namespace
</sequencepoints>
<locals/>
<scope startOffset="0x0" endOffset="0xd">
<importsforward declaringType="TheDefaultNamespace.Boo.C1" methodName=".ctor" parameterNames=""/>
<importsforward declaringType="DefaultNamespace.Boo.C1" methodName=".ctor" parameterNames=""/>
</scope>
</method>
<method containingType="TheDefaultNamespace.C2" name="DoStuff2" parameterNames="">
<method containingType="DefaultNamespace.C2" name="DoStuff2" parameterNames="">
<sequencepoints total="3">
<entry il_offset="0x0" start_row="23" start_column="5" end_row="23" end_column="33" file_ref="2"/>
<entry il_offset="0x1" start_row="24" start_column="9" end_row="24" end_column="65" file_ref="2"/>
......@@ -346,14 +346,14 @@ End Namespace
<alias name="typefile2" target="System.Int32" kind="namespace" importlevel="file"/>
<namespace name="System.Diagnostics" importlevel="file"/>
<type name="System.Collections.ArrayList" importlevel="file"/>
<defaultnamespace name="TheDefaultNamespace"/>
<defaultnamespace name="DefaultNamespace"/>
<xmlnamespace prefix="prjlevel1" name="http://NewNamespace" importlevel="project"/>
<xmlnamespace prefix="" name="http://NewNamespace/prjlevel" importlevel="project"/>
<alias name="prjlevel" target="System.Collections.Generic" kind="namespace" importlevel="project"/>
<alias name="typeproj1" target="System.Int64" kind="namespace" importlevel="project"/>
<namespace name="System.Threading" importlevel="project"/>
<type name="System.Collections.ArrayList" importlevel="project"/>
<currentnamespace name="TheDefaultNamespace"/>
<currentnamespace name="DefaultNamespace"/>
</scope>
</method>
</methods>
......
......@@ -646,6 +646,7 @@ private void WriteNamespace(ISymUnmanagedNamespace @namespace)
case 'X':
case 'Z':
case 'E':
case 'T':
scope = ImportScope.Unspecified;
if (!CDI.TryParseCSharpImportString(rawName, out alias, out externAlias, out target, out kind))
{
......
......@@ -729,6 +729,7 @@ public static bool IsCSharpExternAliasInfo(string import)
/// "XOldLib" -> <extern alias="OldLib" />
/// "ZOldLib assembly" -> <externinfo name="OldLib" assembly="assembly" />
/// "ESystem alias" -> <namespace qualifier="alias" name="System" />
/// "TSystem.Math" -> <type name="System.Math" />
/// ]]>
/// </remarks>
public static bool TryParseCSharpImportString(string import, out string alias, out string externAlias, out string target, out ImportTargetKind kind)
......@@ -745,14 +746,14 @@ public static bool TryParseCSharpImportString(string import, out string alias, o
switch (import[0])
{
case 'U': // C# using
case 'U': // C# (namespace) using
alias = null;
externAlias = null;
target = import.Substring(1);
kind = ImportTargetKind.Namespace;
return true;
case 'E': // C# using
case 'E': // C# (namespace) using
// NOTE: Dev12 has related cases "I" and "O" in EMITTER::ComputeDebugNamespace,
// but they were probably implementation details that do not affect roslyn.
if (!TrySplit(import, 1, ' ', out target, out externAlias))
......@@ -764,6 +765,13 @@ public static bool TryParseCSharpImportString(string import, out string alias, o
kind = ImportTargetKind.Namespace;
return true;
case 'T': // C# (type) using
alias = null;
externAlias = null;
target = import.Substring(1);
kind = ImportTargetKind.Type;
return true;
case 'A': // C# type or namespace alias
if (!TrySplit(import, 1, ' ', out alias, out target))
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册