| 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 library sourcemap.helper; | 5 library sourcemap.helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:compiler/compiler_new.dart'; | 9 import 'package:compiler/compiler_new.dart'; |
| 10 import 'package:compiler/src/apiimpl.dart' as api; | 10 import 'package:compiler/src/apiimpl.dart' as api; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 @override | 112 @override |
| 113 void exitNode( | 113 void exitNode( |
| 114 js.Node node, int startPosition, int endPosition, int closingPosition) { | 114 js.Node node, int startPosition, int endPosition, int closingPosition) { |
| 115 codePositions[node] = | 115 codePositions[node] = |
| 116 new CodePosition(startPosition, endPosition, closingPosition); | 116 new CodePosition(startPosition, endPosition, closingPosition); |
| 117 listener.onPositions(node, startPosition, endPosition, closingPosition); | 117 listener.onPositions(node, startPosition, endPosition, closingPosition); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 /// A [SourceMapper] that records the source locations on each node. | 121 /// A [SourceMapper] that records the source locations on each node. |
| 122 class RecordingSourceMapperProvider implements SourceMapperProvider { |
| 123 final SourceMapperProvider sourceMapperProvider; |
| 124 final _LocationRecorder nodeToSourceLocationsMap; |
| 125 |
| 126 RecordingSourceMapperProvider( |
| 127 this.sourceMapperProvider, this.nodeToSourceLocationsMap); |
| 128 |
| 129 @override |
| 130 SourceMapper createSourceMapper(String name) { |
| 131 return new RecordingSourceMapper( |
| 132 sourceMapperProvider.createSourceMapper(name), |
| 133 nodeToSourceLocationsMap); |
| 134 } |
| 135 } |
| 136 |
| 137 /// A [SourceMapper] that records the source locations on each node. |
| 122 class RecordingSourceMapper implements SourceMapper { | 138 class RecordingSourceMapper implements SourceMapper { |
| 123 final SourceMapper sourceMapper; | 139 final SourceMapper sourceMapper; |
| 124 final _LocationRecorder nodeToSourceLocationsMap; | 140 final _LocationRecorder nodeToSourceLocationsMap; |
| 125 | 141 |
| 126 RecordingSourceMapper(this.sourceMapper, this.nodeToSourceLocationsMap); | 142 RecordingSourceMapper(this.sourceMapper, this.nodeToSourceLocationsMap); |
| 127 | 143 |
| 128 @override | 144 @override |
| 129 void register(js.Node node, int codeOffset, SourceLocation sourceLocation) { | 145 void register(js.Node node, int codeOffset, SourceLocation sourceLocation) { |
| 130 nodeToSourceLocationsMap.register(node, codeOffset, sourceLocation); | 146 nodeToSourceLocationsMap.register(node, codeOffset, sourceLocation); |
| 131 sourceMapper.register(node, codeOffset, sourceLocation); | 147 sourceMapper.register(node, codeOffset, sourceLocation); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 <js.Node, RecordedSourceInformationProcess>{}; | 197 <js.Node, RecordedSourceInformationProcess>{}; |
| 182 | 198 |
| 183 RecordingSourceInformationStrategy(this.strategy); | 199 RecordingSourceInformationStrategy(this.strategy); |
| 184 | 200 |
| 185 @override | 201 @override |
| 186 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { | 202 SourceInformationBuilder createBuilderForContext(ResolvedAst resolvedAst) { |
| 187 return strategy.createBuilderForContext(resolvedAst); | 203 return strategy.createBuilderForContext(resolvedAst); |
| 188 } | 204 } |
| 189 | 205 |
| 190 @override | 206 @override |
| 191 SourceInformationProcessor createProcessor(SourceMapper sourceMapper) { | 207 SourceInformationProcessor createProcessor( |
| 208 SourceMapperProvider provider, SourceInformationReader reader) { |
| 192 LocationMap nodeToSourceLocationsMap = new _LocationRecorder(); | 209 LocationMap nodeToSourceLocationsMap = new _LocationRecorder(); |
| 193 CodePositionRecorder codePositions = new CodePositionRecorder(); | 210 CodePositionRecorder codePositions = new CodePositionRecorder(); |
| 194 return new RecordingSourceInformationProcessor( | 211 return new RecordingSourceInformationProcessor( |
| 195 this, | 212 this, |
| 196 strategy.createProcessor( | 213 strategy.createProcessor( |
| 197 new RecordingSourceMapper(sourceMapper, nodeToSourceLocationsMap)), | 214 new RecordingSourceMapperProvider( |
| 215 provider, nodeToSourceLocationsMap), |
| 216 reader), |
| 198 codePositions, | 217 codePositions, |
| 199 nodeToSourceLocationsMap); | 218 nodeToSourceLocationsMap); |
| 200 } | 219 } |
| 201 | 220 |
| 202 void registerProcess( | 221 void registerProcess( |
| 203 js.Node root, | 222 js.Node root, |
| 204 BufferedCodeOutput code, | 223 BufferedCodeOutput code, |
| 205 CodePositionRecorder codePositions, | 224 CodePositionRecorder codePositions, |
| 206 LocationMap nodeToSourceLocationsMap) { | 225 LocationMap nodeToSourceLocationsMap) { |
| 207 RecordedSourceInformationProcess subProcess = | 226 RecordedSourceInformationProcess subProcess = |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // TODO(johnniwinther): Find out when this is happening and if it | 344 // TODO(johnniwinther): Find out when this is happening and if it |
| 326 // is benign. (Known to happen for `bool#fromString`) | 345 // is benign. (Known to happen for `bool#fromString`) |
| 327 print('No subProcess found for $element'); | 346 print('No subProcess found for $element'); |
| 328 return; | 347 return; |
| 329 } | 348 } |
| 330 LocationMap nodeMap = subProcess.nodeToSourceLocationsMap; | 349 LocationMap nodeMap = subProcess.nodeToSourceLocationsMap; |
| 331 String code = subProcess.code; | 350 String code = subProcess.code; |
| 332 CodePositionRecorder codePositions = subProcess.codePositions; | 351 CodePositionRecorder codePositions = subProcess.codePositions; |
| 333 CodePointComputer visitor = | 352 CodePointComputer visitor = |
| 334 new CodePointComputer(sourceFileManager, code, nodeMap); | 353 new CodePointComputer(sourceFileManager, code, nodeMap); |
| 335 new JavaScriptTracer(codePositions, [visitor]).apply(node); | 354 new JavaScriptTracer( |
| 355 codePositions, const SourceInformationReader(), [visitor]) |
| 356 .apply(node); |
| 336 List<CodePoint> codePoints = visitor.codePoints; | 357 List<CodePoint> codePoints = visitor.codePoints; |
| 337 elementSourceMapInfos[element] = new SourceMapInfo( | 358 elementSourceMapInfos[element] = new SourceMapInfo( |
| 338 element, code, node, codePoints, codePositions, nodeMap); | 359 element, code, node, codePoints, codePositions, nodeMap); |
| 339 }); | 360 }); |
| 340 } | 361 } |
| 341 if (forMain) { | 362 if (forMain) { |
| 342 // TODO(johnniwinther): Supported multiple output units. | 363 // TODO(johnniwinther): Supported multiple output units. |
| 343 RecordedSourceInformationProcess process = strategy.processMap.keys.first; | 364 RecordedSourceInformationProcess process = strategy.processMap.keys.first; |
| 344 js.Node node = strategy.processMap[process]; | 365 js.Node node = strategy.processMap[process]; |
| 345 String code; | 366 String code; |
| 346 LocationMap nodeMap; | 367 LocationMap nodeMap; |
| 347 CodePositionRecorder codePositions; | 368 CodePositionRecorder codePositions; |
| 348 nodeMap = process.nodeToSourceLocationsMap; | 369 nodeMap = process.nodeToSourceLocationsMap; |
| 349 code = process.code; | 370 code = process.code; |
| 350 codePositions = process.codePositions; | 371 codePositions = process.codePositions; |
| 351 CodePointComputer visitor = | 372 CodePointComputer visitor = |
| 352 new CodePointComputer(sourceFileManager, code, nodeMap); | 373 new CodePointComputer(sourceFileManager, code, nodeMap); |
| 353 new JavaScriptTracer(codePositions, [visitor]).apply(node); | 374 new JavaScriptTracer( |
| 375 codePositions, const SourceInformationReader(), [visitor]) |
| 376 .apply(node); |
| 354 List<CodePoint> codePoints = visitor.codePoints; | 377 List<CodePoint> codePoints = visitor.codePoints; |
| 355 mainSourceMapInfo = new SourceMapInfo( | 378 mainSourceMapInfo = new SourceMapInfo( |
| 356 null, code, node, codePoints, codePositions, nodeMap); | 379 null, code, node, codePoints, codePositions, nodeMap); |
| 357 } | 380 } |
| 358 | 381 |
| 359 return new SourceMaps( | 382 return new SourceMaps( |
| 360 compiler, sourceFileManager, mainSourceMapInfo, elementSourceMapInfos); | 383 compiler, sourceFileManager, mainSourceMapInfo, elementSourceMapInfos); |
| 361 } | 384 } |
| 362 } | 385 } |
| 363 | 386 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 absoluteUri = base.resolveUri(uri); | 569 absoluteUri = base.resolveUri(uri); |
| 547 } else { | 570 } else { |
| 548 absoluteUri = base.resolve(uri); | 571 absoluteUri = base.resolve(uri); |
| 549 } | 572 } |
| 550 return sourceFiles.putIfAbsent(absoluteUri, () { | 573 return sourceFiles.putIfAbsent(absoluteUri, () { |
| 551 String text = new File.fromUri(absoluteUri).readAsStringSync(); | 574 String text = new File.fromUri(absoluteUri).readAsStringSync(); |
| 552 return new StringSourceFile.fromUri(absoluteUri, text); | 575 return new StringSourceFile.fromUri(absoluteUri, text); |
| 553 }); | 576 }); |
| 554 } | 577 } |
| 555 } | 578 } |
| OLD | NEW |