OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'breakpoint.dart'; | 5 import 'breakpoint.dart'; |
6 import 'scope.dart'; | 6 import 'scope.dart'; |
7 import 'script.dart'; | 7 import 'script.dart'; |
8 | 8 |
9 VMSourceLocation newVMSourceLocation(Scope scope, | 9 VMSourceLocation newVMSourceLocation(Scope scope, Map json) { |
10 Map json) { | |
11 if (json == null) return null; | 10 if (json == null) return null; |
12 assert(json["type"] == "SourceLocation"); | 11 assert(json["type"] == "SourceLocation"); |
13 return new VMSourceLocation._(scope, json); | 12 return new VMSourceLocation._(scope, json); |
14 } | 13 } |
15 | 14 |
| 15 VMSourceLocation newVMSourceLocationFromPosition( |
| 16 VMScriptRef script, int tokenPos, int endTokenPos) => |
| 17 new VMSourceLocation._fromPositions(script, tokenPos, endTokenPos); |
| 18 |
16 /// A location or span of code in a Dart script. | 19 /// A location or span of code in a Dart script. |
17 class VMSourceLocation implements VMBreakpointLocation { | 20 class VMSourceLocation implements VMBreakpointLocation { |
18 /// The script containing the source location. | 21 /// The script containing the source location. |
19 final VMScriptRef script; | 22 final VMScriptRef script; |
20 | 23 |
21 /// The canonical source URI of [script]. | 24 /// The canonical source URI of [script]. |
22 Uri get uri => script.uri; | 25 Uri get uri => script.uri; |
23 | 26 |
24 /// If this is a span, this represents the start of that span. | 27 /// If this is a span, this represents the start of that span. |
25 final VMScriptToken token; | 28 final VMScriptToken token; |
26 | 29 |
27 /// The final token of the location, or `null` if this is not a span. | 30 /// The final token of the location, or `null` if this is not a span. |
28 final VMScriptToken end; | 31 final VMScriptToken end; |
29 | 32 |
30 VMSourceLocation._(Scope scope, Map json) | 33 VMSourceLocation._(Scope scope, Map json) |
31 : script = newVMScriptRef(scope, json["script"]), | 34 : script = newVMScriptRef(scope, json["script"]), |
32 token = newVMScriptToken( | 35 token = newVMScriptToken( |
33 scope.isolateId, json["script"]["id"], json["tokenPos"]), | 36 scope.isolateId, json["script"]["id"], json["tokenPos"]), |
34 end = newVMScriptToken( | 37 end = newVMScriptToken( |
35 scope.isolateId, json["script"]["id"], json["endTokenPos"]); | 38 scope.isolateId, json["script"]["id"], json["endTokenPos"]); |
36 | 39 |
| 40 VMSourceLocation._fromPositions( |
| 41 VMScriptRef script, int tokenPos, int endTokenPos) |
| 42 : this.script = script, |
| 43 token = newVMScriptTokenFromPosition(script, tokenPos), |
| 44 end = newVMScriptTokenFromPosition(script, endTokenPos); |
| 45 |
37 String toString() => | 46 String toString() => |
38 end == null ? "$script at $token" : "$script from $token to $end"; | 47 end == null ? "$script at $token" : "$script from $token to $end"; |
39 } | 48 } |
OLD | NEW |