Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
84f97441
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,发现更多精彩内容 >>
提交
84f97441
编写于
11月 10, 2016
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CR feedback
上级
25901a85
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
126 addition
and
24 deletion
+126
-24
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
...harp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Tuples/TupleErrorFieldSymbol.cs
...s/CSharp/Portable/Symbols/Tuples/TupleErrorFieldSymbol.cs
+9
-1
src/Compilers/CSharp/Portable/Symbols/Tuples/TupleFieldSymbol.cs
...pilers/CSharp/Portable/Symbols/Tuples/TupleFieldSymbol.cs
+1
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
+27
-4
src/Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
...Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
+9
-0
src/Compilers/Core/Portable/CodeAnalysisResources.resx
src/Compilers/Core/Portable/CodeAnalysisResources.resx
+3
-0
src/Compilers/Core/Portable/Compilation/Compilation.cs
src/Compilers/Core/Portable/Compilation/Compilation.cs
+8
-0
src/Compilers/Core/Portable/Symbols/ISymbolExtensions.cs
src/Compilers/Core/Portable/Symbols/ISymbolExtensions.cs
+30
-0
src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.vb
...asic/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.vb
+1
-1
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleErrorFieldSymbol.vb
...ualBasic/Portable/Symbols/Tuples/TupleErrorFieldSymbol.vb
+7
-1
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleFieldSymbol.vb
...s/VisualBasic/Portable/Symbols/Tuples/TupleFieldSymbol.vb
+1
-1
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
+24
-4
src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs
...Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs
+1
-6
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
...s/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
+4
-4
未找到文件。
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
浏览文件 @
84f97441
...
...
@@ -418,7 +418,7 @@ private bool CanUseTupleTypeName(INamedTypeSymbol tupleSymbol)
private
static
bool
HasNonDefaultTupleElements
(
INamedTypeSymbol
tupleSymbol
)
{
return
tupleSymbol
.
TupleElements
.
Any
(
e
=>(
object
)
e
!=
e
.
CorrespondingTupleField
);
return
tupleSymbol
.
TupleElements
.
Any
(
e
=>
!
e
.
IsDefaultTupleElement
()
);
}
private
void
AddTupleTypeName
(
INamedTypeSymbol
symbol
)
...
...
src/Compilers/CSharp/Portable/Symbols/Tuples/TupleErrorFieldSymbol.cs
浏览文件 @
84f97441
...
...
@@ -50,7 +50,7 @@ internal sealed class TupleErrorFieldSymbol : SynthesizedFieldSymbolBase
_tupleElementIndex
=
(
object
)
correspondingDefaultFieldOpt
==
null
?
tupleElementIndex
<<
1
:
(
tupleElementIndex
<<
1
)
+
1
;
_isImplicitlyDeclared
=
isImplicitlyDeclared
;
Debug
.
Assert
(
correspondingDefaultFieldOpt
!=
null
||
this
.
IsDefaultTupleElement
);
Debug
.
Assert
(
(
correspondingDefaultFieldOpt
==
null
)
==
this
.
IsDefaultTupleElement
);
Debug
.
Assert
(
correspondingDefaultFieldOpt
==
null
||
correspondingDefaultFieldOpt
.
IsDefaultTupleElement
);
_correspondingDefaultField
=
correspondingDefaultFieldOpt
??
this
;
...
...
@@ -126,6 +126,14 @@ public override bool IsImplicitlyDeclared
}
}
public
override
FieldSymbol
CorrespondingTupleField
{
get
{
return
_correspondingDefaultField
;
}
}
internal
override
bool
SuppressDynamicAttribute
{
get
...
...
src/Compilers/CSharp/Portable/Symbols/Tuples/TupleFieldSymbol.cs
浏览文件 @
84f97441
...
...
@@ -165,7 +165,7 @@ internal class TupleElementFieldSymbol : TupleFieldSymbol
_locations
=
location
==
null
?
ImmutableArray
<
Location
>.
Empty
:
ImmutableArray
.
Create
(
location
);
_isImplicitlyDeclared
=
isImplicitlyDeclared
;
Debug
.
Assert
(
correspondingDefaultFieldOpt
!=
null
||
this
.
IsDefaultTupleElement
);
Debug
.
Assert
(
(
correspondingDefaultFieldOpt
==
null
)
==
this
.
IsDefaultTupleElement
);
Debug
.
Assert
(
correspondingDefaultFieldOpt
==
null
||
correspondingDefaultFieldOpt
.
IsDefaultTupleElement
);
_correspondingDefaultField
=
correspondingDefaultFieldOpt
??
this
;
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
浏览文件 @
84f97441
...
...
@@ -4843,7 +4843,7 @@ private static ImmutableArray<string> GetTupleElementNames(INamedTypeSymbol tupl
return default(ImmutableArray<string>);
}
return elements.SelectAsArray(e => e.
IsImplicitlyDeclared? null: e.Name
);
return elements.SelectAsArray(e => e.
ProvidedTupleElementNameOrNull()
);
}
[Fact]
...
...
@@ -5116,10 +5116,11 @@ public void CreateTupleTypeSymbol_BadNames()
NamedTypeSymbol intType = comp.GetSpecialType(SpecialType.System_Int32);
var vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, intType);
var vt3 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T3).Construct(intType, intType, intType);
// illegal C# identifiers
and blank
var tuple2 = comp.CreateTupleTypeSymbol(vt
2, ImmutableArray.Create("123", " "
));
Assert.Equal(new[] { "123", " " }, GetTupleElementNames(tuple2));
// illegal C# identifiers
, space and null
var tuple2 = comp.CreateTupleTypeSymbol(vt
3, ImmutableArray.Create("123", " ", null
));
Assert.Equal(new[] { "123", " "
, null
}, GetTupleElementNames(tuple2));
// reserved identifiers
var tuple3 = comp.CreateTupleTypeSymbol(vt2, ImmutableArray.Create("return", "class"));
...
...
@@ -5137,6 +5138,28 @@ public void CreateTupleTypeSymbol_BadNames()
}
}
[Fact]
public void CreateTupleTypeSymbol_EmptyNames()
{
var comp = CSharpCompilation.Create("test", references: new[] { MscorlibRef });
NamedTypeSymbol intType = comp.GetSpecialType(SpecialType.System_Int32);
var vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, intType);
// not tuple-compatible underlying type
try
{
// illegal C# identifiers and blank
var tuple2 = comp.CreateTupleTypeSymbol(vt2, ImmutableArray.Create("123", ""));
Assert.True(false);
}
catch (ArgumentException e)
{
Assert.Contains(CodeAnalysisResources.TupleElementNameEmpty, e.Message);
Assert.Contains("1", e.Message);
}
}
[Fact]
public void CreateTupleTypeSymbol_VisualBasicElements()
{
...
...
src/Compilers/Core/Portable/CodeAnalysisResources.Designer.cs
浏览文件 @
84f97441
...
...
@@ -1333,6 +1333,15 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to Tuple element name cannot be an empty string..
/// </summary>
internal
static
string
TupleElementNameEmpty
{
get
{
return
ResourceManager
.
GetString
(
"TupleElementNameEmpty"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to Tuples must have at least two elements..
/// </summary>
...
...
src/Compilers/Core/Portable/CodeAnalysisResources.resx
浏览文件 @
84f97441
...
...
@@ -540,6 +540,9 @@
<data
name=
"TupleElementNameCountMismatch"
xml:space=
"preserve"
>
<value>
If tuple element names are specified, the number of element names must match the cardinality of the tuple.
</value>
</data>
<data
name=
"TupleElementNameEmpty"
xml:space=
"preserve"
>
<value>
Tuple element name cannot be an empty string.
</value>
</data>
<data
name=
"TupleElementLocationCountMismatch"
xml:space=
"preserve"
>
<value>
If tuple element locations are specified, the number of locations must match the cardinality of the tuple.
</value>
</data>
...
...
src/Compilers/Core/Portable/Compilation/Compilation.cs
浏览文件 @
84f97441
...
...
@@ -878,6 +878,14 @@ protected static ImmutableArray<string> CheckTupleElementNames(int cardinality,
throw
new
ArgumentException
(
CodeAnalysisResources
.
TupleElementNameCountMismatch
,
nameof
(
elementNames
));
}
for
(
int
i
=
0
;
i
<
elementNames
.
Length
;
i
++)
{
if
(
elementNames
[
i
]
==
""
)
{
throw
new
ArgumentException
(
CodeAnalysisResources
.
TupleElementNameEmpty
,
$"
{
nameof
(
elementNames
)}
[
{
i
}
]"
);
}
}
if
(
elementNames
.
All
(
n
=>
n
==
null
))
{
return
default
(
ImmutableArray
<
string
>);
...
...
src/Compilers/Core/Portable/Symbols/ISymbolExtensions.cs
浏览文件 @
84f97441
...
...
@@ -58,5 +58,35 @@ public static IMethodSymbol GetConstructedReducedFrom(this IMethodSymbol method)
return
reducedFrom
.
Construct
(
typeArgs
);
}
/// <summary>
/// Returns true if a given field is a nondefault tuple element
/// </summary>
internal
static
bool
IsDefaultTupleElement
(
this
IFieldSymbol
field
)
{
return
(
object
)
field
==
field
.
CorrespondingTupleField
;
}
/// <summary>
/// Returns true if a given field is a tuple element
/// </summary>
internal
static
bool
IsTupleElement
(
this
IFieldSymbol
field
)
{
return
(
object
)
field
.
CorrespondingTupleField
!=
null
;
}
/// <summary>
/// Return the name of the field if the field is an explicitly named tuple element.
/// Otherwise returns null.
/// </summary>
/// <remarks>
/// Note that it is possible for an element to be both "Default" and to have a user provided name.
/// That could happen if the provided name matches the default name such as "Item10"
/// </remarks>
internal
static
string
ProvidedTupleElementNameOrNull
(
this
IFieldSymbol
field
)
{
return
field
.
IsTupleElement
()
&&
!
field
.
IsImplicitlyDeclared
?
field
.
Name
:
null
;
}
}
}
src/Compilers/VisualBasic/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.vb
浏览文件 @
84f97441
...
...
@@ -322,7 +322,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Function
Private
Shared
Function
HasNonDefaultTupleElements
(
tupleSymbol
As
INamedTypeSymbol
)
As
Boolean
Return
tupleSymbol
.
TupleElements
.
Any
(
Function
(
e
)
e
IsNot
e
.
CorrespondingTupleField
)
Return
tupleSymbol
.
TupleElements
.
Any
(
Function
(
e
)
Not
e
.
IsDefaultTupleElement
)
End
Function
Private
Sub
AddTupleTypeName
(
symbol
As
INamedTypeSymbol
)
...
...
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleErrorFieldSymbol.vb
浏览文件 @
84f97441
...
...
@@ -47,7 +47,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Me
.
_tupleElementIndex
=
If
(
correspondingDefaultFieldOpt
Is
Nothing
,
tupleElementIndex
<<
1
,
(
tupleElementIndex
<<
1
)
+
1
)
Me
.
_isImplicitlyDeclared
=
isImplicitlyDeclared
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Not
Nothing
OrElse
Me
.
IsDefaultTupleElement
)
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Nothing
=
Me
.
IsDefaultTupleElement
)
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Nothing
OrElse
correspondingDefaultFieldOpt
.
IsDefaultTupleElement
)
_correspondingDefaultField
=
If
(
correspondingDefaultFieldOpt
,
Me
)
...
...
@@ -107,6 +107,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End
Get
End
Property
Public
Overrides
ReadOnly
Property
CorrespondingTupleField
As
FieldSymbol
Get
Return
_correspondingDefaultField
End
Get
End
Property
Public
Overrides
ReadOnly
Property
Type
As
TypeSymbol
Get
Return
Me
.
_type
...
...
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleFieldSymbol.vb
浏览文件 @
84f97441
...
...
@@ -143,7 +143,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Me
.
_locations
=
If
((
location
Is
Nothing
),
ImmutableArray
(
Of
Location
).
Empty
,
ImmutableArray
.
Create
(
Of
Location
)(
location
))
Me
.
_isImplicitlyDeclared
=
isImplicitlyDeclared
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Not
Nothing
OrElse
Me
.
IsDefaultTupleElement
)
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Nothing
=
Me
.
IsDefaultTupleElement
)
Debug
.
Assert
(
correspondingDefaultFieldOpt
Is
Nothing
OrElse
correspondingDefaultFieldOpt
.
IsDefaultTupleElement
)
_correspondingDefaultField
=
If
(
correspondingDefaultFieldOpt
,
Me
)
...
...
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
浏览文件 @
84f97441
...
...
@@ -6496,10 +6496,11 @@ End Class
Dim intType As NamedTypeSymbol = comp.GetSpecialType(SpecialType.System_Int32)
Dim vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, intType)
Dim vt3 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T3).Construct(intType, intType, intType)
' Illegal VB identifier
and blank
Dim tuple2 = comp.CreateTupleTypeSymbol(vt
2, ImmutableArray.Create("123", " "
))
Assert.Equal({"123", " "}, GetTupleElementNames(tuple2))
' Illegal VB identifier
, space and null
Dim tuple2 = comp.CreateTupleTypeSymbol(vt
3, ImmutableArray.Create("123", " ", Nothing
))
Assert.Equal({"123", " "
, Nothing
}, GetTupleElementNames(tuple2))
' Reserved keywords
Dim tuple3 = comp.CreateTupleTypeSymbol(vt2, ImmutableArray.Create("return", "class"))
...
...
@@ -6514,6 +6515,25 @@ End Class
End Sub
<Fact>
Public Sub CreateTupleTypeSymbol_EmptyNames()
Dim comp = VisualBasicCompilation.Create("test", references:={MscorlibRef})
Dim intType As NamedTypeSymbol = comp.GetSpecialType(SpecialType.System_Int32)
Dim vt2 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).Construct(intType, intType)
Try
' Illegal VB identifier and empty
Dim tuple2 = comp.CreateTupleTypeSymbol(vt2, ImmutableArray.Create("123", ""))
Assert.True(False)
Catch ex As ArgumentException
Assert.Contains(CodeAnalysisResources.TupleElementNameEmpty, ex.Message)
Assert.Contains("1", ex.Message)
End Try
End Sub
<Fact>
Public Sub CreateTupleTypeSymbol_CSharpElements()
...
...
@@ -6787,7 +6807,7 @@ End Class
Return Nothing
End If
Return elements.SelectAsArray(Function(e)
If(e.IsImplicitlyDeclared, Nothing, e.Name)
)
Return elements.SelectAsArray(Function(e)
e.ProvidedTupleElementNameOrNull
)
End Function
<Fact>
...
...
src/Workspaces/Core/Portable/Shared/Utilities/SymbolEquivalenceComparer.GetHashCodeVisitor.cs
浏览文件 @
84f97441
...
...
@@ -189,12 +189,7 @@ private int CombineNamedTypeHashCode(INamedTypeSymbol x, int currentHash)
{
if
(
x
.
IsTupleType
)
{
foreach
(
var
element
in
x
.
TupleElements
)
{
currentHash
=
Hash
.
Combine
(
element
.
Type
,
currentHash
);
}
return
currentHash
;
return
Hash
.
Combine
(
currentHash
,
Hash
.
CombineValues
(
x
.
TupleElements
));
}
// If we want object and dynamic to be the same, and this is 'object', then return
...
...
src/Workspaces/Core/Portable/SymbolKey/SymbolKey.TupleTypeSymbolKey.cs
浏览文件 @
84f97441
...
...
@@ -15,16 +15,16 @@ public static void Create(INamedTypeSymbol symbol, SymbolKeyWriter visitor)
Debug
.
Assert
(
symbol
.
IsTupleType
);
visitor
.
WriteSymbolKey
(
symbol
.
TupleUnderlyingType
);
var
frie
l
dlyNames
=
ArrayBuilder
<
String
>.
GetInstance
();
var
frie
n
dlyNames
=
ArrayBuilder
<
String
>.
GetInstance
();
var
locations
=
ArrayBuilder
<
Location
>.
GetInstance
();
foreach
(
var
element
in
symbol
.
TupleElements
)
foreach
(
var
element
in
symbol
.
TupleElements
)
{
frie
ldlyNames
.
Add
(
element
.
IsImplicitlyDeclared
?
null
:
element
.
Name
);
frie
ndlyNames
.
Add
(
element
.
IsImplicitlyDeclared
?
null
:
element
.
Name
);
locations
.
Add
(
element
.
Locations
.
FirstOrDefault
());
}
visitor
.
WriteStringArray
(
frie
l
dlyNames
.
ToImmutableAndFree
());
visitor
.
WriteStringArray
(
frie
n
dlyNames
.
ToImmutableAndFree
());
visitor
.
WriteLocationArray
(
locations
.
ToImmutableAndFree
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录