Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5b5d4313
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,发现更多精彩内容 >>
提交
5b5d4313
编写于
10月 05, 2015
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Intrinsic method assembly should not be dropped
上级
194da7ce
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
177 addition
and
47 deletion
+177
-47
src/Compilers/CSharp/Portable/Symbols/AssemblySymbol.cs
src/Compilers/CSharp/Portable/Symbols/AssemblySymbol.cs
+8
-10
src/Compilers/Core/Portable/MetadataReader/MetadataReaderExtensions.cs
.../Core/Portable/MetadataReader/MetadataReaderExtensions.cs
+16
-6
src/Compilers/VisualBasic/Portable/Symbols/AssemblySymbol.vb
src/Compilers/VisualBasic/Portable/Symbols/AssemblySymbol.vb
+11
-13
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
...or/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
+1
-0
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
.../CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
+115
-8
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
...ionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
+1
-0
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/ExpressionCompilerConstants.cs
.../Source/ExpressionCompiler/ExpressionCompilerConstants.cs
+3
-1
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
...uator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
+11
-0
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs
.../Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs
+2
-1
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/MissingAssemblyTests.vb
...sualBasic/Test/ExpressionCompiler/MissingAssemblyTests.vb
+1
-0
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ReferencedModulesTests.vb
...alBasic/Test/ExpressionCompiler/ReferencedModulesTests.vb
+8
-8
未找到文件。
src/Compilers/CSharp/Portable/Symbols/AssemblySymbol.cs
浏览文件 @
5b5d4313
...
...
@@ -535,22 +535,20 @@ public NamedTypeSymbol GetTypeByMetadataName(string fullyQualifiedMetadataName)
bool
useCLSCompliantNameArityEncoding
=
false
,
DiagnosticBag
warnings
=
null
)
{
NamedTypeSymbol
type
=
null
;
NamedTypeSymbol
type
;
MetadataTypeName
mdName
;
if
(
metadataName
.
IndexOf
(
'+'
)
>=
0
)
{
var
parts
=
metadataName
.
Split
(
s_nestedTypeNameSeparators
);
if
(
parts
.
Length
>
0
)
Debug
.
Assert
(
parts
.
Length
>
0
);
mdName
=
MetadataTypeName
.
FromFullName
(
parts
[
0
],
useCLSCompliantNameArityEncoding
);
type
=
GetTopLevelTypeByMetadataName
(
ref
mdName
,
assemblyOpt
:
null
,
includeReferences
:
includeReferences
,
isWellKnownType
:
isWellKnownType
,
warnings
:
warnings
);
for
(
int
i
=
1
;
(
object
)
type
!=
null
&&
!
type
.
IsErrorType
()
&&
i
<
parts
.
Length
;
i
++)
{
mdName
=
MetadataTypeName
.
FromFullName
(
parts
[
0
],
useCLSCompliantNameArityEncoding
);
type
=
GetTopLevelTypeByMetadataName
(
ref
mdName
,
assemblyOpt
:
null
,
includeReferences
:
includeReferences
,
isWellKnownType
:
isWellKnownType
,
warnings
:
warnings
);
for
(
int
i
=
1
;
(
object
)
type
!=
null
&&
!
type
.
IsErrorType
()
&&
i
<
parts
.
Length
;
i
++)
{
mdName
=
MetadataTypeName
.
FromTypeName
(
parts
[
i
]);
NamedTypeSymbol
temp
=
type
.
LookupMetadataType
(
ref
mdName
);
type
=
(!
isWellKnownType
||
IsValidWellKnownType
(
temp
))
?
temp
:
null
;
}
mdName
=
MetadataTypeName
.
FromTypeName
(
parts
[
i
]);
NamedTypeSymbol
temp
=
type
.
LookupMetadataType
(
ref
mdName
);
type
=
(!
isWellKnownType
||
IsValidWellKnownType
(
temp
))
?
temp
:
null
;
}
}
else
...
...
src/Compilers/Core/Portable/MetadataReader/MetadataReaderExtensions.cs
浏览文件 @
5b5d4313
...
...
@@ -159,15 +159,24 @@ internal static Guid GetModuleVersionIdOrThrow(this MetadataReader reader)
}
internal
static
bool
DeclaresTheObjectClass
(
this
MetadataReader
reader
)
{
return
reader
.
DeclaresType
(
IsTheObjectClass
);
}
private
static
bool
IsTheObjectClass
(
this
MetadataReader
reader
,
TypeDefinition
typeDef
)
{
return
typeDef
.
BaseType
.
IsNil
&&
reader
.
IsPublicNonInterfaceType
(
typeDef
,
"System"
,
"Object"
);
}
internal
static
bool
DeclaresType
(
this
MetadataReader
reader
,
Func
<
MetadataReader
,
TypeDefinition
,
bool
>
predicate
)
{
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
))
if
(
predicate
(
reader
,
typeDef
))
{
return
true
;
}
...
...
@@ -181,10 +190,11 @@ internal static bool DeclaresTheObjectClass(this MetadataReader reader)
}
/// <exception cref="BadImageFormatException">An exception from metadata reader.</exception>
private
static
bool
IsSystemObjectOrThrow
(
this
MetadataReader
reader
,
TypeDefinition
typeDef
)
internal
static
bool
IsPublicNonInterfaceType
(
this
MetadataReader
reader
,
TypeDefinition
typeDef
,
string
namespaceName
,
string
typeName
)
{
return
reader
.
StringComparer
.
Equals
(
typeDef
.
Name
,
"Object"
)
&&
reader
.
StringComparer
.
Equals
(
typeDef
.
Namespace
,
"System"
);
return
(
typeDef
.
Attributes
&
(
TypeAttributes
.
Public
|
TypeAttributes
.
Interface
))
==
TypeAttributes
.
Public
&&
reader
.
StringComparer
.
Equals
(
typeDef
.
Name
,
typeName
)
&&
reader
.
StringComparer
.
Equals
(
typeDef
.
Namespace
,
namespaceName
);
}
}
}
src/Compilers/VisualBasic/Portable/Symbols/AssemblySymbol.vb
浏览文件 @
5b5d4313
...
...
@@ -436,26 +436,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Throw
New
ArgumentNullException
(
NameOf
(
metadataName
))
End
If
Dim
type
As
NamedTypeSymbol
=
Nothing
Dim
type
As
NamedTypeSymbol
Dim
mdName
As
MetadataTypeName
If
metadataName
.
Contains
(
"+"
c
)
Then
Dim
parts
()
As
String
=
metadataName
.
Split
(
s_nestedTypeNameSeparators
)
Debug
.
Assert
(
parts
.
Length
>
0
)
mdName
=
MetadataTypeName
.
FromFullName
(
parts
(
0
),
useCLSCompliantNameArityEncoding
)
type
=
GetTopLevelTypeByMetadataName
(
mdName
,
includeReferences
,
isWellKnownType
)
If
parts
.
Length
>
0
Then
mdName
=
MetadataTypeName
.
FromFullName
(
parts
(
0
),
useCLSCompliantNameArityEncoding
)
type
=
GetTopLevelTypeByMetadataName
(
mdName
,
includeReferences
,
isWellKnownType
)
Dim
i
As
Integer
=
1
Dim
i
As
Integer
=
1
While
type
IsNot
Nothing
AndAlso
Not
type
.
IsErrorType
()
AndAlso
i
<
parts
.
Length
mdName
=
MetadataTypeName
.
FromTypeName
(
parts
(
i
))
Dim
temp
=
type
.
LookupMetadataType
(
mdName
)
type
=
If
(
Not
isWellKnownType
OrElse
IsValidWellKnownType
(
temp
),
temp
,
Nothing
)
i
+=
1
End
While
End
If
While
type
IsNot
Nothing
AndAlso
Not
type
.
IsErrorType
()
AndAlso
i
<
parts
.
Length
mdName
=
MetadataTypeName
.
FromTypeName
(
parts
(
i
))
Dim
temp
=
type
.
LookupMetadataType
(
mdName
)
type
=
If
(
Not
isWellKnownType
OrElse
IsValidWellKnownType
(
temp
),
temp
,
Nothing
)
i
+=
1
End
While
Else
mdName
=
MetadataTypeName
.
FromFullName
(
metadataName
,
useCLSCompliantNameArityEncoding
)
type
=
GetTopLevelTypeByMetadataName
(
mdName
,
includeReferences
,
isWellKnownType
)
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
浏览文件 @
5b5d4313
...
...
@@ -694,6 +694,7 @@ class UseLinq
var
compileResult
=
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
runtime
.
Modules
.
Select
(
m
=>
m
.
MetadataBlock
).
ToImmutableArray
(),
"args.Where(a => a.Length > 0)"
,
ImmutableArray
<
Alias
>.
Empty
,
(
_1
,
_2
)
=>
context
,
// ignore new blocks and just keep using the same failed context...
(
AssemblyIdentity
assemblyIdentity
,
out
uint
uSize
)
=>
{
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
浏览文件 @
5b5d4313
...
...
@@ -388,22 +388,22 @@ static void M()
var
contextFactory
=
CreateTypeContextFactory
(
moduleVersionId
,
typeToken
);
// Duplicate type in namespace, at type scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new N.C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new N.C1()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
True
(
errorMessage
.
StartsWith
(
"error CS0433: The type 'C1' exists in both "
));
GetContextState
(
runtime
,
"B.M"
,
out
blocks
,
out
moduleVersionId
,
out
symReader
,
out
methodToken
,
out
localSignatureToken
);
contextFactory
=
CreateMethodContextFactory
(
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
);
// Duplicate type in namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C1()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
True
(
errorMessage
.
StartsWith
(
"error CS0433: The type 'C1' exists in both "
));
// Duplicate type in global namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C2()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C2()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
True
(
errorMessage
.
StartsWith
(
"error CS0433: The type 'C2' exists in both "
));
// Duplicate extension method, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Equal
(
errorMessage
,
"(1,3): error CS0121: The call is ambiguous between the following methods or properties: 'N.E.F(A)' and 'N.E.F(A)'"
);
// Same tests as above but in library that does not directly reference duplicates.
...
...
@@ -411,7 +411,7 @@ static void M()
contextFactory
=
CreateTypeContextFactory
(
moduleVersionId
,
typeToken
);
// Duplicate type in namespace, at type scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new N.C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new N.C1()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Null
(
errorMessage
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
methodData
.
VerifyIL
(
...
...
@@ -427,7 +427,7 @@ .maxstack 1
contextFactory
=
CreateMethodContextFactory
(
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
);
// Duplicate type in global namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C2()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"new C2()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Null
(
errorMessage
);
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
methodData
.
VerifyIL
(
...
...
@@ -442,7 +442,7 @@ .maxstack 1
Assert
.
Equal
(
methodData
.
Method
.
ReturnType
.
ContainingAssembly
.
ToDisplayString
(),
identityA
.
GetDisplayName
());
// Duplicate extension method, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Null
(
errorMessage
);
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
methodData
.
VerifyIL
(
...
...
@@ -544,7 +544,7 @@ class C
// Compile: [DebuggerDisplay("{new B()}")]
const
string
expr
=
"new B()"
;
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
expr
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
expr
,
ImmutableArray
<
Alias
>.
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Null
(
errorMessage
);
Assert
.
Equal
(
2
,
attempts
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
...
...
@@ -656,6 +656,113 @@ .maxstack 1
}
}
/// <summary>
/// Intrinsic methods assembly should not be dropped.
/// </summary>
[
WorkItem
(
4140
)]
[
Fact
]
public
void
IntrinsicMethods
()
{
var
sourceA
=
@"public class A { }"
;
var
sourceB
=
@"public class A { }
public class B
{
static void M(A a)
{
}
}"
;
var
assemblyNameA
=
ExpressionCompilerUtilities
.
GenerateUniqueName
();
var
compilationA
=
CreateCompilationWithMscorlibAndSystemCore
(
sourceA
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
assemblyNameA
);
byte
[]
exeBytesA
;
byte
[]
pdbBytesA
;
ImmutableArray
<
MetadataReference
>
referencesA
;
compilationA
.
EmitAndGetReferences
(
out
exeBytesA
,
out
pdbBytesA
,
out
referencesA
);
var
referenceA
=
AssemblyMetadata
.
CreateFromImage
(
exeBytesA
).
GetReference
(
display
:
assemblyNameA
);
var
identityA
=
referenceA
.
GetAssemblyIdentity
();
var
moduleA
=
referenceA
.
ToModuleInstance
(
exeBytesA
,
new
SymReader
(
pdbBytesA
));
var
assemblyNameB
=
ExpressionCompilerUtilities
.
GenerateUniqueName
();
var
compilationB
=
CreateCompilationWithMscorlibAndSystemCore
(
sourceB
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
assemblyNameB
,
references
:
new
[]
{
referenceA
});
byte
[]
exeBytesB
;
byte
[]
pdbBytesB
;
ImmutableArray
<
MetadataReference
>
referencesB
;
compilationB
.
EmitAndGetReferences
(
out
exeBytesB
,
out
pdbBytesB
,
out
referencesB
);
var
referenceB
=
AssemblyMetadata
.
CreateFromImage
(
exeBytesB
).
GetReference
(
display
:
assemblyNameB
);
var
moduleB
=
referenceB
.
ToModuleInstance
(
exeBytesB
,
new
SymReader
(
pdbBytesB
));
var
moduleBuilder
=
ArrayBuilder
<
ModuleInstance
>.
GetInstance
();
moduleBuilder
.
AddRange
(
referencesA
.
Select
(
r
=>
r
.
ToModuleInstance
(
null
,
null
)));
moduleBuilder
.
Add
(
moduleA
);
moduleBuilder
.
Add
(
moduleB
);
moduleBuilder
.
Add
(
ExpressionCompilerTestHelpers
.
IntrinsicAssemblyReference
.
ToModuleInstance
(
fullImage
:
null
,
symReader
:
null
));
var
modules
=
moduleBuilder
.
ToImmutableAndFree
();
using
(
var
runtime
=
new
RuntimeInstance
(
modules
))
{
ImmutableArray
<
MetadataBlock
>
blocks
;
Guid
moduleVersionId
;
ISymUnmanagedReader
symReader
;
int
methodToken
;
int
localSignatureToken
;
GetContextState
(
runtime
,
"B.M"
,
out
blocks
,
out
moduleVersionId
,
out
symReader
,
out
methodToken
,
out
localSignatureToken
);
var
aliases
=
ImmutableArray
.
Create
(
ExceptionAlias
(
typeof
(
ArgumentException
)),
ReturnValueAlias
(
2
,
typeof
(
string
)),
ObjectIdAlias
(
1
,
typeof
(
object
)));
int
attempts
=
0
;
ExpressionCompiler
.
CreateContextDelegate
contextFactory
=
(
b
,
u
)
=>
{
attempts
++;
return
EvaluationContext
.
CreateMethodContext
(
ToCompilation
(
b
,
u
,
moduleVersionId
),
symReader
,
moduleVersionId
,
methodToken
,
methodVersion
:
1
,
ilOffset
:
0
,
localSignatureToken
:
localSignatureToken
);
};
string
errorMessage
;
CompilationTestData
testData
;
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"(object)new A() ?? $exception ?? $1 ?? $ReturnValue2"
,
aliases
,
contextFactory
,
getMetaDataBytesPtr
:
null
,
errorMessage
:
out
errorMessage
,
testData
:
out
testData
);
Assert
.
Null
(
errorMessage
);
Assert
.
Equal
(
2
,
attempts
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
methodData
.
VerifyIL
(
@"{
// Code size 49 (0x31)
.maxstack 2
IL_0000: newobj ""A..ctor()""
IL_0005: dup
IL_0006: brtrue.s IL_0030
IL_0008: pop
IL_0009: call ""System.Exception Microsoft.VisualStudio.Debugger.Clr.IntrinsicMethods.GetException()""
IL_000e: castclass ""System.ArgumentException""
IL_0013: dup
IL_0014: brtrue.s IL_0030
IL_0016: pop
IL_0017: ldstr ""$1""
IL_001c: call ""object Microsoft.VisualStudio.Debugger.Clr.IntrinsicMethods.GetObjectByAlias(string)""
IL_0021: dup
IL_0022: brtrue.s IL_0030
IL_0024: pop
IL_0025: ldc.i4.2
IL_0026: call ""object Microsoft.VisualStudio.Debugger.Clr.IntrinsicMethods.GetReturnValue(int)""
IL_002b: castclass ""string""
IL_0030: ret
}"
);
}
}
private
static
ExpressionCompiler
.
CreateContextDelegate
CreateTypeContextFactory
(
Guid
moduleVersionId
,
int
typeToken
)
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
浏览文件 @
5b5d4313
...
...
@@ -347,6 +347,7 @@ static void M(C c)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
runtime
.
Modules
.
SelectAsArray
(
m
=>
m
.
MetadataBlock
),
"c.Dispatcher"
,
ImmutableArray
<
Alias
>.
Empty
,
(
metadataBlocks
,
_
)
=>
{
return
CreateMethodContext
(
runtime
,
"C.M"
);
...
...
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/ExpressionCompilerConstants.cs
浏览文件 @
5b5d4313
...
...
@@ -8,7 +8,9 @@ internal static class ExpressionCompilerConstants
{
internal
const
string
TypeVariablesLocalName
=
"<>TypeVariables"
;
internal
const
string
TypeVariablesClassName
=
"<>c__TypeVariables"
;
internal
const
string
IntrinsicAssemblyTypeMetadataName
=
"Microsoft.VisualStudio.Debugger.Clr.IntrinsicMethods"
;
internal
const
string
IntrinsicAssemblyNamespace
=
"Microsoft.VisualStudio.Debugger.Clr"
;
internal
const
string
IntrinsicAssemblyTypeName
=
"IntrinsicMethods"
;
internal
const
string
IntrinsicAssemblyTypeMetadataName
=
IntrinsicAssemblyNamespace
+
"."
+
IntrinsicAssemblyTypeName
;
internal
const
string
GetExceptionMethodName
=
"GetException"
;
internal
const
string
GetStowedExceptionMethodName
=
"GetStowedException"
;
internal
const
string
GetObjectAtAddressMethodName
=
"GetObjectAtAddress"
;
...
...
src/ExpressionEvaluator/Core/Source/ExpressionCompiler/MetadataUtilities.cs
浏览文件 @
5b5d4313
...
...
@@ -87,6 +87,7 @@ internal static class MetadataUtilities
var
referencesBuilder
=
ArrayBuilder
<
MetadataReference
>.
GetInstance
();
var
identitiesBuilder
=
(
identityComparer
==
null
)
?
null
:
ArrayBuilder
<
AssemblyIdentity
>.
GetInstance
();
AssemblyIdentity
corLibrary
=
null
;
AssemblyIdentity
intrinsicsAssembly
=
null
;
foreach
(
var
metadata
in
metadataBuilder
)
{
...
...
@@ -107,6 +108,11 @@ internal static class MetadataUtilities
{
corLibrary
=
identity
;
}
else
if
((
intrinsicsAssembly
==
null
)
&&
reader
.
DeclaresType
((
r
,
t
)
=>
r
.
IsPublicNonInterfaceType
(
t
,
ExpressionCompilerConstants
.
IntrinsicAssemblyNamespace
,
ExpressionCompilerConstants
.
IntrinsicAssemblyTypeName
)))
{
intrinsicsAssembly
=
identity
;
}
}
var
reference
=
MakeAssemblyMetadata
(
metadata
,
modulesByName
);
referencesBuilder
.
Add
(
reference
);
...
...
@@ -131,6 +137,11 @@ internal static class MetadataUtilities
{
referencedModules
.
Add
(
corLibrary
);
}
// Ensure Debugger intrinsic methods assembly is included.
if
(
intrinsicsAssembly
!=
null
)
{
referencedModules
.
Add
(
intrinsicsAssembly
);
}
RemoveUnreferencedModules
(
referencesBuilder
,
identitiesBuilder
,
identityComparer
,
referencedModules
);
referencedModules
.
Free
();
}
...
...
src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs
浏览文件 @
5b5d4313
...
...
@@ -253,6 +253,7 @@ internal static class ExpressionCompilerTestHelpers
internal
static
CompileResult
CompileExpressionWithRetry
(
ImmutableArray
<
MetadataBlock
>
metadataBlocks
,
string
expr
,
ImmutableArray
<
Alias
>
aliases
,
ExpressionCompiler
.
CreateContextDelegate
createContext
,
DkmUtilities
.
GetMetadataBytesPtrFunction
getMetaDataBytesPtr
,
out
string
errorMessage
,
...
...
@@ -269,7 +270,7 @@ internal static class ExpressionCompilerTestHelpers
var
compileResult
=
context
.
CompileExpression
(
expr
,
DkmEvaluationFlags
.
TreatAsExpression
,
ImmutableArray
<
Alias
>.
Empty
,
aliases
,
diagnostics
,
out
resultProperties
,
td
);
...
...
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/MissingAssemblyTests.vb
浏览文件 @
5b5d4313
...
...
@@ -545,6 +545,7 @@ End Class"
Dim
compileResult
=
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
runtime
.
Modules
.
Select
(
Function
(
m
)
m
.
MetadataBlock
).
ToImmutableArray
(),
"args.Where(Function(a) a.Length > 0)"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
Function
(
_1
,
_2
)
context
,
' ignore new blocks and just keep using the same failed context...
Function
(
assemblyIdentity
As
AssemblyIdentity
,
ByRef
uSize
As
UInteger
)
retryCount
+=
1
...
...
src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ReferencedModulesTests.vb
浏览文件 @
5b5d4313
...
...
@@ -230,22 +230,22 @@ End Class"
' Duplicate type in namespace, at type scope.
Dim
testData
As
CompilationTestData
=
Nothing
Dim
errorMessage
As
String
=
Nothing
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New N.C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New N.C1()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Equal
(
errorMessage
,
"(1,6): error BC30560: 'C1' is ambiguous in the namespace 'N'."
)
GetContextState
(
runtime
,
"B.Main"
,
blocks
,
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
)
contextFactory
=
CreateMethodContextFactory
(
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
)
' Duplicate type in namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C1()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Equal
(
errorMessage
,
"(1,6): error BC30560: 'C1' is ambiguous in the namespace 'N'."
)
' Duplicate type in global namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C2()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C2()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Equal
(
errorMessage
,
"(1,6): error BC30554: 'C2' is ambiguous."
)
' Duplicate extension method, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
True
(
errorMessage
.
StartsWith
(
"(1,4): error BC30521: Overload resolution failed because no accessible 'F' is most specific for these arguments:"
))
' Same tests as above but in library that does not directly reference duplicates.
...
...
@@ -253,7 +253,7 @@ End Class"
contextFactory
=
CreateTypeContextFactory
(
moduleVersionId
,
typeToken
)
' Duplicate type in namespace, at type scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New N.C1()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New N.C1()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Null
(
errorMessage
)
Dim
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
)
methodData
.
VerifyIL
(
...
...
@@ -269,7 +269,7 @@ End Class"
contextFactory
=
CreateMethodContextFactory
(
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
)
' Duplicate type in global namespace, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C2()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"New C2()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Null
(
errorMessage
)
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
)
methodData
.
VerifyIL
(
...
...
@@ -284,7 +284,7 @@ End Class"
Assert
.
Equal
(
methodData
.
Method
.
ReturnType
.
ContainingAssembly
.
ToDisplayString
(),
identityA
.
GetDisplayName
())
' Duplicate extension method, at method scope.
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"x.F()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Null
(
errorMessage
)
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
)
methodData
.
VerifyIL
(
...
...
@@ -374,7 +374,7 @@ End Class"
Dim
testData
As
New
CompilationTestData
()
Dim
contextFactory
=
CreateMethodContextFactory
(
moduleVersionId
,
symReader
,
methodToken
,
localSignatureToken
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"F()"
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
ExpressionCompilerTestHelpers
.
CompileExpressionWithRetry
(
blocks
,
"F()"
,
ImmutableArray
(
Of
[
Alias
]
).
Empty
,
contextFactory
,
getMetaDataBytesPtr
:
=
Nothing
,
errorMessage
:
=
errorMessage
,
testData
:
=
testData
)
Assert
.
Null
(
errorMessage
)
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
"{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录