Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
28791bf5
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,发现更多精彩内容 >>
提交
28791bf5
编写于
2月 11, 2016
作者:
J
John Hamby
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Eliminated ILabeledStatement and OperationKind.LabeledStatement.
上级
cfcfdefb
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
130 addition
and
46 deletion
+130
-46
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
+8
-5
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
...Sharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
+23
-0
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
...ore/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
+50
-0
src/Compilers/Core/Portable/Compilation/IExpression.cs
src/Compilers/Core/Portable/Compilation/IExpression.cs
+7
-7
src/Compilers/Core/Portable/Compilation/IOperation.cs
src/Compilers/Core/Portable/Compilation/IOperation.cs
+1
-1
src/Compilers/Core/Portable/Compilation/IStatement.cs
src/Compilers/Core/Portable/Compilation/IStatement.cs
+5
-12
src/Compilers/Core/Portable/Compilation/OperationVisitor.cs
src/Compilers/Core/Portable/Compilation/OperationVisitor.cs
+1
-11
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
+1
-4
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
+1
-6
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
+7
-0
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
...Basic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
+26
-0
未找到文件。
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
浏览文件 @
28791bf5
...
...
@@ -642,6 +642,9 @@ public override void Accept(OperationVisitor visitor)
internal
partial
class
BoundLabelStatement
:
ILabelStatement
{
// These represent synthesized labels, and do not have an attached statement.
IOperation
ILabelStatement
.
LabeledStatement
=>
null
;
ILabelSymbol
ILabelStatement
.
Label
=>
this
.
Label
;
protected
override
OperationKind
StatementKind
=>
OperationKind
.
LabelStatement
;
...
...
@@ -657,22 +660,22 @@ public override void Accept(OperationVisitor visitor)
}
}
internal
partial
class
BoundLabeledStatement
:
ILabel
ed
Statement
internal
partial
class
BoundLabeledStatement
:
ILabelStatement
{
IOperation
ILabel
edStatement
.
Labeled
=>
this
.
Body
;
IOperation
ILabel
Statement
.
LabeledStatement
=>
this
.
Body
;
ILabelSymbol
ILabelStatement
.
Label
=>
this
.
Label
;
protected
override
OperationKind
StatementKind
=>
OperationKind
.
Label
ed
Statement
;
protected
override
OperationKind
StatementKind
=>
OperationKind
.
LabelStatement
;
public
override
void
Accept
(
OperationVisitor
visitor
)
{
visitor
.
VisitLabel
ed
Statement
(
this
);
visitor
.
VisitLabelStatement
(
this
);
}
public
override
TResult
Accept
<
TArgument
,
TResult
>(
OperationVisitor
<
TArgument
,
TResult
>
visitor
,
TArgument
argument
)
{
return
visitor
.
VisitLabel
ed
Statement
(
this
,
argument
);
return
visitor
.
VisitLabelStatement
(
this
,
argument
);
}
}
...
...
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
浏览文件 @
28791bf5
...
...
@@ -1331,6 +1331,29 @@ void Foo()
);
}
[
Fact
]
public
void
LabelOperatorsCSharp
()
{
const
string
source
=
@"
public class A
{
public void Fred()
{
Wilma: goto Betty;
Betty: goto Wilma;
}
}
"
;
CreateCompilationWithMscorlib45
(
source
)
.
VerifyDiagnostics
()
.
VerifyAnalyzerDiagnostics
(
new
DiagnosticAnalyzer
[]
{
new
LabelOperationsTestAnalyzer
()
},
null
,
null
,
false
,
Diagnostic
(
LabelOperationsTestAnalyzer
.
LabelDescriptor
.
Id
,
"Wilma: goto Betty;"
).
WithLocation
(
6
,
9
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
GotoDescriptor
.
Id
,
"goto Betty;"
).
WithLocation
(
6
,
16
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
LabelDescriptor
.
Id
,
"Betty: goto Wilma;"
).
WithLocation
(
7
,
9
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
GotoDescriptor
.
Id
,
"goto Wilma;"
).
WithLocation
(
7
,
16
)
);
}
[
Fact
]
public
void
UnaryBinaryOperatorsCSharp
()
{
...
...
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
28791bf5
...
...
@@ -1315,6 +1315,56 @@ public sealed override void Initialize(AnalysisContext context)
}
}
public
class
LabelOperationsTestAnalyzer
:
DiagnosticAnalyzer
{
public
static
readonly
DiagnosticDescriptor
LabelDescriptor
=
new
DiagnosticDescriptor
(
"Label"
,
"Label found"
,
"A label was was found"
,
"Testing"
,
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
static
readonly
DiagnosticDescriptor
GotoDescriptor
=
new
DiagnosticDescriptor
(
"Goto"
,
"Goto found"
,
"A goto was was found"
,
"Testing"
,
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
sealed
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
LabelDescriptor
,
GotoDescriptor
);
public
sealed
override
void
Initialize
(
AnalysisContext
context
)
{
context
.
RegisterOperationAction
(
(
operationContext
)
=>
{
ILabelSymbol
label
=
((
ILabelStatement
)
operationContext
.
Operation
).
Label
;
if
(
label
.
Name
==
"Wilma"
||
label
.
Name
==
"Betty"
)
{
operationContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
LabelDescriptor
,
operationContext
.
Operation
.
Syntax
.
GetLocation
()));
}
},
OperationKind
.
LabelStatement
);
context
.
RegisterOperationAction
(
(
operationContext
)
=>
{
IBranchStatement
branch
=
(
IBranchStatement
)
operationContext
.
Operation
;
if
(
branch
.
BranchKind
==
BranchKind
.
GoTo
)
{
ILabelSymbol
label
=
branch
.
Target
;
if
(
label
.
Name
==
"Wilma"
||
label
.
Name
==
"Betty"
)
{
operationContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
GotoDescriptor
,
branch
.
Syntax
.
GetLocation
()));
}
}
},
OperationKind
.
BranchStatement
);
}
}
public
class
UnaryAndBinaryOperationsTestAnalyzer
:
DiagnosticAnalyzer
{
public
static
readonly
DiagnosticDescriptor
OperatorAddMethodDescriptor
=
new
DiagnosticDescriptor
(
...
...
src/Compilers/Core/Portable/Compilation/IExpression.cs
浏览文件 @
28791bf5
...
...
@@ -95,19 +95,19 @@ public enum ArgumentKind
/// <summary>
/// Argument is specified positionally and matches the parameter of the same ordinality.
/// </summary>
Positional
,
Positional
=
0x0
,
/// <summary>
/// Argument is specified by name and matches the parameter of the same name.
/// </summary>
Named
,
Named
=
0x1
,
/// <summary>
/// Argument becomes an element of an array that matches a trailing C# params or VB ParamArray parameter.
/// </summary>
ParamArray
,
ParamArray
=
0x2
,
/// <summary>
/// Argument was omitted in source but has a default value supplied automatically.
/// </summary>
DefaultValue
DefaultValue
=
0x3
}
/// <summary>
...
...
@@ -185,16 +185,16 @@ public interface ISyntheticLocalReferenceExpression : IReferenceExpression
/// </summary>
public
enum
SyntheticLocalKind
{
None
,
None
=
0x0
,
/// <summary>
/// Created to capture the step value of a VB for loop.
/// </summary>
ForLoopStepValue
,
ForLoopStepValue
=
0x1
,
/// <summary>
/// Created to capture the limit value of a VB for loop.
/// </summary>
ForLoopLimitValue
ForLoopLimitValue
=
0x2
}
/// <summary>
...
...
src/Compilers/Core/Portable/Compilation/IOperation.cs
浏览文件 @
28791bf5
...
...
@@ -50,8 +50,8 @@ public enum OperationKind
LoopStatement
=
0x6
,
/// <summary>Indicates an <see cref="IReturnStatement"/>.</summary>
YieldBreakStatement
=
0x9
,
/// <summary>Indicates an <see cref="ILabelStatement"/>.</summary>
LabelStatement
=
0xa
,
LabeledStatement
=
0xb
,
// Why do both of these exist?
/// <summary>Indicates an <see cref="IBranchStatement"/>.</summary>
BranchStatement
=
0xc
,
/// <summary>Indicates an <see cref="IEmptyStatement"/>.</summary>
...
...
src/Compilers/Core/Portable/Compilation/IStatement.cs
浏览文件 @
28791bf5
...
...
@@ -94,19 +94,19 @@ public enum CaseKind
/// <summary>
/// Indicates case x in C# or Case x in VB.
/// </summary>
SingleValue
,
SingleValue
=
0x0
,
/// <summary>
/// Indicates Case Is op x in VB.
/// </summary>
Relational
,
Relational
=
0x1
,
/// <summary>
/// Indicates Case x To Y in VB.
/// </summary>
Range
,
Range
=
0x2
,
/// <summary>
/// Indicates default in C# or Case Else in VB.
/// </summary>
Default
Default
=
0x3
}
/// <summary>
...
...
@@ -276,17 +276,10 @@ public interface ILabelStatement : IOperation
/// Label that can be the target of branches.
/// </summary>
ILabelSymbol
Label
{
get
;
}
}
/// <summary>
/// Represents a C# label statement.
/// </summary>
public
interface
ILabeledStatement
:
ILabelStatement
{
/// <summary>
/// Statement that has been labeled.
/// </summary>
IOperation
Labeled
{
get
;
}
IOperation
Labeled
Statement
{
get
;
}
}
/// <summary>
...
...
src/Compilers/Core/Portable/Compilation/OperationVisitor.cs
浏览文件 @
28791bf5
...
...
@@ -89,12 +89,7 @@ public virtual void VisitLabelStatement(ILabelStatement operation)
{
DefaultVisit
(
operation
);
}
public
virtual
void
VisitLabeledStatement
(
ILabeledStatement
operation
)
{
DefaultVisit
(
operation
);
}
public
virtual
void
VisitBranchStatement
(
IBranchStatement
operation
)
{
DefaultVisit
(
operation
);
...
...
@@ -480,11 +475,6 @@ public virtual TResult VisitLabelStatement(ILabelStatement operation, TArgument
return
DefaultVisit
(
operation
,
argument
);
}
public
virtual
TResult
VisitLabeledStatement
(
ILabeledStatement
operation
,
TArgument
argument
)
{
return
DefaultVisit
(
operation
,
argument
);
}
public
virtual
TResult
VisitBranchStatement
(
IBranchStatement
operation
,
TArgument
argument
)
{
return
DefaultVisit
(
operation
,
argument
);
...
...
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
浏览文件 @
28791bf5
...
...
@@ -119,11 +119,8 @@ public override void VisitForEachLoopStatement(IForEachLoopStatement operation)
}
public
override
void
VisitLabelStatement
(
ILabelStatement
operation
)
{
}
public
override
void
VisitLabeledStatement
(
ILabeledStatement
operation
)
{
Visit
(
operation
.
Labeled
);
Visit
(
operation
.
Labeled
Statement
);
}
public
override
void
VisitBranchStatement
(
IBranchStatement
operation
)
...
...
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
浏览文件 @
28791bf5
...
...
@@ -101,7 +101,6 @@ Microsoft.CodeAnalysis.OperationKind.InvalidStatement = 1 -> Microsoft.CodeAnaly
Microsoft.CodeAnalysis.OperationKind.InvocationExpression = 28 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.IsExpression = 51 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.LabelStatement = 10 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.LabeledStatement = 11 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.LambdaExpression = 43 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.LateBoundMemberReferenceExpression = 38 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.LiteralExpression = 26 -> Microsoft.CodeAnalysis.OperationKind
...
...
@@ -434,8 +433,7 @@ Microsoft.CodeAnalysis.Semantics.IIsExpression.IsType.get -> Microsoft.CodeAnaly
Microsoft.CodeAnalysis.Semantics.IIsExpression.Operand.get -> Microsoft.CodeAnalysis.Semantics.IExpression
Microsoft.CodeAnalysis.Semantics.ILabelStatement
Microsoft.CodeAnalysis.Semantics.ILabelStatement.Label.get -> Microsoft.CodeAnalysis.ILabelSymbol
Microsoft.CodeAnalysis.Semantics.ILabeledStatement
Microsoft.CodeAnalysis.Semantics.ILabeledStatement.Labeled.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.ILabelStatement.LabeledStatement.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.Semantics.ILambdaExpression
Microsoft.CodeAnalysis.Semantics.ILambdaExpression.Body.get -> Microsoft.CodeAnalysis.Semantics.IBlockStatement
Microsoft.CodeAnalysis.Semantics.ILambdaExpression.Signature.get -> Microsoft.CodeAnalysis.IMethodSymbol
...
...
@@ -692,7 +690,6 @@ override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitInvalidStatement(
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitInvocationExpression(Microsoft.CodeAnalysis.Semantics.IInvocationExpression operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitIsExpression(Microsoft.CodeAnalysis.Semantics.IIsExpression operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitLabelStatement(Microsoft.CodeAnalysis.Semantics.ILabelStatement operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitLabeledStatement(Microsoft.CodeAnalysis.Semantics.ILabeledStatement operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitLambdaExpression(Microsoft.CodeAnalysis.Semantics.ILambdaExpression operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitLateBoundMemberReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILateBoundMemberReferenceExpression operation) -> void
override Microsoft.CodeAnalysis.Semantics.OperationWalker.VisitLiteralExpression(Microsoft.CodeAnalysis.Semantics.ILiteralExpression operation) -> void
...
...
@@ -785,7 +782,6 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitInvalidStatement(
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitInvocationExpression(Microsoft.CodeAnalysis.Semantics.IInvocationExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitIsExpression(Microsoft.CodeAnalysis.Semantics.IIsExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLabelStatement(Microsoft.CodeAnalysis.Semantics.ILabelStatement operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLabeledStatement(Microsoft.CodeAnalysis.Semantics.ILabeledStatement operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLambdaExpression(Microsoft.CodeAnalysis.Semantics.ILambdaExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLateBoundMemberReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILateBoundMemberReferenceExpression operation) -> void
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor.VisitLiteralExpression(Microsoft.CodeAnalysis.Semantics.ILiteralExpression operation) -> void
...
...
@@ -859,7 +855,6 @@ virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.Vi
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitInvocationExpression(Microsoft.CodeAnalysis.Semantics.IInvocationExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitIsExpression(Microsoft.CodeAnalysis.Semantics.IIsExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLabelStatement(Microsoft.CodeAnalysis.Semantics.ILabelStatement operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLabeledStatement(Microsoft.CodeAnalysis.Semantics.ILabeledStatement operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLambdaExpression(Microsoft.CodeAnalysis.Semantics.ILambdaExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLateBoundMemberReferenceExpression(Microsoft.CodeAnalysis.Semantics.ILateBoundMemberReferenceExpression operation, TArgument argument) -> TResult
virtual Microsoft.CodeAnalysis.Semantics.OperationVisitor<TArgument, TResult>.VisitLiteralExpression(Microsoft.CodeAnalysis.Semantics.ILiteralExpression operation, TArgument argument) -> TResult
...
...
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
浏览文件 @
28791bf5
...
...
@@ -1050,6 +1050,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Get
End
Property
Private
ReadOnly
Property
ILabeled
As
IOperation
Implements
ILabelStatement
.
LabeledStatement
Get
' The VB bound trees do not encode the statement to which the label is attached.
Return
Nothing
End
Get
End
Property
Protected
Overrides
Function
StatementKind
()
As
OperationKind
Return
OperationKind
.
LabelStatement
End
Function
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
浏览文件 @
28791bf5
...
...
@@ -1432,6 +1432,32 @@ End Class
Diagnostic
(
StaticMemberTestAnalyzer
.
StaticMemberDescriptor
.
Id
,
"D.Method()"
).
WithLocation
(
27
,
9
))
End
Sub
<
Fact
>
Public
Sub
LabelOperatorsVisualBasic
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
Public
Class
A
Public
Sub
Fred
()
Wilma
:
GoTo
Betty
Betty
:
GoTo
Wilma
End
Sub
End
Class
]]
>
</
file
>
</
compilation
>
Dim
comp
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
LabelOperationsTestAnalyzer
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
LabelOperationsTestAnalyzer
.
LabelDescriptor
.
Id
,
"Wilma:"
).
WithLocation
(
3
,
9
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
GotoDescriptor
.
Id
,
"GoTo Betty"
).
WithLocation
(
4
,
9
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
LabelDescriptor
.
Id
,
"Betty:"
).
WithLocation
(
5
,
9
),
Diagnostic
(
LabelOperationsTestAnalyzer
.
GotoDescriptor
.
Id
,
"GoTo Wilma"
).
WithLocation
(
6
,
9
))
End
Sub
<
Fact
>
Public
Sub
UnaryBinaryOperatorsVisualBasic
()
Dim
source
=
<
compilation
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录