| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dump_info; | 5 library dump_info; |
| 6 | 6 |
| 7 import 'dart:convert' | 7 import 'dart:convert' |
| 8 show ChunkedConversionSink, JsonEncoder, StringConversionSink; | 8 show ChunkedConversionSink, JsonEncoder, StringConversionSink; |
| 9 | 9 |
| 10 import 'package:dart2js_info/info.dart'; | 10 import 'package:dart2js_info/info.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 final Map<Element, Info> _elementToInfo = <Element, Info>{}; | 35 final Map<Element, Info> _elementToInfo = <Element, Info>{}; |
| 36 final Map<ConstantValue, Info> _constantToInfo = <ConstantValue, Info>{}; | 36 final Map<ConstantValue, Info> _constantToInfo = <ConstantValue, Info>{}; |
| 37 final Map<OutputUnit, OutputUnitInfo> _outputToInfo = {}; | 37 final Map<OutputUnit, OutputUnitInfo> _outputToInfo = {}; |
| 38 | 38 |
| 39 ElementInfoCollector(this.compiler, this.closedWorld); | 39 ElementInfoCollector(this.compiler, this.closedWorld); |
| 40 | 40 |
| 41 void run() { | 41 void run() { |
| 42 compiler.dumpInfoTask._constantToNode.forEach((constant, node) { | 42 compiler.dumpInfoTask._constantToNode.forEach((constant, node) { |
| 43 // TODO(sigmund): add dependencies on other constants | 43 // TODO(sigmund): add dependencies on other constants |
| 44 var size = compiler.dumpInfoTask._nodeToSize[node]; | 44 var size = compiler.dumpInfoTask._nodeToSize[node]; |
| 45 var code = jsAst.prettyPrint(node, compiler); | 45 var code = jsAst.prettyPrint(node, compiler.options); |
| 46 var info = new ConstantInfo( | 46 var info = new ConstantInfo( |
| 47 size: size, code: code, outputUnit: _unitInfoForConstant(constant)); | 47 size: size, code: code, outputUnit: _unitInfoForConstant(constant)); |
| 48 _constantToInfo[constant] = info; | 48 _constantToInfo[constant] = info; |
| 49 result.constants.add(info); | 49 result.constants.add(info); |
| 50 }); | 50 }); |
| 51 (compiler.libraryLoader.libraries as Iterable<LibraryElement>) | 51 (compiler.libraryLoader.libraries as Iterable<LibraryElement>) |
| 52 .forEach(visit); | 52 .forEach(visit); |
| 53 } | 53 } |
| 54 | 54 |
| 55 Info visit(Element e, [_]) => e.accept(this, null); | 55 Info visit(Element e, [_]) => e.accept(this, null); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 var size = _nodeToSize[node]; | 526 var size = _nodeToSize[node]; |
| 527 return size == null ? 0 : size; | 527 return size == null ? 0 : size; |
| 528 } | 528 } |
| 529 | 529 |
| 530 String codeOf(Element element) { | 530 String codeOf(Element element) { |
| 531 List<jsAst.Node> code = _elementToNodes[element]; | 531 List<jsAst.Node> code = _elementToNodes[element]; |
| 532 if (code == null) return null; | 532 if (code == null) return null; |
| 533 // Concatenate rendered ASTs. | 533 // Concatenate rendered ASTs. |
| 534 StringBuffer sb = new StringBuffer(); | 534 StringBuffer sb = new StringBuffer(); |
| 535 for (jsAst.Node ast in code) { | 535 for (jsAst.Node ast in code) { |
| 536 sb.writeln(jsAst.prettyPrint(ast, compiler)); | 536 sb.writeln(jsAst.prettyPrint(ast, compiler.options)); |
| 537 } | 537 } |
| 538 return sb.toString(); | 538 return sb.toString(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void dumpInfo(ClosedWorld closedWorld) { | 541 void dumpInfo(ClosedWorld closedWorld) { |
| 542 measure(() { | 542 measure(() { |
| 543 infoCollector = new ElementInfoCollector(compiler, closedWorld)..run(); | 543 infoCollector = new ElementInfoCollector(compiler, closedWorld)..run(); |
| 544 StringBuffer jsonBuffer = new StringBuffer(); | 544 StringBuffer jsonBuffer = new StringBuffer(); |
| 545 dumpInfoJson(jsonBuffer, closedWorld); | 545 dumpInfoJson(jsonBuffer, closedWorld); |
| 546 compiler.outputProvider(compiler.options.outputUri.pathSegments.last, | 546 compiler.outputProvider(compiler.options.outputUri.pathSegments.last, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 617 |
| 618 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( | 618 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( |
| 619 new StringConversionSink.fromStringSink(buffer)); | 619 new StringConversionSink.fromStringSink(buffer)); |
| 620 sink.add(new AllInfoJsonCodec().encode(result)); | 620 sink.add(new AllInfoJsonCodec().encode(result)); |
| 621 compiler.reporter.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { | 621 compiler.reporter.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { |
| 622 'text': "View the dumped .info.json file at " | 622 'text': "View the dumped .info.json file at " |
| 623 "https://dart-lang.github.io/dump-info-visualizer" | 623 "https://dart-lang.github.io/dump-info-visualizer" |
| 624 }); | 624 }); |
| 625 } | 625 } |
| 626 } | 626 } |
| OLD | NEW |