Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
28f41128
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,发现更多精彩内容 >>
提交
28f41128
编写于
1月 05, 2017
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply ComVisible attribute to embedded value types.
Fixes #16177.
上级
84e6e7e5
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
63 addition
and
25 deletion
+63
-25
src/Compilers/CSharp/Portable/Emitter/NoPia/EmbeddedType.cs
src/Compilers/CSharp/Portable/Emitter/NoPia/EmbeddedType.cs
+0
-7
src/Compilers/CSharp/Portable/Emitter/NoPia/EmbeddedTypesManager.cs
...ers/CSharp/Portable/Emitter/NoPia/EmbeddedTypesManager.cs
+17
-0
src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
...s/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
+6
-2
src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
+4
-2
src/Compilers/Core/Portable/Emit/NoPia/CommonEmbeddedType.cs
src/Compilers/Core/Portable/Emit/NoPia/CommonEmbeddedType.cs
+6
-2
src/Compilers/Core/Portable/Emit/NoPia/EmbeddedTypesManager.cs
...ompilers/Core/Portable/Emit/NoPia/EmbeddedTypesManager.cs
+2
-0
src/Compilers/VisualBasic/Portable/Emit/NoPia/EmbeddedType.vb
...Compilers/VisualBasic/Portable/Emit/NoPia/EmbeddedType.vb
+0
-6
src/Compilers/VisualBasic/Portable/Emit/NoPia/EmbeddedTypesManager.vb
...s/VisualBasic/Portable/Emit/NoPia/EmbeddedTypesManager.vb
+15
-0
src/Compilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
...ompilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
+9
-4
src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
+4
-2
未找到文件。
src/Compilers/CSharp/Portable/Emitter/NoPia/EmbeddedType.cs
浏览文件 @
28f41128
...
...
@@ -206,13 +206,6 @@ protected override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(Mo
return
UnderlyingNamedType
.
GetCustomAttributesToEmit
(
compilationState
);
}
protected
override
CSharpAttributeData
CreateCompilerGeneratedAttribute
()
{
Debug
.
Assert
(
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
));
var
compilation
=
TypeManager
.
ModuleBeingBuilt
.
Compilation
;
return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
);
}
protected
override
CSharpAttributeData
CreateTypeIdentifierAttribute
(
bool
hasGuid
,
SyntaxNode
syntaxNodeOpt
,
DiagnosticBag
diagnostics
)
{
var
member
=
hasGuid
?
...
...
src/Compilers/CSharp/Portable/Emitter/NoPia/EmbeddedTypesManager.cs
浏览文件 @
28f41128
...
...
@@ -565,5 +565,22 @@ protected override EmbeddedType GetEmbeddedTypeForMember(Symbol member, SyntaxNo
{
return
underlyingParameters
.
SelectAsArray
((
p
,
c
)
=>
new
EmbeddedParameter
(
c
,
p
),
containingPropertyOrMethod
);
}
protected
override
CSharpAttributeData
CreateCompilerGeneratedAttribute
()
{
Debug
.
Assert
(
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
));
var
compilation
=
ModuleBeingBuilt
.
Compilation
;
return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
);
}
protected
override
CSharpAttributeData
CreateComVisibleAttribute
()
{
var
compilation
=
ModuleBeingBuilt
.
Compilation
;
return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_InteropServices_ComVisibleAttribute__ctor
,
ImmutableArray
.
Create
(
new
TypedConstant
(
compilation
.
GetSpecialType
(
SpecialType
.
System_Boolean
),
TypedConstantKind
.
Primitive
,
value
:
true
)),
isOptionalUse
:
true
);
}
}
}
src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs
浏览文件 @
28f41128
...
...
@@ -306,10 +306,14 @@ internal static Symbol GetRuntimeMember(NamedTypeSymbol declaringType, ref Membe
/// If the well-known member does not exist in the compilation then no attribute
/// will be synthesized.
/// </param>
/// <param name="isOptionalUse">
/// Indicates if this particular attribute application should be considered optional.
/// </param>
internal
SynthesizedAttributeData
TrySynthesizeAttribute
(
WellKnownMember
constructor
,
ImmutableArray
<
TypedConstant
>
arguments
=
default
(
ImmutableArray
<
TypedConstant
>),
ImmutableArray
<
KeyValuePair
<
WellKnownMember
,
TypedConstant
>>
namedArguments
=
default
(
ImmutableArray
<
KeyValuePair
<
WellKnownMember
,
TypedConstant
>>))
ImmutableArray
<
KeyValuePair
<
WellKnownMember
,
TypedConstant
>>
namedArguments
=
default
(
ImmutableArray
<
KeyValuePair
<
WellKnownMember
,
TypedConstant
>>),
bool
isOptionalUse
=
false
)
{
DiagnosticInfo
diagnosticInfo
;
var
ctorSymbol
=
(
MethodSymbol
)
Binder
.
GetWellKnownTypeMember
(
this
,
constructor
,
out
diagnosticInfo
,
isOptional
:
true
);
...
...
@@ -317,7 +321,7 @@ internal static Symbol GetRuntimeMember(NamedTypeSymbol declaringType, ref Membe
if
((
object
)
ctorSymbol
==
null
)
{
// if this assert fails, UseSiteErrors for "member" have not been checked before emitting ...
Debug
.
Assert
(
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
constructor
));
Debug
.
Assert
(
isOptionalUse
||
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
constructor
));
return
null
;
}
...
...
src/Compilers/CSharp/Test/Emit/Emit/NoPiaEmbedTypes.cs
浏览文件 @
28f41128
...
...
@@ -1201,9 +1201,10 @@ public void M6(ITest26 x)
Assert
.
Equal
(
TypeAttributes
.
Public
|
TypeAttributes
.
SequentialLayout
|
TypeAttributes
.
Class
|
TypeAttributes
.
Sealed
|
TypeAttributes
.
AnsiClass
|
TypeAttributes
.
BeforeFieldInit
,
test2
.
Flags
);
attributes
=
test2
.
GetAttributes
();
Assert
.
Equal
(
2
,
attributes
.
Length
);
Assert
.
Equal
(
3
,
attributes
.
Length
);
Assert
.
Equal
(
"System.Runtime.CompilerServices.CompilerGeneratedAttribute"
,
attributes
[
0
].
ToString
());
Assert
.
Equal
(
@"System.Runtime.InteropServices.TypeIdentifierAttribute(""f9c2d51d-4f44-45f0-9eda-c9d599b58257"", ""Test2"")"
,
attributes
[
1
].
ToString
());
Assert
.
Equal
(
"System.Runtime.InteropServices.ComVisibleAttribute(true)"
,
attributes
[
2
].
ToString
());
var
itest3
=
module
.
GlobalNamespace
.
GetTypeMembers
(
"ITest3"
).
Single
();
Assert
.
Equal
(
TypeKind
.
Interface
,
itest3
.
TypeKind
);
...
...
@@ -1261,9 +1262,10 @@ public void M6(ITest26 x)
Assert
.
Equal
(
TypeAttributes
.
Public
|
TypeAttributes
.
AutoLayout
|
TypeAttributes
.
Class
|
TypeAttributes
.
Sealed
|
TypeAttributes
.
AnsiClass
,
test9
.
Flags
);
attributes
=
test9
.
GetAttributes
();
Assert
.
Equal
(
2
,
attributes
.
Length
);
Assert
.
Equal
(
3
,
attributes
.
Length
);
Assert
.
Equal
(
"System.Runtime.CompilerServices.CompilerGeneratedAttribute"
,
attributes
[
0
].
ToString
());
Assert
.
Equal
(
@"System.Runtime.InteropServices.TypeIdentifierAttribute(""f9c2d51d-4f44-45f0-9eda-c9d599b58257"", ""Test9"")"
,
attributes
[
1
].
ToString
());
Assert
.
Equal
(
"System.Runtime.InteropServices.ComVisibleAttribute(true)"
,
attributes
[
2
].
ToString
());
var
fieldToEmit
=
test9
.
GetFieldsToEmit
().
ToArray
().
AsImmutableOrNull
();
Assert
.
Equal
(
3
,
fieldToEmit
.
Length
);
...
...
src/Compilers/Core/Portable/Emit/NoPia/CommonEmbeddedType.cs
浏览文件 @
28f41128
...
...
@@ -68,7 +68,6 @@ protected CommonEmbeddedType(TEmbeddedTypesManager typeManager, TNamedTypeSymbol
protected
abstract
bool
IsSealed
{
get
;
}
protected
abstract
TypeLayout
?
GetTypeLayoutIfStruct
();
protected
abstract
System
.
Runtime
.
InteropServices
.
CharSet
StringFormat
{
get
;
}
protected
abstract
TAttributeData
CreateCompilerGeneratedAttribute
();
protected
abstract
TAttributeData
CreateTypeIdentifierAttribute
(
bool
hasGuid
,
TSyntaxNode
syntaxNodeOpt
,
DiagnosticBag
diagnostics
);
protected
abstract
void
EmbedDefaultMembers
(
string
defaultMember
,
TSyntaxNode
syntaxNodeOpt
,
DiagnosticBag
diagnostics
);
protected
abstract
IEnumerable
<
TAttributeData
>
GetCustomAttributesToEmit
(
TModuleCompilationState
compilationState
);
...
...
@@ -85,7 +84,7 @@ private ImmutableArray<TAttributeData> GetAttributes(TModuleCompilationState com
// Put the CompilerGenerated attribute on the NoPIA types we define so that
// static analysis tools (e.g. fxcop) know that they can be skipped
builder
.
AddOptional
(
CreateCompilerGeneratedAttribute
());
builder
.
AddOptional
(
TypeManager
.
CreateCompilerGeneratedAttribute
());
// Copy some of the attributes.
...
...
@@ -204,6 +203,11 @@ private ImmutableArray<TAttributeData> GetAttributes(TModuleCompilationState com
builder
.
AddOptional
(
CreateTypeIdentifierAttribute
(
hasGuid
&&
IsInterface
,
syntaxNodeOpt
,
diagnostics
));
if
(
UnderlyingNamedType
.
IsValueType
)
{
builder
.
AddOptional
(
TypeManager
.
CreateComVisibleAttribute
());
}
return
builder
.
ToImmutableAndFree
();
}
...
...
src/Compilers/Core/Portable/Emit/NoPia/EmbeddedTypesManager.cs
浏览文件 @
28f41128
...
...
@@ -155,6 +155,8 @@ internal bool IsTargetAttribute(TSymbol underlyingSymbol, TAttributeData attrDat
protected
abstract
void
OnGetTypesCompleted
(
ImmutableArray
<
TEmbeddedType
>
types
,
DiagnosticBag
diagnostics
);
protected
abstract
void
ReportNameCollisionBetweenEmbeddedTypes
(
TEmbeddedType
typeA
,
TEmbeddedType
typeB
,
DiagnosticBag
diagnostics
);
protected
abstract
void
ReportNameCollisionWithAlreadyDeclaredType
(
TEmbeddedType
type
,
DiagnosticBag
diagnostics
);
protected
abstract
TAttributeData
CreateCompilerGeneratedAttribute
();
protected
abstract
TAttributeData
CreateComVisibleAttribute
();
private
sealed
class
TypeComparer
:
IComparer
<
TEmbeddedType
>
{
...
...
src/Compilers/VisualBasic/Portable/Emit/NoPia/EmbeddedType.vb
浏览文件 @
28f41128
...
...
@@ -158,12 +158,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit.NoPia
Return
UnderlyingNamedType
.
GetCustomAttributesToEmit
(
compilationState
)
End
Function
Protected
Overrides
Function
CreateCompilerGeneratedAttribute
()
As
VisualBasicAttributeData
Debug
.
Assert
(
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
))
Dim
compilation
=
TypeManager
.
ModuleBeingBuilt
.
Compilation
Return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
)
End
Function
Protected
Overrides
Function
CreateTypeIdentifierAttribute
(
hasGuid
As
Boolean
,
syntaxNodeOpt
As
SyntaxNode
,
diagnostics
As
DiagnosticBag
)
As
VisualBasicAttributeData
Dim
member
=
If
(
hasGuid
,
WellKnownMember
.
System_Runtime_InteropServices_TypeIdentifierAttribute__ctor
,
...
...
src/Compilers/VisualBasic/Portable/Emit/NoPia/EmbeddedTypesManager.vb
浏览文件 @
28f41128
...
...
@@ -488,6 +488,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit.NoPia
Return
underlyingParameters
.
SelectAsArray
(
Function
(
parameter
,
container
)
New
EmbeddedParameter
(
container
,
parameter
),
containingPropertyOrMethod
)
End
Function
Protected
Overrides
Function
CreateCompilerGeneratedAttribute
()
As
VisualBasicAttributeData
Debug
.
Assert
(
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
))
Dim
compilation
=
ModuleBeingBuilt
.
Compilation
Return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor
)
End
Function
Protected
Overrides
Function
CreateComVisibleAttribute
()
As
VisualBasicAttributeData
Dim
compilation
=
ModuleBeingBuilt
.
Compilation
Return
compilation
.
TrySynthesizeAttribute
(
WellKnownMember
.
System_Runtime_InteropServices_ComVisibleAttribute__ctor
,
ImmutableArray
.
Create
(
New
TypedConstant
(
compilation
.
GetSpecialType
(
SpecialType
.
System_Boolean
),
TypedConstantKind
.
Primitive
,
value
:
=
True
)),
isOptionalUse
:
=
True
)
End
Function
End
Class
End
Namespace
src/Compilers/VisualBasic/Portable/Symbols/WellKnownMembers.vb
浏览文件 @
28f41128
...
...
@@ -136,15 +136,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' If the well-known member does Not exist in the compilation then no attribute
''' will be synthesized.
''' </param>
''' <param name="isOptionalUse">
''' Indicates if this particular attribute application should be considered optional.
''' </param>
Friend
Function
TrySynthesizeAttribute
(
constructor
As
WellKnownMember
,
Optional
arguments
As
ImmutableArray
(
Of
TypedConstant
)
=
Nothing
,
Optional
namedArguments
As
ImmutableArray
(
Of
KeyValuePair
(
Of
WellKnownMember
,
TypedConstant
))
=
Nothing
)
As
SynthesizedAttributeData
Optional
namedArguments
As
ImmutableArray
(
Of
KeyValuePair
(
Of
WellKnownMember
,
TypedConstant
))
=
Nothing
,
Optional
isOptionalUse
As
Boolean
=
False
)
As
SynthesizedAttributeData
Dim
constructorSymbol
=
TryCast
(
GetWellKnownTypeMember
(
constructor
),
MethodSymbol
)
If
constructorSymbol
Is
Nothing
OrElse
Binder
.
GetUseSiteErrorForWellKnownTypeMember
(
constructorSymbol
,
constructor
,
False
)
IsNot
Nothing
Then
Return
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
)
Return
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
,
isOptionalUse
)
End
If
If
arguments
.
IsDefault
Then
...
...
@@ -172,8 +177,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
New
SynthesizedAttributeData
(
constructorSymbol
,
arguments
,
namedStringArguments
)
End
Function
Private
Function
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
As
WellKnownMember
)
As
SynthesizedAttributeData
If
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
constructor
)
Then
Private
Function
ReturnNothingOrThrowIfAttributeNonOptional
(
constructor
As
WellKnownMember
,
Optional
isOptionalUse
As
Boolean
=
False
)
As
SynthesizedAttributeData
If
isOptionalUse
OrElse
WellKnownMembers
.
IsSynthesizedAttributeOptional
(
constructor
)
Then
Return
Nothing
Else
Throw
ExceptionUtilities
.
Unreachable
...
...
src/Compilers/VisualBasic/Test/Emit/Emit/NoPiaEmbedTypes.vb
浏览文件 @
28f41128
...
...
@@ -1033,9 +1033,10 @@ End Class
Assert
.
Equal
(
TypeAttributes
.
Public
Or
TypeAttributes
.
SequentialLayout
Or
TypeAttributes
.
Class
Or
TypeAttributes
.
Sealed
Or
TypeAttributes
.
AnsiClass
Or
TypeAttributes
.
BeforeFieldInit
,
test2
.
TypeDefFlags
)
attributes
=
test2
.
GetAttributes
()
Assert
.
Equal
(
2
,
attributes
.
Length
)
Assert
.
Equal
(
3
,
attributes
.
Length
)
Assert
.
Equal
(
"System.Runtime.CompilerServices.CompilerGeneratedAttribute"
,
attributes
(
0
).
ToString
())
Assert
.
Equal
(
"System.Runtime.InteropServices.TypeIdentifierAttribute(
""
f9c2d51d-4f44-45f0-9eda-c9d599b58257
""
,
""
Test2
""
)"
,
attributes
(
1
).
ToString
())
Assert
.
Equal
(
"System.Runtime.InteropServices.ComVisibleAttribute(True)"
,
attributes
(
2
).
ToString
())
Dim
itest3
=
[
module
]
.
GlobalNamespace
.
GetMember
(
Of
NamedTypeSymbol
)(
"ITest3"
)
Assert
.
Equal
(
TypeKind
.
Interface
,
itest3
.
TypeKind
)
...
...
@@ -1093,9 +1094,10 @@ End Class
Assert
.
Equal
(
TypeAttributes
.
Public
Or
TypeAttributes
.
AutoLayout
Or
TypeAttributes
.
Class
Or
TypeAttributes
.
Sealed
Or
TypeAttributes
.
AnsiClass
,
test9
.
TypeDefFlags
)
attributes
=
test9
.
GetAttributes
()
Assert
.
Equal
(
2
,
attributes
.
Length
)
Assert
.
Equal
(
3
,
attributes
.
Length
)
Assert
.
Equal
(
"System.Runtime.CompilerServices.CompilerGeneratedAttribute"
,
attributes
(
0
).
ToString
())
Assert
.
Equal
(
"System.Runtime.InteropServices.TypeIdentifierAttribute(
""
f9c2d51d-4f44-45f0-9eda-c9d599b58257
""
,
""
Test9
""
)"
,
attributes
(
1
).
ToString
())
Assert
.
Equal
(
"System.Runtime.InteropServices.ComVisibleAttribute(True)"
,
attributes
(
2
).
ToString
())
Dim
fieldToEmit
=
test9
.
GetFieldsToEmit
().
ToArray
().
AsImmutableOrNull
()
Assert
.
Equal
(
3
,
fieldToEmit
.
Length
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录