Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: lib/src/source_report.dart

Issue 1929063002: pkg/vm_service_client: add getSourceReport to VMServiceReference (Closed) Base URL: https://github.com/dart-lang/vm_service_client.git@master
Patch Set: tweak Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'script.dart';
6 import 'scope.dart';
7 import 'source_location.dart';
8
9 VMSourceReport newSourceReport(Scope scope, Map json) {
10 if (json == null) return null;
11 assert(json["type"] == "SourceReport");
12
13 var scripts = (json['scripts'] as List)
14 .map((script) => newVMScriptRef(scope, script))
15 .toList();
16
17 var ranges = new List<VMSourceReportRange>.unmodifiable(
18 (json['ranges'] as List).map((rangeItem) =>
19 new VMSourceReportRange._fromJson(rangeItem, scripts)));
20
21 return new VMSourceReport._(ranges);
22 }
23
24 /// A report about ranges of source code.
25 ///
26 /// [ranges] exposes code coverage and information on possible breakpoints.
27 class VMSourceReport {
28 /// Ranges in the program source corresponding to ranges of executable code in
29 /// the user's program.
30 ///
31 /// Ranges can include members such as functions, methods, and
32 /// constructors.
33 ///
34 /// Note: ranges may nest in other ranges, in the case of nested functions.
35 /// Rranges may be duplicated, in the case of mixins.
nweiz 2016/05/11 23:03:31 "Rranges" -> "Ranges"
kevmoo 2016/05/12 05:22:34 Done.
36 final List<VMSourceReportRange> ranges;
37
38 VMSourceReport._(this.ranges);
39 }
40
41 /// A range of executable code (function, method, constructor, etc)
42 /// in the running program.
43 ///
44 /// This is part of a [VMSourceReport].
45 class VMSourceReportRange {
46 VMScriptRef get script => location.script;
47
48 /// The location of the range in the target script.
49 final VMSourceLocation location;
50
51 /// `true` if this range been compiled by the Dart VM.
52 ///
53 /// If `false`, `possibleBreakpoints`, `hits`, and `misses` will be `null`.
54 ///
55 /// Use `forceCompile` in `getSourceReport` to ensure the target scripts are
56 /// compiled.
57 final bool compiled;
58
59 /// Token positions at which breakpoints can be set.
60 ///
61 /// Provided only when `includePossibleBreakpoints` in `getSourceReport`
62 /// is `true` and the range has been compiled.
63 final List<VMScriptToken> possibleBreakpoints;
64
65 /// Token positions in a [VMSourceReportRange] which have been executed.
nweiz 2016/05/11 23:03:31 "a [VMSourceReportRange]" -> "this range" same be
kevmoo 2016/05/12 05:22:35 Done.
66 ///
67 /// Provided only when `includeCoverageReport` in `getSourceReport` is `true`
68 /// and the range has been compiled.
69 ///
70 /// Sorted by the position in the source file, starting with the first hit.
71 final List<VMScriptToken> hits;
72
73 /// Token positions in a [VMSourceReportRange] which have not yet been
74 /// executed.
75 ///
76 /// Provided only when `includeCoverageReport` in `getSourceReport` is `true`
77 /// and the range has been compiled.
78 ///
79 /// Sorted by the location in the source file, starting with the first miss.
80 final List<VMScriptToken> misses;
81
82 factory VMSourceReportRange._fromJson(Map json, List<VMScriptRef> scripts) {
nweiz 2016/05/11 23:03:31 Document this.
kevmoo 2016/05/12 05:22:35 Done.
83 var script = scripts[json['scriptIndex']];
84
85 var location = newVMSourceLocationFromPosition(
86 script, json['startPos'], json['endPos']);
87
88 var compiled = json['compiled'];
89
90 var hits = json['coverage'] == null
91 ? null
92 : _getTokens(script, json['coverage']['hits']);
93
94 var misses = json['coverage'] == null
95 ? null
96 : _getTokens(script, json['coverage']['misses']);
97
98 var possibleBreakpoints = json['possibleBreakpoints'] == null
99 ? null
100 : _getTokens(script, json['possibleBreakpoints']);
101
102 return new VMSourceReportRange._(
103 compiled, hits, misses, possibleBreakpoints, location);
104 }
105
106 VMSourceReportRange._(this.compiled, this.hits, this.misses,
107 this.possibleBreakpoints, this.location);
108
109 static List<VMScriptToken> _getTokens(
nweiz 2016/05/11 23:03:31 Document this as well.
kevmoo 2016/05/12 05:22:35 Done.
110 VMScriptRef script, Iterable<int> locations) {
111 if (locations == null) return null;
nweiz 2016/05/11 23:03:31 It shouldn't be possible for this to be null. It's
kevmoo 2016/05/12 05:22:35 Acknowledged.
112
113 return new List<VMScriptToken>.unmodifiable(locations
114 .map((position) => newVMScriptTokenFromPosition(script, position)));
115 }
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698