| 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 /// Data produced by dart2js when run with the `--dump-info` flag. | 5 /// Data produced by dart2js when run with the `--dump-info` flag. |
| 6 library dart2js_info.info; | 6 library dart2js_info.info; |
| 7 | 7 |
| 8 import 'src/measurements.dart'; |
| 9 export 'src/measurements.dart'; |
| 10 |
| 8 /// Common interface to many pieces of information generated by the dart2js | 11 /// Common interface to many pieces of information generated by the dart2js |
| 9 /// compiler. | 12 /// compiler that are directly associated with an element (compilation unit, |
| 13 /// library, class, function, or field). |
| 10 abstract class Info { | 14 abstract class Info { |
| 11 /// An identifier for the kind of information. | 15 /// An identifier for the kind of information. |
| 12 InfoKind get kind; | 16 InfoKind get kind; |
| 13 | 17 |
| 14 /// Name of the element associated with this info. | 18 /// Name of the element associated with this info. |
| 15 String name; | 19 String name; |
| 16 | 20 |
| 17 /// An id to uniquely identify this info among infos of the same [kind]. | 21 /// An id to uniquely identify this info among infos of the same [kind]. |
| 18 int get id; | 22 int get id; |
| 19 | 23 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 ..coverageId = json['coverageId'] | 366 ..coverageId = json['coverageId'] |
| 363 ..outputUnit = parseId(json['outputUnit']) | 367 ..outputUnit = parseId(json['outputUnit']) |
| 364 ..size = json['size'] | 368 ..size = json['size'] |
| 365 ..type = json['type'] | 369 ..type = json['type'] |
| 366 ..returnType = json['returnType'] | 370 ..returnType = json['returnType'] |
| 367 ..inferredReturnType = json['inferredReturnType'] | 371 ..inferredReturnType = json['inferredReturnType'] |
| 368 ..parameters = json['parameters'].map(parseParameter).toList() | 372 ..parameters = json['parameters'].map(parseParameter).toList() |
| 369 ..code = json['code'] | 373 ..code = json['code'] |
| 370 ..sideEffects = json['sideEffects'] | 374 ..sideEffects = json['sideEffects'] |
| 371 ..modifiers = parseModifiers(json['modifiers']) | 375 ..modifiers = parseModifiers(json['modifiers']) |
| 372 ..closures = json['children'].map(parseId).toList(); | 376 ..closures = json['children'].map(parseId).toList() |
| 377 ..measurements = parseMeasurements(json['measurements']); |
| 373 } | 378 } |
| 374 | 379 |
| 375 ParameterInfo parseParameter(Map json) => | 380 ParameterInfo parseParameter(Map json) => |
| 376 new ParameterInfo(json['name'], json['type'], json['declaredType']); | 381 new ParameterInfo(json['name'], json['type'], json['declaredType']); |
| 377 | 382 |
| 383 Measurements parseMeasurements(Map json) { |
| 384 if (json == null) return null; |
| 385 var uri = json['sourceFile']; |
| 386 var res = new Measurements(uri == null ? null : Uri.parse(uri)); |
| 387 for (var key in json.keys) { |
| 388 var value = json[key]; |
| 389 if (value == null) continue; |
| 390 if (key == 'entries') { |
| 391 value.forEach((metricName, entries) { |
| 392 var metric = Metric.fromJson(metricName); |
| 393 for (var i = 0; i < entries.length; i += 2) { |
| 394 res.record(metric, entries[i], entries[i + 1]); |
| 395 } |
| 396 }); |
| 397 } else { |
| 398 res.counters[Metric.fromJson(key)] = value; |
| 399 } |
| 400 } |
| 401 return res; |
| 402 } |
| 403 |
| 378 FunctionModifiers parseModifiers(Map<String, bool> json) { | 404 FunctionModifiers parseModifiers(Map<String, bool> json) { |
| 379 return new FunctionModifiers( | 405 return new FunctionModifiers( |
| 380 isStatic: json['static'] == true, | 406 isStatic: json['static'] == true, |
| 381 isConst: json['const'] == true, | 407 isConst: json['const'] == true, |
| 382 isFactory: json['factory'] == true, | 408 isFactory: json['factory'] == true, |
| 383 isExternal: json['external'] == true); | 409 isExternal: json['external'] == true); |
| 384 } | 410 } |
| 385 | 411 |
| 386 Info parseId(String serializedId) => registry.putIfAbsent(serializedId, () { | 412 Info parseId(String serializedId) => registry.putIfAbsent(serializedId, () { |
| 387 if (serializedId == null) { | 413 if (serializedId == null) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 415 | 441 |
| 416 /// Top level fields defined within the library. | 442 /// Top level fields defined within the library. |
| 417 final List<FieldInfo> topLevelVariables = <FieldInfo>[]; | 443 final List<FieldInfo> topLevelVariables = <FieldInfo>[]; |
| 418 | 444 |
| 419 /// Classes defined within the library. | 445 /// Classes defined within the library. |
| 420 final List<ClassInfo> classes = <ClassInfo>[]; | 446 final List<ClassInfo> classes = <ClassInfo>[]; |
| 421 | 447 |
| 422 /// Typedefs defined within the library. | 448 /// Typedefs defined within the library. |
| 423 final List<TypedefInfo> typedefs = <TypedefInfo>[]; | 449 final List<TypedefInfo> typedefs = <TypedefInfo>[]; |
| 424 | 450 |
| 451 // TODO(sigmund): add here a list of parts. That can help us improve how we |
| 452 // encode source-span information in metrics (rather than include the uri on |
| 453 // each function, include an index into this list). |
| 454 |
| 425 static int _id = 0; | 455 static int _id = 0; |
| 426 | 456 |
| 427 /// Whether there is any information recorded for this library. | 457 /// Whether there is any information recorded for this library. |
| 428 bool get isEmpty => | 458 bool get isEmpty => |
| 429 topLevelFunctions.isEmpty && topLevelVariables.isEmpty && classes.isEmpty; | 459 topLevelFunctions.isEmpty && topLevelVariables.isEmpty && classes.isEmpty; |
| 430 | 460 |
| 431 LibraryInfo(String name, this.uri, OutputUnitInfo outputUnit, int size) | 461 LibraryInfo(String name, this.uri, OutputUnitInfo outputUnit, int size) |
| 432 : super(InfoKind.library, _id++, name, outputUnit, size, null); | 462 : super(InfoKind.library, _id++, name, outputUnit, size, null); |
| 433 | 463 |
| 434 LibraryInfo._(String serializedId) : super._fromId(serializedId); | 464 LibraryInfo._(String serializedId) : super._fromId(serializedId); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 /// Side-effects. | 641 /// Side-effects. |
| 612 // TODO(sigmund): serialize more precisely, not just a string representation. | 642 // TODO(sigmund): serialize more precisely, not just a string representation. |
| 613 String sideEffects; | 643 String sideEffects; |
| 614 | 644 |
| 615 /// How many function calls were inlined into this function. | 645 /// How many function calls were inlined into this function. |
| 616 int inlinedCount; | 646 int inlinedCount; |
| 617 | 647 |
| 618 /// The actual generated code. | 648 /// The actual generated code. |
| 619 String code; | 649 String code; |
| 620 | 650 |
| 651 /// Measurements collected for this function. |
| 652 Measurements measurements; |
| 653 |
| 621 FunctionInfo( | 654 FunctionInfo( |
| 622 {String name, | 655 {String name, |
| 623 String coverageId, | 656 String coverageId, |
| 624 OutputUnitInfo outputUnit, | 657 OutputUnitInfo outputUnit, |
| 625 int size: 0, | 658 int size: 0, |
| 626 this.functionKind, | 659 this.functionKind, |
| 627 this.modifiers, | 660 this.modifiers, |
| 628 this.closures, | 661 this.closures, |
| 629 this.type, | 662 this.type, |
| 630 this.returnType, | 663 this.returnType, |
| 631 this.inferredReturnType, | 664 this.inferredReturnType, |
| 632 this.parameters, | 665 this.parameters, |
| 633 this.sideEffects, | 666 this.sideEffects, |
| 634 this.inlinedCount, | 667 this.inlinedCount, |
| 635 this.code}) | 668 this.code, |
| 669 this.measurements}) |
| 636 : super(InfoKind.function, _ids++, name, outputUnit, size, coverageId); | 670 : super(InfoKind.function, _ids++, name, outputUnit, size, coverageId); |
| 637 | 671 |
| 638 FunctionInfo._(String serializedId) : super._fromId(serializedId); | 672 FunctionInfo._(String serializedId) : super._fromId(serializedId); |
| 639 | 673 |
| 640 Map toJson() => super.toJson() | 674 Map toJson() => super.toJson() |
| 641 ..addAll({ | 675 ..addAll({ |
| 642 'children': closures.map((i) => i.serializedId).toList(), | 676 'children': closures.map((i) => i.serializedId).toList(), |
| 643 'modifiers': modifiers.toJson(), | 677 'modifiers': modifiers.toJson(), |
| 644 'returnType': returnType, | 678 'returnType': returnType, |
| 645 'inferredReturnType': inferredReturnType, | 679 'inferredReturnType': inferredReturnType, |
| 646 'parameters': parameters.map((p) => p.toJson()).toList(), | 680 'parameters': parameters.map((p) => p.toJson()).toList(), |
| 647 'sideEffects': sideEffects, | 681 'sideEffects': sideEffects, |
| 648 'inlinedCount': inlinedCount, | 682 'inlinedCount': inlinedCount, |
| 649 'code': code, | 683 'code': code, |
| 650 'type': type, | 684 'type': type, |
| 685 'measurements': measurements?.toJson(), |
| 651 // Note: version 3.2 of dump-info serializes `uses` in a section called | 686 // Note: version 3.2 of dump-info serializes `uses` in a section called |
| 652 // `holding` at the top-level. | 687 // `holding` at the top-level. |
| 653 }); | 688 }); |
| 654 | 689 |
| 655 void accept(InfoVisitor visitor) => visitor.visitFunction(this); | 690 void accept(InfoVisitor visitor) => visitor.visitFunction(this); |
| 656 } | 691 } |
| 657 | 692 |
| 658 /// Information about how a dependency is used. | 693 /// Information about how a dependency is used. |
| 659 class DependencyInfo { | 694 class DependencyInfo { |
| 660 /// The dependency, either a FunctionInfo or FieldInfo. | 695 /// The dependency, either a FunctionInfo or FieldInfo. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 } | 845 } |
| 811 | 846 |
| 812 visitField(FieldInfo info) { | 847 visitField(FieldInfo info) { |
| 813 info.closures.forEach(visitFunction); | 848 info.closures.forEach(visitFunction); |
| 814 } | 849 } |
| 815 | 850 |
| 816 visitFunction(FunctionInfo info) { | 851 visitFunction(FunctionInfo info) { |
| 817 info.closures.forEach(visitFunction); | 852 info.closures.forEach(visitFunction); |
| 818 } | 853 } |
| 819 } | 854 } |
| OLD | NEW |