Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
50924c3a
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,发现更多精彩内容 >>
提交
50924c3a
编写于
7月 28, 2016
作者:
J
John Hamby
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add instrumentation of bound pattern switch statements.
上级
06c25e54
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
185 addition
and
1 deletion
+185
-1
src/Compilers/CSharp/Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
...Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
+5
-0
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
...rp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
+14
-0
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.cs
...table/Lowering/Instrumentation/DynamicAnalysisInjector.cs
+8
-0
src/Compilers/CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
.../CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
+6
-0
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
...ing/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
+9
-1
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
...Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
+59
-0
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
.../Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
+84
-0
未找到文件。
src/Compilers/CSharp/Portable/Lowering/Instrumentation/CompoundInstrumenter.cs
浏览文件 @
50924c3a
...
...
@@ -163,6 +163,11 @@ public override BoundStatement InstrumentSwitchStatement(BoundSwitchStatement or
return
Previous
.
InstrumentSwitchStatement
(
original
,
rewritten
);
}
public
override
BoundStatement
InstrumentBoundPatternSwitchStatement
(
BoundPatternSwitchStatement
original
,
BoundStatement
rewritten
)
{
return
Previous
.
InstrumentBoundPatternSwitchStatement
(
original
,
rewritten
);
}
public
override
BoundStatement
InstrumentUsingTargetCapture
(
BoundUsingStatement
original
,
BoundStatement
usingTargetCapture
)
{
return
Previous
.
InstrumentUsingTargetCapture
(
original
,
usingTargetCapture
);
...
...
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DebugInfoInjector.cs
浏览文件 @
50924c3a
...
...
@@ -359,6 +359,20 @@ public override BoundStatement InstrumentSwitchStatement(BoundSwitchStatement or
hasErrors
:
false
);
}
public
override
BoundStatement
InstrumentBoundPatternSwitchStatement
(
BoundPatternSwitchStatement
original
,
BoundStatement
rewritten
)
{
SwitchStatementSyntax
switchSyntax
=
(
SwitchStatementSyntax
)
original
.
Syntax
;
TextSpan
switchSequencePointSpan
=
TextSpan
.
FromBounds
(
switchSyntax
.
SwitchKeyword
.
SpanStart
,
switchSyntax
.
CloseParenToken
.
Span
.
End
);
return
new
BoundSequencePointWithSpan
(
syntax
:
switchSyntax
,
statementOpt
:
base
.
InstrumentBoundPatternSwitchStatement
(
original
,
rewritten
),
span
:
switchSequencePointSpan
,
hasErrors
:
false
);
}
public
override
BoundStatement
InstrumentUsingTargetCapture
(
BoundUsingStatement
original
,
BoundStatement
usingTargetCapture
)
{
return
AddSequencePoint
((
UsingStatementSyntax
)
original
.
Syntax
,
...
...
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.cs
浏览文件 @
50924c3a
...
...
@@ -213,6 +213,11 @@ public override BoundStatement InstrumentSwitchStatement(BoundSwitchStatement or
return
AddDynamicAnalysis
(
original
,
base
.
InstrumentSwitchStatement
(
original
,
rewritten
));
}
public
override
BoundStatement
InstrumentBoundPatternSwitchStatement
(
BoundPatternSwitchStatement
original
,
BoundStatement
rewritten
)
{
return
AddDynamicAnalysis
(
original
,
base
.
InstrumentBoundPatternSwitchStatement
(
original
,
rewritten
));
}
public
override
BoundStatement
InstrumentUsingTargetCapture
(
BoundUsingStatement
original
,
BoundStatement
usingTargetCapture
)
{
return
AddDynamicAnalysis
(
original
,
base
.
InstrumentUsingTargetCapture
(
original
,
usingTargetCapture
));
...
...
@@ -303,6 +308,9 @@ private static CSharpSyntaxNode SyntaxForSpan(BoundStatement statement)
case
BoundKind
.
SwitchStatement
:
syntaxForSpan
=
((
BoundSwitchStatement
)
statement
).
Expression
.
Syntax
;
break
;
case
BoundKind
.
PatternSwitchStatement
:
syntaxForSpan
=
((
BoundPatternSwitchStatement
)
statement
).
Expression
.
Syntax
;
break
;
default
:
syntaxForSpan
=
statement
.
Syntax
;
break
;
...
...
src/Compilers/CSharp/Portable/Lowering/Instrumentation/Instrumenter.cs
浏览文件 @
50924c3a
...
...
@@ -244,6 +244,12 @@ public virtual BoundStatement InstrumentSwitchStatement(BoundSwitchStatement ori
return
InstrumentStatement
(
original
,
rewritten
);
}
public
virtual
BoundStatement
InstrumentBoundPatternSwitchStatement
(
BoundPatternSwitchStatement
original
,
BoundStatement
rewritten
)
{
Debug
.
Assert
(
original
.
Syntax
.
Kind
()
==
SyntaxKind
.
SwitchStatement
);
return
InstrumentStatement
(
original
,
rewritten
);
}
public
virtual
BoundStatement
InstrumentUsingTargetCapture
(
BoundUsingStatement
original
,
BoundStatement
usingTargetCapture
)
{
Debug
.
Assert
(!
original
.
WasCompilerGenerated
);
...
...
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs
浏览文件 @
50924c3a
...
...
@@ -49,7 +49,15 @@ public override BoundNode VisitPatternSwitchStatement(BoundPatternSwitchStatemen
}
result
.
Add
(
_factory
.
Label
(
node
.
BreakLabel
));
var
translatedSwitch
=
_factory
.
Block
(
pslr
.
DeclaredTemps
.
ToImmutableArray
().
Concat
(
node
.
InnerLocals
),
node
.
InnerLocalFunctions
,
result
.
ToImmutableAndFree
());
BoundStatement
translatedSwitch
=
_factory
.
Block
(
pslr
.
DeclaredTemps
.
ToImmutableArray
().
Concat
(
node
.
InnerLocals
),
node
.
InnerLocalFunctions
,
result
.
ToImmutableAndFree
());
// Create the sequence point if generating debug info and
// node is not compiler generated
if
(
this
.
Instrument
&&
!
node
.
WasCompilerGenerated
)
{
translatedSwitch
=
_instrumenter
.
InstrumentBoundPatternSwitchStatement
(
node
,
translatedSwitch
);
}
return
translatedSwitch
;
}
...
...
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
浏览文件 @
50924c3a
...
...
@@ -364,6 +364,65 @@ int Wilma
"(60,8)-(60,17)"
);
}
[
Fact
]
public
void
TestPatternSpans
()
{
string
source
=
@"
using System;
public class C
{
public static void Main() // Method 0
{
Student s = new Student();
s.Name = ""Bozo"";
s.GPA = 2.3;
Operate(s);
}
static string Operate(Person p) // Method 1
{
switch (p)
{
case Student s when s.GPA > 3.5:
return $""Student {s.Name} ({s.GPA:N1})"";
case Student s:
return $""Student {s.Name} ({s.GPA:N1})"";
case Teacher t:
return $""Teacher {t.Name} of {t.Subject}"";
default:
return $""Person {p.Name}"";
}
}
}
class Person { public string Name; }
class Teacher : Person { public string Subject; }
class Student : Person { public double GPA; }
"
;
var
c
=
CreateCompilationWithMscorlib
(
Parse
(
source
+
InstrumentationHelperSource
,
@"C:\myproject\doc1.cs"
));
var
peImage
=
c
.
EmitToArray
(
EmitOptions
.
Default
.
WithInstrument
(
"Test.Flag"
));
var
peReader
=
new
PEReader
(
peImage
);
var
reader
=
DynamicAnalysisDataReader
.
TryCreateFromPE
(
peReader
,
"<DynamicAnalysisData>"
);
VerifySpans
(
reader
,
reader
.
Methods
[
0
],
"(5,4)-(11,5)"
,
"(7,8)-(7,34)"
,
"(8,8)-(8,24)"
,
"(9,8)-(9,20)"
,
"(10,8)-(10,19)"
);
VerifySpans
(
reader
,
reader
.
Methods
[
1
],
"(13,4)-(26,5)"
,
"(18,16)-(18,56)"
,
"(20,16)-(20,56)"
,
"(22,16)-(22,58)"
,
"(24,16)-(24,42)"
,
"(15,16)-(15,17)"
);
}
[
Fact
]
public
void
TestDynamicAnalysisResourceMissingWhenInstrumentationFlagIsDisabled
()
{
...
...
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
浏览文件 @
50924c3a
...
...
@@ -1287,6 +1287,90 @@ File 1
CompileAndVerify
(
source
+
InstrumentationHelperSource
,
expectedOutput
:
expectedOutput
);
}
[
Fact
]
public
void
PatternsCoverage
()
{
string
source
=
@"
using System;
public class C
{
public static void Main()
{
TestMain();
Microsoft.CodeAnalysis.Runtime.Instrumentation.FlushPayload();
}
static void TestMain() // Method 2
{
Student s = new Student();
s.Name = ""Bozo"";
s.GPA = 2.3;
Operate(s);
}
static string Operate(Person p) // Method 3
{
switch (p)
{
case Student s when s.GPA > 3.5:
return $""Student {s.Name} ({s.GPA:N1})"";
case Student s:
return $""Student {s.Name} ({s.GPA:N1})"";
case Teacher t:
return $""Teacher {t.Name} of {t.Subject}"";
default:
return $""Person {p.Name}"";
}
}
}
class Person { public string Name; }
class Teacher : Person { public string Subject; }
class Student : Person { public double GPA; }
"
;
string
expectedOutput
=
@"Flushing
Method 1
File 1
True
True
True
Method 2
File 1
True
True
True
True
True
Method 3
File 1
True
False
True
False
False
True
Method 9
File 1
True
True
False
True
True
True
True
True
True
True
True
True
True
True
"
;
CompileAndVerify
(
source
+
InstrumentationHelperSource
,
expectedOutput
:
expectedOutput
);
}
[
Fact
]
public
void
LambdaCoverage
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录