Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
204d75ed
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,发现更多精彩内容 >>
提交
204d75ed
编写于
8月 08, 2016
作者:
J
John Hamby
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make instrumenting implicit constructs work for C#.
上级
73553c7c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
181 addition
and
12 deletion
+181
-12
src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.cs
...table/Lowering/Instrumentation/DynamicAnalysisInjector.cs
+11
-4
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
...Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
+63
-0
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
.../Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
+105
-6
src/Compilers/VisualBasic/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.vb
...table/Lowering/Instrumentation/DynamicAnalysisInjector.vb
+1
-1
未找到文件。
src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
浏览文件 @
204d75ed
...
...
@@ -886,7 +886,7 @@ public override object VisitField(FieldSymbol symbol, TypeCompilationState argum
analyzedInitializers
=
InitializerRewriter
.
RewriteConstructor
(
processedInitializers
.
BoundInitializers
,
methodSymbol
);
processedInitializers
.
HasErrors
=
processedInitializers
.
HasErrors
||
analyzedInitializers
.
HasAnyErrors
;
if
(
body
!=
null
&&
(
methodSymbol
.
ContainingType
.
IsStructType
()
||
instrumentForDynamicAnalysis
)
&&
!
methodSymbol
.
IsImplicitConstructor
)
if
(
body
!=
null
&&
(
(
methodSymbol
.
ContainingType
.
IsStructType
()
&&
!
methodSymbol
.
IsImplicitConstructor
)
||
instrumentForDynamicAnalysis
)
)
{
// In order to get correct diagnostics, we need to analyze initializers and the body together.
body
=
body
.
Update
(
body
.
Locals
,
body
.
LocalFunctions
,
body
.
Statements
.
Insert
(
0
,
analyzedInitializers
));
...
...
src/Compilers/CSharp/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.cs
浏览文件 @
204d75ed
...
...
@@ -30,8 +30,8 @@ internal sealed class DynamicAnalysisInjector : CompoundInstrumenter
public
static
DynamicAnalysisInjector
TryCreate
(
MethodSymbol
method
,
BoundStatement
methodBody
,
SyntheticBoundNodeFactory
methodBodyFactory
,
DiagnosticBag
diagnostics
,
DebugDocumentProvider
debugDocumentProvider
,
Instrumenter
previous
)
{
// Do not instrument implicitly-declared methods.
if
(!
method
.
IsImplicitlyDeclared
)
// Do not instrument implicitly-declared methods
, except for constructors
.
if
(!
method
.
IsImplicitlyDeclared
||
method
.
IsImplicitConstructor
)
{
MethodSymbol
createPayload
=
GetCreatePayload
(
methodBodyFactory
.
Compilation
,
methodBody
.
Syntax
,
diagnostics
);
...
...
@@ -64,7 +64,10 @@ private DynamicAnalysisInjector(MethodSymbol method, BoundStatement methodBody,
// The first point indicates entry into the method and has the span of the method definition.
CSharpSyntaxNode
syntax
=
MethodDeclarationIfAvailable
(
methodBody
.
Syntax
);
_methodEntryInstrumentation
=
AddAnalysisPoint
(
syntax
,
SkipAttributes
(
syntax
),
methodBodyFactory
);
if
(!
method
.
IsImplicitlyDeclared
)
{
_methodEntryInstrumentation
=
AddAnalysisPoint
(
syntax
,
SkipAttributes
(
syntax
),
methodBodyFactory
);
}
}
public
override
BoundStatement
CreateBlockPrologue
(
BoundBlock
original
,
out
LocalSymbol
synthesizedLocal
)
...
...
@@ -100,7 +103,11 @@ public override BoundStatement CreateBlockPrologue(BoundBlock original, out Loca
ArrayBuilder
<
BoundStatement
>
prologueStatements
=
ArrayBuilder
<
BoundStatement
>.
GetInstance
(
previousPrologue
==
null
?
3
:
4
);
prologueStatements
.
Add
(
payloadInitialization
);
prologueStatements
.
Add
(
payloadIf
);
prologueStatements
.
Add
(
_methodEntryInstrumentation
);
if
(
_methodEntryInstrumentation
!=
null
)
{
prologueStatements
.
Add
(
_methodEntryInstrumentation
);
}
if
(
previousPrologue
!=
null
)
{
prologueStatements
.
Add
(
previousPrologue
);
...
...
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicAnalysisResourceTests.cs
浏览文件 @
204d75ed
...
...
@@ -533,6 +533,69 @@ public class C
new
SpanResult
(
41
,
8
,
41
,
19
,
"_z = a + b"
));
}
[
Fact
]
public
void
TestImplicitConstructorSpans
()
{
string
source
=
@"
using System;
public class C
{
public static void Main() // Method 0
{
TestMain();
}
static void TestMain() // Method 1
{
C local = new C();
}
static int Init() => 33; // Method 2
int _x = Init();
int _y = Init() + 12;
static int s_x = Init();
static int s_y = Init() + 153;
static int s_z = 144;
int Prop1 { get; } = 15;
static int Prop2 { get; } = 255;
}
"
;
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>"
);
string
[]
sourceLines
=
source
.
Split
(
'\n'
);
VerifySpans
(
reader
,
reader
.
Methods
[
0
],
sourceLines
,
new
SpanResult
(
5
,
4
,
8
,
5
,
"public static void Main()"
),
new
SpanResult
(
7
,
8
,
7
,
19
,
"TestMain()"
));
VerifySpans
(
reader
,
reader
.
Methods
[
1
],
sourceLines
,
new
SpanResult
(
10
,
4
,
13
,
5
,
"static void TestMain()"
),
new
SpanResult
(
12
,
8
,
12
,
26
,
"C local = new C()"
));
VerifySpans
(
reader
,
reader
.
Methods
[
2
],
sourceLines
,
new
SpanResult
(
15
,
4
,
15
,
28
,
"static int Init() => 33"
),
new
SpanResult
(
15
,
25
,
15
,
27
,
"33"
));
VerifySpans
(
reader
,
reader
.
Methods
[
5
],
sourceLines
,
// Synthesized instance constructor
new
SpanResult
(
17
,
13
,
17
,
19
,
"Init()"
),
new
SpanResult
(
18
,
13
,
18
,
24
,
"Init() + 12"
),
new
SpanResult
(
23
,
25
,
23
,
27
,
"15"
));
VerifySpans
(
reader
,
reader
.
Methods
[
6
],
sourceLines
,
// Synthesized static constructor
new
SpanResult
(
19
,
21
,
19
,
27
,
"Init()"
),
new
SpanResult
(
20
,
21
,
20
,
33
,
"Init() + 153"
),
new
SpanResult
(
21
,
21
,
21
,
24
,
"144"
),
new
SpanResult
(
24
,
32
,
24
,
35
,
"255"
));
}
[
Fact
]
public
void
TestDynamicAnalysisResourceMissingWhenInstrumentationFlagIsDisabled
()
{
...
...
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
浏览文件 @
204d75ed
...
...
@@ -782,6 +782,8 @@ static int Lambda(int x, Func<int, int> l)
{
return l(x);
}
// Method 11 is a synthesized static constructor.
}
"
;
// There is no entry for method '8' since it's a Prop2_set which is never called.
...
...
@@ -823,6 +825,9 @@ Method 9
File 1
True
True
Method 11
File 1
True
Method 13
File 1
True
...
...
@@ -854,27 +859,30 @@ public void MultipleFilesCoverage()
public class Program
{
#line 10 ""File1.cs""
public static void Main(string[] args)
public static void Main(string[] args)
// Method 1
{
TestMain();
Microsoft.CodeAnalysis.Runtime.Instrumentation.FlushPayload();
}
#line 20 ""File2.cs""
static void TestMain()
static void TestMain()
// Method 2
{
Fred();
Fred
();
Program p = new Program
();
return;
}
#line 30 ""File3.cs""
static void Fred()
static void Fred()
// Method 3
{
return;
}
#line 40 ""File4.cs""
#line 40 ""File5.cs""
// The synthesized instance constructor is method 4 and
// appears in the original source file, which gets file index 4.
}
"
;
...
...
@@ -894,8 +902,10 @@ Method 3
File 3
True
True
Method
6
Method
4
File 4
Method 6
File 5
True
True
False
...
...
@@ -1329,6 +1339,8 @@ public static void Main()
class Person { public string Name; }
class Teacher : Person { public string Subject; }
class Student : Person { public double GPA; }
// Methods 5 and 7 are implicit constructors.
"
;
string
expectedOutput
=
@"Flushing
Method 1
...
...
@@ -1351,6 +1363,10 @@ File 1
False
False
True
Method 5
File 1
Method 7
File 1
Method 9
File 1
True
...
...
@@ -1658,6 +1674,89 @@ File 1
CompileAndVerify
(
source
+
InstrumentationHelperSource
,
expectedOutput
:
expectedOutput
);
}
[
Fact
]
public
void
TestImplicitConstructorSpans
()
{
string
source
=
@"
using System;
public class C
{
public static void Main() // Method 1
{
TestMain();
Microsoft.CodeAnalysis.Runtime.Instrumentation.FlushPayload();
}
static void TestMain() // Method 2
{
C local = new C();
int x = local._x + C.s_x;
}
static int Init() => 33; // Method 3
// Method 6 is the implicit instance constructor.
// Method 7 is the implicit shared constructor.
int _x = Init();
int _y = Init() + 12;
static int s_x = Init();
static int s_y = Init() + 153;
static int s_z = 144;
int Prop1 { get; } = 15;
static int Prop2 { get; } = 255;
}
"
;
string
expectedOutput
=
@"
Flushing
Method 1
File 1
True
True
True
Method 2
File 1
True
True
True
Method 3
File 1
True
True
Method 6
File 1
True
True
True
Method 7
File 1
True
True
True
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
MissingMethodNeededForAnalysis
()
{
...
...
src/Compilers/VisualBasic/Portable/Lowering/Instrumentation/DynamicAnalysisInjector.vb
浏览文件 @
204d75ed
...
...
@@ -29,7 +29,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private
ReadOnly
_methodBodyFactory
As
SyntheticBoundNodeFactory
Public
Shared
Function
TryCreate
(
method
As
MethodSymbol
,
methodBody
As
BoundStatement
,
methodBodyFactory
As
SyntheticBoundNodeFactory
,
diagnostics
As
DiagnosticBag
,
debugDocumentProvider
As
DebugDocumentProvider
,
previous
As
Instrumenter
)
As
DynamicAnalysisInjector
' Do not instrument implicitly-declared methods.
' Do not instrument implicitly-declared methods
, except for constructors
.
If
Not
method
.
IsImplicitlyDeclared
OrElse
method
.
IsAnyConstructor
Then
Dim
createPayload
As
MethodSymbol
=
GetCreatePayload
(
methodBodyFactory
.
Compilation
,
methodBody
.
Syntax
,
diagnostics
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录