Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
9bfdb948
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9bfdb948
编写于
5月 06, 2015
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure mscorlib is included when ignoring unreferenced assemblies
上级
cc6fa894
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
79 addition
and
42 deletion
+79
-42
src/Compilers/Core/Portable/MetadataReader/MetadataReaderExtensions.cs
.../Core/Portable/MetadataReader/MetadataReaderExtensions.cs
+29
-0
src/Compilers/Core/Portable/MetadataReader/PEAssembly.cs
src/Compilers/Core/Portable/MetadataReader/PEAssembly.cs
+2
-7
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
+0
-31
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
.../CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
+7
-1
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
...ionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
+2
-2
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
...uator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
+20
-1
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestUtilities.csproj
...ExpressionCompiler/ExpressionCompilerTestUtilities.csproj
+1
-0
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources.Designer.cs
...luator/Core/Test/ExpressionCompiler/Resources.Designer.cs
+10
-0
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources.resx
...sionEvaluator/Core/Test/ExpressionCompiler/Resources.resx
+8
-0
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources/Empty.dll
...valuator/Core/Test/ExpressionCompiler/Resources/Empty.dll
+0
-0
未找到文件。
src/Compilers/Core/Portable/MetadataReader/MetadataReaderExtensions.cs
浏览文件 @
9bfdb948
...
...
@@ -157,5 +157,34 @@ internal static Guid GetModuleVersionIdOrThrow(this MetadataReader reader)
contentType
:
(
AssemblyContentType
)((
int
)(
flags
&
AssemblyFlags
.
ContentTypeMask
)
>>
9
),
noThrow
:
true
);
}
internal
static
bool
DeclaresTheObjectClass
(
this
MetadataReader
reader
)
{
foreach
(
TypeDefinitionHandle
handle
in
reader
.
TypeDefinitions
)
{
try
{
var
typeDef
=
reader
.
GetTypeDefinition
(
handle
);
if
(
typeDef
.
BaseType
.
IsNil
&&
(
typeDef
.
Attributes
&
(
TypeAttributes
.
Public
|
TypeAttributes
.
Interface
))
==
TypeAttributes
.
Public
&&
reader
.
IsSystemObjectOrThrow
(
typeDef
))
{
return
true
;
}
}
catch
(
BadImageFormatException
)
{
}
}
return
false
;
}
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private
static
bool
IsSystemObjectOrThrow
(
this
MetadataReader
reader
,
TypeDefinition
typeDef
)
{
return
reader
.
StringComparer
.
Equals
(
typeDef
.
Name
,
"Object"
)
&&
reader
.
StringComparer
.
Equals
(
typeDef
.
Namespace
,
"System"
);
}
}
}
src/Compilers/Core/Portable/MetadataReader/PEAssembly.cs
浏览文件 @
9bfdb948
...
...
@@ -167,13 +167,8 @@ internal bool DeclaresTheObjectClass
{
if
(
_lazyDeclaresTheObjectClass
==
ThreeState
.
Unknown
)
{
if
(!
_modules
[
0
].
FindSystemObjectTypeDef
().
IsNil
)
{
_lazyDeclaresTheObjectClass
=
ThreeState
.
True
;
return
true
;
}
_lazyDeclaresTheObjectClass
=
ThreeState
.
False
;
var
value
=
_modules
[
0
].
MetadataReader
.
DeclaresTheObjectClass
();
_lazyDeclaresTheObjectClass
=
value
.
ToThreeState
();
}
return
_lazyDeclaresTheObjectClass
==
ThreeState
.
True
;
...
...
src/Compilers/Core/Portable/MetadataReader/PEModule.cs
浏览文件 @
9bfdb948
...
...
@@ -500,37 +500,6 @@ public bool HasGenericParametersOrThrow(TypeDefinitionHandle typeDef)
extends
=
row
.
BaseType
;
}
internal
TypeDefinitionHandle
FindSystemObjectTypeDef
()
{
MetadataReader
reader
=
MetadataReader
;
foreach
(
TypeDefinitionHandle
handle
in
reader
.
TypeDefinitions
)
{
try
{
var
typeDef
=
reader
.
GetTypeDefinition
(
handle
);
if
(
typeDef
.
BaseType
.
IsNil
&&
(
typeDef
.
Attributes
&
(
TypeAttributes
.
Public
|
TypeAttributes
.
Interface
))
==
TypeAttributes
.
Public
&&
IsSystemObjectOrThrow
(
typeDef
))
{
return
handle
;
}
}
catch
(
BadImageFormatException
)
{
}
}
return
default
(
TypeDefinitionHandle
);
}
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private
bool
IsSystemObjectOrThrow
(
TypeDefinition
typeDef
)
{
return
MetadataReader
.
StringComparer
.
Equals
(
typeDef
.
Name
,
"Object"
)
&&
MetadataReader
.
StringComparer
.
Equals
(
typeDef
.
Namespace
,
"System"
);
}
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
internal
bool
IsNestedTypeDefOrThrow
(
TypeDefinitionHandle
typeDef
)
{
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
浏览文件 @
9bfdb948
...
...
@@ -13,6 +13,7 @@
using
Roslyn.Test.PdbUtilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
using
Resources
=
Microsoft
.
CodeAnalysis
.
ExpressionEvaluator
.
UnitTests
.
Resources
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests
{
...
...
@@ -463,7 +464,7 @@ .maxstack 1
/// compiled against portable framework assemblies.
/// </summary>
[
WorkItem
(
1150981
)]
[
Fact
(
Skip
=
"1150981"
)
]
[
Fact
]
public
void
MissingMscorlib
()
{
var
sourceA
=
...
...
@@ -507,6 +508,10 @@ class C
var
referenceB
=
AssemblyMetadata
.
CreateFromImage
(
exeBytesB
).
GetReference
(
display
:
assemblyNameB
);
var
moduleB
=
referenceB
.
ToModuleInstance
(
exeBytesB
,
new
SymReader
(
pdbBytesB
));
// Include an empty assembly to verify that not all assemblies
// with no references are treated as mscorlib.
var
referenceC
=
AssemblyMetadata
.
CreateFromImage
(
Resources
.
Empty
).
GetReference
();
// At runtime System.Runtime.dll contract assembly is replaced
// by mscorlib.dll and System.Runtime.dll facade assemblies.
var
moduleBuilder
=
ArrayBuilder
<
ModuleInstance
>.
GetInstance
();
...
...
@@ -514,6 +519,7 @@ class C
moduleBuilder
.
Add
(
SystemRuntimeFacadeRef
.
ToModuleInstance
(
null
,
null
));
moduleBuilder
.
Add
(
moduleA
);
moduleBuilder
.
Add
(
moduleB
);
moduleBuilder
.
Add
(
referenceC
.
ToModuleInstance
(
null
,
null
));
var
modules
=
moduleBuilder
.
ToImmutableAndFree
();
using
(
var
runtime
=
new
RuntimeInstance
(
modules
))
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
浏览文件 @
9bfdb948
...
...
@@ -6,15 +6,15 @@
using
Microsoft.CodeAnalysis.ExpressionEvaluator
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.VisualStudio.Debugger.Evaluation
;
using
Roslyn.Test.PdbUtilities
;
using
Roslyn.Test.Utilities
;
using
Roslyn.Utilities
;
using
System
;
using
System.Collections.Immutable
;
using
System.Linq
;
using
System.Reflection.Metadata
;
using
Xunit
;
using
Resources
=
Microsoft
.
CodeAnalysis
.
ExpressionEvaluator
.
UnitTests
.
Resources
;
using
Roslyn.Test.PdbUtilities
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests
{
...
...
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
浏览文件 @
9bfdb948
...
...
@@ -86,6 +86,7 @@ internal static class MetadataUtilities
// Build assembly references from modules in primary module manifests.
var
referencesBuilder
=
ArrayBuilder
<
MetadataReference
>.
GetInstance
();
var
identitiesBuilder
=
(
identityComparer
==
null
)
?
null
:
ArrayBuilder
<
AssemblyIdentity
>.
GetInstance
();
AssemblyIdentity
corLibrary
=
null
;
foreach
(
var
metadata
in
metadataBuilder
)
{
...
...
@@ -95,8 +96,17 @@ internal static class MetadataUtilities
}
if
(
identitiesBuilder
!=
null
)
{
var
identity
=
metadata
.
MetadataReader
.
ReadAssemblyIdentityOrThrow
();
var
reader
=
metadata
.
MetadataReader
;
var
identity
=
reader
.
ReadAssemblyIdentityOrThrow
();
identitiesBuilder
.
Add
(
identity
);
// If this assembly has no references, and declares
// System.Object, assume it is the COR library.
if
((
corLibrary
==
null
)
&&
(
reader
.
AssemblyReferences
.
Count
==
0
)
&&
reader
.
DeclaresTheObjectClass
())
{
corLibrary
=
identity
;
}
}
var
reference
=
MakeAssemblyMetadata
(
metadata
,
modulesByName
);
referencesBuilder
.
Add
(
reference
);
...
...
@@ -112,6 +122,15 @@ internal static class MetadataUtilities
var
referencedModules
=
ArrayBuilder
<
AssemblyIdentity
>.
GetInstance
();
referencedModules
.
Add
(
module
.
MetadataReader
.
ReadAssemblyIdentityOrThrow
());
referencedModules
.
AddRange
(
module
.
MetadataReader
.
GetReferencedAssembliesOrThrow
());
// Ensure COR library is included, otherwise any compilation will fail.
// (Note, an equivalent assembly may have already been included from
// GetReferencedAssembliesOrThrow above but RemoveUnreferencedModules
// allows duplicates.)
Debug
.
Assert
(
corLibrary
!=
null
);
if
(
corLibrary
!=
null
)
{
referencedModules
.
Add
(
corLibrary
);
}
RemoveUnreferencedModules
(
referencesBuilder
,
identitiesBuilder
,
identityComparer
,
referencedModules
);
referencedModules
.
Free
();
}
...
...
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestUtilities.csproj
浏览文件 @
9bfdb948
...
...
@@ -77,6 +77,7 @@
</ItemGroup>
<ItemGroup>
<None
Include=
"packages.config"
/>
<None
Include=
"Resources\Empty.dll"
/>
<None
Include=
"Resources\LibraryA.winmd"
/>
<None
Include=
"Resources\LibraryB.winmd"
/>
<None
Include=
"Resources\NoValidTables.metadata"
/>
...
...
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources.Designer.cs
浏览文件 @
9bfdb948
...
...
@@ -60,6 +60,16 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal
static
byte
[]
Empty
{
get
{
object
obj
=
ResourceManager
.
GetObject
(
"Empty"
,
resourceCulture
);
return
((
byte
[])(
obj
));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
...
...
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources.resx
浏览文件 @
9bfdb948
...
...
@@ -119,6 +119,14 @@
</resheader>
<assembly
alias=
"System.Windows.Forms"
name=
"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
<!--
copy NUL Empty.txt
resgen.exe Empty.txt
al.exe /embed:Empty.resources /t:lib /out:Empty.dll
-->
<data
name=
"Empty"
type=
"System.Resources.ResXFileRef, System.Windows.Forms"
>
<value>
Resources\Empty.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
</value>
</data>
<!--
echo namespace Windows.Data.Text { public sealed class TextSegment { } } > Windows.Data.cs
csc /t:winmdobj Windows.Data.cs
winmdexp.exe /r:"%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\mscorlib.dll" /r:"%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.dll" /r:"%ProgramFiles(x86)%\Microsoft SDKs\Portable\v14.0\110C4FEFF2BA61C0746933A9ED6E248D\Windows.winmd" /out:Windows.Data.winmd Windows.Data.winmdobj
...
...
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/Resources/Empty.dll
0 → 100644
浏览文件 @
9bfdb948
文件已添加
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录