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

Side by Side Diff: pkg/compiler/lib/src/js/js_source_mapping.dart

Issue 2690083002: Add MultiSourceInformationStrategy (Closed)
Patch Set: Cleanup. Created 3 years, 10 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
« no previous file with comments | « pkg/compiler/lib/src/js/js.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library js.source_mapping; 5 library js.source_mapping;
6 6
7 import '../io/code_output.dart' show BufferedCodeOutput, SourceLocations; 7 import '../io/code_output.dart'
8 show BufferedCodeOutput, SourceLocations, SourceLocationsProvider;
8 import '../io/source_information.dart' 9 import '../io/source_information.dart'
9 show SourceLocation, SourceInformation, SourceInformationStrategy; 10 show SourceLocation, SourceInformation, SourceInformationStrategy;
10 import 'js.dart'; 11 import 'js.dart';
11 12
12 /// [SourceInformationStrategy] that can associate source information with 13 /// [SourceInformationStrategy] that can associate source information with
13 /// JavaScript output. 14 /// JavaScript output.
14 class JavaScriptSourceInformationStrategy extends SourceInformationStrategy { 15 class JavaScriptSourceInformationStrategy extends SourceInformationStrategy {
15 const JavaScriptSourceInformationStrategy(); 16 const JavaScriptSourceInformationStrategy();
16 17
17 /// Creates a processor that can associate source information on [Node] with 18 /// Creates a processor that can associate source information on [Node] with
18 /// code offsets in the [sourceMapper]. 19 /// code offsets in a [SourceMapper] provided by [sourceMapperProvider].
19 SourceInformationProcessor createProcessor(SourceMapper sourceMapper) { 20 /// Source information for each [Node] is provider by [reader].
21 SourceInformationProcessor createProcessor(
22 SourceMapperProvider sourceMapperProvider,
23 SourceInformationReader reader) {
20 return const SourceInformationProcessor(); 24 return const SourceInformationProcessor();
21 } 25 }
22 } 26 }
23 27
28 /// Interface for deriving [SourceInformation] from a [Node].
29 ///
30 /// The base implementation read the value of the node itself.
31 class SourceInformationReader {
32 const SourceInformationReader();
33
34 SourceInformation getSourceInformation(Node node) => node.sourceInformation;
35 }
36
24 /// An observer of code positions of printed JavaScript [Node]s. 37 /// An observer of code positions of printed JavaScript [Node]s.
25 class CodePositionListener { 38 class CodePositionListener {
26 const CodePositionListener(); 39 const CodePositionListener();
27 40
28 /// Called to associate [node] with the provided start position. 41 /// Called to associate [node] with the provided start position.
29 /// 42 ///
30 /// The nodes are seen in pre-traversal order. 43 /// The nodes are seen in pre-traversal order.
31 void onStartPosition(Node node, int startPosition) {} 44 void onStartPosition(Node node, int startPosition) {}
32 45
33 /// Called to associate [node] with the provided start, end and closing 46 /// Called to associate [node] with the provided start, end and closing
34 /// positions. 47 /// positions.
35 /// 48 ///
36 /// The nodes are seen in post-traversal order. 49 /// The nodes are seen in post-traversal order.
37 void onPositions( 50 void onPositions(
38 Node node, int startPosition, int endPosition, int closingPosition) {} 51 Node node, int startPosition, int endPosition, int closingPosition) {}
39 } 52 }
40 53
54 /// Interface for creating [SourceMapper]s for multiple source information
55 /// engines.
56 abstract class SourceMapperProvider {
57 SourceMapper createSourceMapper(String name);
58 }
59
60 /// Base implementation of [SourceMapperProvider].
61 class SourceMapperProviderImpl implements SourceMapperProvider {
62 final SourceLocationsProvider provider;
63
64 SourceMapperProviderImpl(this.provider);
65
66 SourceMapper createSourceMapper(String name) {
67 return new SourceLocationsMapper(provider.createSourceLocations(name));
68 }
69 }
70
41 /// An interface for mapping code offsets with [SourceLocation]s for JavaScript 71 /// An interface for mapping code offsets with [SourceLocation]s for JavaScript
42 /// [Node]s. 72 /// [Node]s.
43 abstract class SourceMapper { 73 abstract class SourceMapper {
44 /// Associate [codeOffset] with [sourceLocation] for [node]. 74 /// Associate [codeOffset] with [sourceLocation] for [node].
45 void register(Node node, int codeOffset, SourceLocation sourceLocation); 75 void register(Node node, int codeOffset, SourceLocation sourceLocation);
46 } 76 }
47 77
48 /// An implementation of [SourceMapper] that stores the information directly 78 /// An implementation of [SourceMapper] that stores the information directly
49 /// into a [SourceLocations] object. 79 /// into a [SourceLocations] object.
50 class SourceLocationsMapper implements SourceMapper { 80 class SourceLocationsMapper implements SourceMapper {
51 final SourceLocations sourceLocations; 81 final SourceLocations sourceLocations;
52 82
53 SourceLocationsMapper(this.sourceLocations); 83 SourceLocationsMapper(this.sourceLocations);
54 84
55 @override 85 @override
56 void register(Node node, int codeOffset, SourceLocation sourceLocation) { 86 void register(Node node, int codeOffset, SourceLocation sourceLocation) {
57 sourceLocations.addSourceLocation(codeOffset, sourceLocation); 87 sourceLocations.addSourceLocation(codeOffset, sourceLocation);
58 } 88 }
59 } 89 }
60 90
61 /// A processor that associates [SourceInformation] with code position of 91 /// A processor that associates [SourceInformation] with code position of
62 /// JavaScript [Node]s. 92 /// JavaScript [Node]s.
63 class SourceInformationProcessor extends CodePositionListener { 93 class SourceInformationProcessor extends CodePositionListener {
64 const SourceInformationProcessor(); 94 const SourceInformationProcessor();
65 95
66 /// Process the source information and code positions for the [node] and all 96 /// Process the source information and code positions for the [node] and all
67 /// its children. 97 /// its children.
68 void process(Node node, BufferedCodeOutput code) {} 98 void process(Node node, BufferedCodeOutput code) {}
69 } 99 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js/js.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698