提交 73553c7c 编写于 作者: J John Hamby

Instrument implicit constructors for VB.

上级 112e1a41
...@@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ...@@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public Shared Function TryCreate(method As MethodSymbol, methodBody As BoundStatement, methodBodyFactory As SyntheticBoundNodeFactory, diagnostics As DiagnosticBag, debugDocumentProvider As DebugDocumentProvider, previous As Instrumenter) As DynamicAnalysisInjector 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.
If Not method.IsImplicitlyDeclared Then If Not method.IsImplicitlyDeclared OrElse method.IsAnyConstructor Then
Dim createPayload As MethodSymbol = GetCreatePayload(methodBodyFactory.Compilation, methodBody.Syntax, diagnostics) Dim createPayload As MethodSymbol = GetCreatePayload(methodBodyFactory.Compilation, methodBody.Syntax, diagnostics)
' Do not instrument any methods if CreatePayload is not present. ' Do not instrument any methods if CreatePayload is not present.
...@@ -70,7 +70,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ...@@ -70,7 +70,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' The first point indicates entry into the method and has the span of the method definition. ' The first point indicates entry into the method and has the span of the method definition.
Dim bodySyntax As VisualBasicSyntaxNode = methodBody.Syntax Dim bodySyntax As VisualBasicSyntaxNode = methodBody.Syntax
_methodEntryInstrumentation = AddAnalysisPoint(bodySyntax, SkipAttributes(bodySyntax), methodBodyFactory) If Not method.IsImplicitlyDeclared Then
_methodEntryInstrumentation = AddAnalysisPoint(bodySyntax, SkipAttributes(bodySyntax), methodBodyFactory)
End If
End Sub End Sub
Public Overrides Function CreateBlockPrologue(trueOriginal As BoundBlock, original As BoundBlock, ByRef synthesizedLocal As LocalSymbol) As BoundStatement Public Overrides Function CreateBlockPrologue(trueOriginal As BoundBlock, original As BoundBlock, ByRef synthesizedLocal As LocalSymbol) As BoundStatement
...@@ -106,7 +108,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ...@@ -106,7 +108,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim prologueStatements As ArrayBuilder(Of BoundStatement) = ArrayBuilder(Of BoundStatement).GetInstance(If(previousPrologue Is Nothing, 3, 4)) Dim prologueStatements As ArrayBuilder(Of BoundStatement) = ArrayBuilder(Of BoundStatement).GetInstance(If(previousPrologue Is Nothing, 3, 4))
prologueStatements.Add(payloadInitialization) prologueStatements.Add(payloadInitialization)
prologueStatements.Add(payloadIf) prologueStatements.Add(payloadIf)
prologueStatements.Add(_methodEntryInstrumentation) If _methodEntryInstrumentation IsNot Nothing Then
prologueStatements.Add(_methodEntryInstrumentation)
End If
If previousPrologue IsNot Nothing Then If previousPrologue IsNot Nothing Then
prologueStatements.Add(previousPrologue) prologueStatements.Add(previousPrologue)
End If End If
......
...@@ -587,6 +587,71 @@ End Class ...@@ -587,6 +587,71 @@ End Class
New SpanResult(37, 8, 37, 18, "_z = a + b")) New SpanResult(37, 8, 37, 18, "_z = a + b"))
End Sub End Sub
<Fact>
Public Sub TestImplicitConstructorSpans()
Dim testSource As XElement = <file name="c.vb">
<![CDATA[
Module Program
Private x As Integer
Public Sub Main() ' Method 0
TestMain()
End Sub
Sub TestMain() ' Method 1
Dim local As New C()
End Sub
End Module
Class C
Shared Function Init() As Integer ' Method 4
Return 33
End Function
Private _x As Integer = Init()
Private _y As Integer = Init() + 12
Private Shared s_x As Integer = Init()
Private Shared s_y As Integer = Init() + 153
Private Shared s_z As Integer = 144
End Class
]]>
</file>
Dim source As Xml.Linq.XElement = <compilation></compilation>
source.Add(testSource)
source.Add(InstrumentationHelperSource)
Dim c = CompilationUtils.CreateCompilationWithMscorlibAndVBRuntime(source)
Dim peImage = c.EmitToArray(EmitOptions.Default.WithInstrument("Test.Flag"))
Dim PEReader As New PEReader(peImage)
Dim reader = DynamicAnalysisDataReader.TryCreateFromPE(PEReader, "<DynamicAnalysisData>")
VerifyDocuments(reader, reader.Documents, "'c.vb'", "'a.vb'")
Dim sourceLines As String() = testSource.ToString().Split(vbLf(0))
VerifySpans(reader, reader.Methods(0), sourceLines,
New SpanResult(3, 4, 5, 11, "Public Sub Main()"),
New SpanResult(4, 8, 4, 18, "TestMain()"))
VerifySpans(reader, reader.Methods(1), sourceLines,
New SpanResult(7, 4, 9, 11, "Sub TestMain()"),
New SpanResult(8, 21, 8, 28, "New C()"))
VerifySpans(reader, reader.Methods(4), sourceLines,
New SpanResult(13, 4, 15, 16, "Shared Function Init() As Integer"),
New SpanResult(14, 8, 14, 17, "Return 33"))
VerifySpans(reader, reader.Methods(2), sourceLines, ' implicit shared constructor
New SpanResult(19, 36, 19, 42, "Init()"),
New SpanResult(20, 36, 20, 48, "Init() + 153"),
New SpanResult(21, 36, 21, 39, "144"))
VerifySpans(reader, reader.Methods(3), sourceLines, ' implicit default constructor
New SpanResult(17, 28, 17, 34, "Init()"),
New SpanResult(18, 28, 18, 39, "Init() + 12"))
End Sub
<Fact> <Fact>
Public Sub TestDynamicAnalysisResourceMissingWhenInstrumentationFlagIsDisabled() Public Sub TestDynamicAnalysisResourceMissingWhenInstrumentationFlagIsDisabled()
Dim source As Xml.Linq.XElement = <compilation></compilation> Dim source As Xml.Linq.XElement = <compilation></compilation>
......
...@@ -1223,6 +1223,7 @@ True ...@@ -1223,6 +1223,7 @@ True
CompileAndVerify(source, expectedOutput) CompileAndVerify(source, expectedOutput)
End Sub End Sub
<Fact> <Fact>
Public Sub TestFieldInitializerSpans() Public Sub TestFieldInitializerSpans()
Dim testSource As XElement = <file name="c.vb"> Dim testSource As XElement = <file name="c.vb">
...@@ -1327,6 +1328,89 @@ True ...@@ -1327,6 +1328,89 @@ True
CompileAndVerify(source, expectedOutput) CompileAndVerify(source, expectedOutput)
End Sub End Sub
<Fact>
Public Sub TestImplicitConstructorSpans()
Dim testSource As XElement = <file name="c.vb">
<![CDATA[
Module Program
Private x As Integer
Public Sub Main() ' Method 1
TestMain()
Microsoft.CodeAnalysis.Runtime.Instrumentation.FlushPayload()
End Sub
Sub TestMain() ' Method 2
Dim local As New C()
Dim x As Integer = local._x + C.s_x
End Sub
End Module
Class C
' Method 3 is the implicit shared constructor.
' Method 4 is the implicit instance constructor.
Shared Function Init() As Integer ' Method 5
Return 33
End Function
Public _x As Integer = Init()
Public _y As Integer = Init() + 12
Public Shared s_x As Integer = Init()
Public Shared s_y As Integer = Init() + 153
Public Shared s_z As Integer = 144
End Class
]]>
</file>
Dim source As Xml.Linq.XElement = <compilation></compilation>
source.Add(testSource)
source.Add(InstrumentationHelperSource)
Dim expectedOutput As XCData = <![CDATA[
Flushing
Method 1
File 1
True
True
True
Method 2
File 1
True
True
True
Method 3
File 1
True
True
True
Method 4
File 1
True
True
Method 5
File 1
True
True
Method 8
File 1
True
True
False
True
True
True
True
True
True
True
True
True
]]>
CompileAndVerify(source, expectedOutput)
End Sub
<Fact> <Fact>
Public Sub MissingMethodNeededForAnaysis() Public Sub MissingMethodNeededForAnaysis()
Dim testSource As XElement = <file name="c.vb"> Dim testSource As XElement = <file name="c.vb">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册