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

Side by Side Diff: pkg/compiler/lib/src/io/start_end_information.dart

Issue 2682813005: Add NoSourceLocationMarker in old source-info engine. (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
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 /// Source information system that maps spans of Dart AST nodes to spans of 5 /// Source information system that maps spans of Dart AST nodes to spans of
6 /// JavaScript nodes. 6 /// JavaScript nodes.
7 7
8 library dart2js.source_information.start_end; 8 library dart2js.source_information.start_end;
9 9
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 } 123 }
124 124
125 class StartEndSourceInformationProcessor extends SourceInformationProcessor { 125 class StartEndSourceInformationProcessor extends SourceInformationProcessor {
126 final SourceMapper sourceMapper; 126 final SourceMapper sourceMapper;
127 127
128 /// Used to track whether a terminating source location marker has been 128 /// Used to track whether a terminating source location marker has been
129 /// registered for the top-most node with source information. 129 /// registered for the top-most node with source information.
130 bool hasRegisteredRoot = false; 130 bool hasRegisteredRoot = false;
131 131
132 /// The root of the tree. Used to add a [NoSourceLocationMarker] to the start
133 /// of the output.
134 js.Node root;
135
136 /// The root of the current subtree with source information. Used to add
137 /// [NoSourceLocationMarker] after areas with source information.
138 js.Node subRoot;
139
132 StartEndSourceInformationProcessor(this.sourceMapper); 140 StartEndSourceInformationProcessor(this.sourceMapper);
133 141
142 void onStartPosition(js.Node node, int startPosition) {
143 if (root == null) {
144 root = node;
145 sourceMapper.register(
146 node, startPosition, const NoSourceLocationMarker());
147 }
148 if (subRoot == null && node.sourceInformation != null) {
149 subRoot = node;
150 }
151 }
152
134 @override 153 @override
135 void onPositions( 154 void onPositions(
136 js.Node node, int startPosition, int endPosition, int closingPosition) { 155 js.Node node, int startPosition, int endPosition, int closingPosition) {
137 if (node.sourceInformation != null) { 156 if (node.sourceInformation != null) {
138 StartEndSourceInformation sourceInformation = node.sourceInformation; 157 StartEndSourceInformation sourceInformation = node.sourceInformation;
139 sourceMapper.register( 158 sourceMapper.register(
140 node, startPosition, sourceInformation.startPosition); 159 node, startPosition, sourceInformation.startPosition);
141 if (sourceInformation.endPosition != null) { 160 if (sourceInformation.endPosition != null) {
142 sourceMapper.register(node, endPosition, sourceInformation.endPosition); 161 sourceMapper.register(node, endPosition, sourceInformation.endPosition);
143 } 162 }
144 if (!hasRegisteredRoot) { 163 if (!hasRegisteredRoot) {
145 sourceMapper.register(node, endPosition, null); 164 sourceMapper.register(node, endPosition, null);
146 hasRegisteredRoot = true; 165 hasRegisteredRoot = true;
147 } 166 }
167 if (node == subRoot) {
168 sourceMapper.register(
169 node, endPosition, const NoSourceLocationMarker());
170 subRoot = null;
171 }
148 } 172 }
149 } 173 }
150 } 174 }
151 175
152 /// [SourceInformationBuilder] that generates [PositionSourceInformation]. 176 /// [SourceInformationBuilder] that generates [PositionSourceInformation].
153 class StartEndSourceInformationBuilder extends SourceInformationBuilder { 177 class StartEndSourceInformationBuilder extends SourceInformationBuilder {
154 final SourceFile sourceFile; 178 final SourceFile sourceFile;
155 final String name; 179 final String name;
156 180
157 StartEndSourceInformationBuilder(ResolvedAst resolvedAst) 181 StartEndSourceInformationBuilder(ResolvedAst resolvedAst)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 237
214 @override 238 @override
215 SourceInformation buildIf(Node node) => buildGeneric(node); 239 SourceInformation buildIf(Node node) => buildGeneric(node);
216 240
217 @override 241 @override
218 SourceInformationBuilder forContext(ResolvedAst resolvedAst, 242 SourceInformationBuilder forContext(ResolvedAst resolvedAst,
219 {SourceInformation sourceInformation}) { 243 {SourceInformation sourceInformation}) {
220 return new StartEndSourceInformationBuilder(resolvedAst); 244 return new StartEndSourceInformationBuilder(resolvedAst);
221 } 245 }
222 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698