| 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 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'src/measurements.dart'; | 10 import 'src/measurements.dart'; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 /// Information about fields (in any class). | 98 /// Information about fields (in any class). |
| 99 List<FieldInfo> fields = <FieldInfo>[]; | 99 List<FieldInfo> fields = <FieldInfo>[]; |
| 100 | 100 |
| 101 /// Information about constants anywhere in the program. | 101 /// Information about constants anywhere in the program. |
| 102 // TODO(sigmund): expand docs about canonicalization. We don't put these | 102 // TODO(sigmund): expand docs about canonicalization. We don't put these |
| 103 // inside library because a single constant can be used in more than one lib, | 103 // inside library because a single constant can be used in more than one lib, |
| 104 // and we'll include it only once in the output. | 104 // and we'll include it only once in the output. |
| 105 List<ConstantInfo> constants = <ConstantInfo>[]; | 105 List<ConstantInfo> constants = <ConstantInfo>[]; |
| 106 | 106 |
| 107 /// Information about closures anywhere in the program. |
| 108 List<ClosureInfo> closures = <ClosureInfo>[]; |
| 109 |
| 107 /// Information about output units (should be just one entry if not using | 110 /// Information about output units (should be just one entry if not using |
| 108 /// deferred loading). | 111 /// deferred loading). |
| 109 List<OutputUnitInfo> outputUnits = <OutputUnitInfo>[]; | 112 List<OutputUnitInfo> outputUnits = <OutputUnitInfo>[]; |
| 110 | 113 |
| 111 /// Details about all deferred imports and what files would be loaded when the | 114 /// Details about all deferred imports and what files would be loaded when the |
| 112 /// import is resolved. | 115 /// import is resolved. |
| 113 // TODO(sigmund): use a different format for dump-info. This currently emits | 116 // TODO(sigmund): use a different format for dump-info. This currently emits |
| 114 // the same map that is created for the `--deferred-map` flag. | 117 // the same map that is created for the `--deferred-map` flag. |
| 115 Map<String, Map<String, dynamic>> deferredFiles; | 118 Map<String, Map<String, dynamic>> deferredFiles; |
| 116 | 119 |
| 117 /// A new representation of dependencies from one info to another. An entry in | 120 /// A new representation of dependencies from one info to another. An entry in |
| 118 /// this map indicates that an [Info] depends on another (e.g. a function | 121 /// this map indicates that an [Info] depends on another (e.g. a function |
| 119 /// invokes another). Please note that the data in this field might not be | 122 /// invokes another). Please note that the data in this field might not be |
| 120 /// accurate yet (this is work in progress). | 123 /// accurate yet (this is work in progress). |
| 121 Map<Info, List<Info>> dependencies = {}; | 124 Map<Info, List<Info>> dependencies = {}; |
| 122 | 125 |
| 123 /// Major version indicating breaking changes in the format. A new version | 126 /// Major version indicating breaking changes in the format. A new version |
| 124 /// means that an old deserialization algorithm will not work with the new | 127 /// means that an old deserialization algorithm will not work with the new |
| 125 /// format. | 128 /// format. |
| 126 final int version = 4; | 129 final int version = 5; |
| 127 | 130 |
| 128 /// Minor version indicating non-breaking changes in the format. A change in | 131 /// Minor version indicating non-breaking changes in the format. A change in |
| 129 /// this version number means that the json parsing in this library from a | 132 /// this version number means that the json parsing in this library from a |
| 130 /// previous will continue to work after the change. This is typically | 133 /// previous will continue to work after the change. This is typically |
| 131 /// increased when adding new entries to the file format. | 134 /// increased when adding new entries to the file format. |
| 132 // Note: the dump-info.viewer app was written using a json parser version 3.2. | 135 // Note: the dump-info.viewer app was written using a json parser version 3.2. |
| 133 final int minorVersion = 0; | 136 final int minorVersion = 0; |
| 134 | 137 |
| 135 AllInfo(); | 138 AllInfo(); |
| 136 | 139 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 259 |
| 257 /// Information about a field element. | 260 /// Information about a field element. |
| 258 class FieldInfo extends BasicInfo with CodeInfo { | 261 class FieldInfo extends BasicInfo with CodeInfo { |
| 259 /// The type of the field. | 262 /// The type of the field. |
| 260 String type; | 263 String type; |
| 261 | 264 |
| 262 /// The type inferred by dart2js's whole program analysis | 265 /// The type inferred by dart2js's whole program analysis |
| 263 String inferredType; | 266 String inferredType; |
| 264 | 267 |
| 265 /// Nested closures seen in the field initializer. | 268 /// Nested closures seen in the field initializer. |
| 266 List<FunctionInfo> closures; | 269 List<ClosureInfo> closures; |
| 267 | 270 |
| 268 /// The actual generated code for the field. | 271 /// The actual generated code for the field. |
| 269 String code; | 272 String code; |
| 270 | 273 |
| 271 /// Whether this corresponds to a const field declaration. | 274 /// Whether this corresponds to a const field declaration. |
| 272 bool isConst; | 275 bool isConst; |
| 273 | 276 |
| 274 /// When [isConst] is true, the constant initializer expression. | 277 /// When [isConst] is true, the constant initializer expression. |
| 275 ConstantInfo initializer; | 278 ConstantInfo initializer; |
| 276 | 279 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 static const int CONSTRUCTOR_FUNCTION_KIND = 3; | 317 static const int CONSTRUCTOR_FUNCTION_KIND = 3; |
| 315 static int _ids = 0; | 318 static int _ids = 0; |
| 316 | 319 |
| 317 /// Kind of function (top-level function, closure, method, or constructor). | 320 /// Kind of function (top-level function, closure, method, or constructor). |
| 318 int functionKind; | 321 int functionKind; |
| 319 | 322 |
| 320 /// Modifiers applied to this function. | 323 /// Modifiers applied to this function. |
| 321 FunctionModifiers modifiers; | 324 FunctionModifiers modifiers; |
| 322 | 325 |
| 323 /// Nested closures that appear within the body of this function. | 326 /// Nested closures that appear within the body of this function. |
| 324 List<FunctionInfo> closures; | 327 List<ClosureInfo> closures; |
| 325 | 328 |
| 326 /// The type of this function. | 329 /// The type of this function. |
| 327 String type; | 330 String type; |
| 328 | 331 |
| 329 /// The declared return type. | 332 /// The declared return type. |
| 330 String returnType; | 333 String returnType; |
| 331 | 334 |
| 332 /// The inferred return type. | 335 /// The inferred return type. |
| 333 String inferredReturnType; | 336 String inferredReturnType; |
| 334 | 337 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 364 this.inlinedCount, | 367 this.inlinedCount, |
| 365 this.code, | 368 this.code, |
| 366 this.measurements}) | 369 this.measurements}) |
| 367 : super(InfoKind.function, _ids++, name, outputUnit, size, coverageId); | 370 : super(InfoKind.function, _ids++, name, outputUnit, size, coverageId); |
| 368 | 371 |
| 369 FunctionInfo._(String serializedId) : super._fromId(serializedId); | 372 FunctionInfo._(String serializedId) : super._fromId(serializedId); |
| 370 | 373 |
| 371 dynamic accept(InfoVisitor visitor) => visitor.visitFunction(this); | 374 dynamic accept(InfoVisitor visitor) => visitor.visitFunction(this); |
| 372 } | 375 } |
| 373 | 376 |
| 377 /// Information about a closure, also known as a local function. |
| 378 class ClosureInfo extends BasicInfo { |
| 379 static int _ids = 0; |
| 380 |
| 381 /// The function that is wrapped by this closure. |
| 382 FunctionInfo function; |
| 383 |
| 384 ClosureInfo( |
| 385 {String name, OutputUnitInfo outputUnit, int size: 0, this.function}) |
| 386 : super(InfoKind.closure, _ids++, name, outputUnit, size, null); |
| 387 |
| 388 ClosureInfo._(String serializedId) : super._fromId(serializedId); |
| 389 |
| 390 dynamic accept(InfoVisitor visitor) => visitor.visitClosure(this); |
| 391 } |
| 392 |
| 374 /// Information about how a dependency is used. | 393 /// Information about how a dependency is used. |
| 375 class DependencyInfo { | 394 class DependencyInfo { |
| 376 /// The dependency, either a FunctionInfo or FieldInfo. | 395 /// The dependency, either a FunctionInfo or FieldInfo. |
| 377 final Info target; | 396 final Info target; |
| 378 | 397 |
| 379 /// Either a selector mask indicating how this is used, or 'inlined'. | 398 /// Either a selector mask indicating how this is used, or 'inlined'. |
| 380 // TODO(sigmund): split mask into an enum or something more precise to really | 399 // TODO(sigmund): split mask into an enum or something more precise to really |
| 381 // describe the dependencies in detail. | 400 // describe the dependencies in detail. |
| 382 final String mask; | 401 final String mask; |
| 383 | 402 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 400 final bool isFactory; | 419 final bool isFactory; |
| 401 final bool isExternal; | 420 final bool isExternal; |
| 402 | 421 |
| 403 FunctionModifiers( | 422 FunctionModifiers( |
| 404 {this.isStatic: false, | 423 {this.isStatic: false, |
| 405 this.isConst: false, | 424 this.isConst: false, |
| 406 this.isFactory: false, | 425 this.isFactory: false, |
| 407 this.isExternal: false}); | 426 this.isExternal: false}); |
| 408 } | 427 } |
| 409 | 428 |
| 410 /// Possible values of the `kind` field in the serialied infos. | 429 /// Possible values of the `kind` field in the serialized infos. |
| 411 enum InfoKind { | 430 enum InfoKind { |
| 412 library, | 431 library, |
| 413 clazz, | 432 clazz, |
| 414 function, | 433 function, |
| 415 field, | 434 field, |
| 416 constant, | 435 constant, |
| 417 outputUnit, | 436 outputUnit, |
| 418 typedef, | 437 typedef, |
| 438 closure, |
| 419 } | 439 } |
| 420 | 440 |
| 421 String kindToString(InfoKind kind) { | 441 String kindToString(InfoKind kind) { |
| 422 switch (kind) { | 442 switch (kind) { |
| 423 case InfoKind.library: | 443 case InfoKind.library: |
| 424 return 'library'; | 444 return 'library'; |
| 425 case InfoKind.clazz: | 445 case InfoKind.clazz: |
| 426 return 'class'; | 446 return 'class'; |
| 427 case InfoKind.function: | 447 case InfoKind.function: |
| 428 return 'function'; | 448 return 'function'; |
| 429 case InfoKind.field: | 449 case InfoKind.field: |
| 430 return 'field'; | 450 return 'field'; |
| 431 case InfoKind.constant: | 451 case InfoKind.constant: |
| 432 return 'constant'; | 452 return 'constant'; |
| 433 case InfoKind.outputUnit: | 453 case InfoKind.outputUnit: |
| 434 return 'outputUnit'; | 454 return 'outputUnit'; |
| 435 case InfoKind.typedef: | 455 case InfoKind.typedef: |
| 436 return 'typedef'; | 456 return 'typedef'; |
| 457 case InfoKind.closure: |
| 458 return 'closure'; |
| 437 default: | 459 default: |
| 438 return null; | 460 return null; |
| 439 } | 461 } |
| 440 } | 462 } |
| 441 | 463 |
| 442 int _idFromSerializedId(String serializedId) => | 464 int _idFromSerializedId(String serializedId) => |
| 443 int.parse(serializedId.substring(serializedId.indexOf('/') + 1)); | 465 int.parse(serializedId.substring(serializedId.indexOf('/') + 1)); |
| 444 | 466 |
| 445 InfoKind _kindFromSerializedId(String serializedId) => | 467 InfoKind _kindFromSerializedId(String serializedId) => |
| 446 kindFromString(serializedId.substring(0, serializedId.indexOf('/'))); | 468 kindFromString(serializedId.substring(0, serializedId.indexOf('/'))); |
| 447 | 469 |
| 448 InfoKind kindFromString(String kind) { | 470 InfoKind kindFromString(String kind) { |
| 449 switch (kind) { | 471 switch (kind) { |
| 450 case 'library': | 472 case 'library': |
| 451 return InfoKind.library; | 473 return InfoKind.library; |
| 452 case 'class': | 474 case 'class': |
| 453 return InfoKind.clazz; | 475 return InfoKind.clazz; |
| 454 case 'function': | 476 case 'function': |
| 455 return InfoKind.function; | 477 return InfoKind.function; |
| 456 case 'field': | 478 case 'field': |
| 457 return InfoKind.field; | 479 return InfoKind.field; |
| 458 case 'constant': | 480 case 'constant': |
| 459 return InfoKind.constant; | 481 return InfoKind.constant; |
| 460 case 'outputUnit': | 482 case 'outputUnit': |
| 461 return InfoKind.outputUnit; | 483 return InfoKind.outputUnit; |
| 462 case 'typedef': | 484 case 'typedef': |
| 463 return InfoKind.typedef; | 485 return InfoKind.typedef; |
| 486 case 'closure': |
| 487 return InfoKind.closure; |
| 464 default: | 488 default: |
| 465 return null; | 489 return null; |
| 466 } | 490 } |
| 467 } | 491 } |
| 468 | 492 |
| 469 /// A simple visitor for information produced by the dart2js compiler. | 493 /// A simple visitor for information produced by the dart2js compiler. |
| 470 abstract class InfoVisitor<T> { | 494 abstract class InfoVisitor<T> { |
| 471 T visitAll(AllInfo info); | 495 T visitAll(AllInfo info); |
| 472 T visitProgram(ProgramInfo info); | 496 T visitProgram(ProgramInfo info); |
| 473 T visitLibrary(LibraryInfo info); | 497 T visitLibrary(LibraryInfo info); |
| 474 T visitClass(ClassInfo info); | 498 T visitClass(ClassInfo info); |
| 475 T visitField(FieldInfo info); | 499 T visitField(FieldInfo info); |
| 476 T visitConstant(ConstantInfo info); | 500 T visitConstant(ConstantInfo info); |
| 477 T visitFunction(FunctionInfo info); | 501 T visitFunction(FunctionInfo info); |
| 478 T visitTypedef(TypedefInfo info); | 502 T visitTypedef(TypedefInfo info); |
| 503 T visitClosure(ClosureInfo info); |
| 479 T visitOutput(OutputUnitInfo info); | 504 T visitOutput(OutputUnitInfo info); |
| 480 } | 505 } |
| 481 | 506 |
| 482 /// A visitor that recursively walks each portion of the program. Because the | 507 /// A visitor that recursively walks each portion of the program. Because the |
| 483 /// info representation is redundant, this visitor only walks the structure of | 508 /// info representation is redundant, this visitor only walks the structure of |
| 484 /// the program and skips some redundant links. For example, even though | 509 /// the program and skips some redundant links. For example, even though |
| 485 /// visitAll contains references to functions, this visitor only recurses to | 510 /// visitAll contains references to functions, this visitor only recurses to |
| 486 /// visit libraries, then from each library we visit functions and classes, and | 511 /// visit libraries, then from each library we visit functions and classes, and |
| 487 /// so on. | 512 /// so on. |
| 488 class RecursiveInfoVisitor extends InfoVisitor<Null> { | 513 class RecursiveInfoVisitor extends InfoVisitor<Null> { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 501 info.classes.forEach(visitClass); | 526 info.classes.forEach(visitClass); |
| 502 info.typedefs.forEach(visitTypedef); | 527 info.typedefs.forEach(visitTypedef); |
| 503 } | 528 } |
| 504 | 529 |
| 505 visitClass(ClassInfo info) { | 530 visitClass(ClassInfo info) { |
| 506 info.functions.forEach(visitFunction); | 531 info.functions.forEach(visitFunction); |
| 507 info.fields.forEach(visitField); | 532 info.fields.forEach(visitField); |
| 508 } | 533 } |
| 509 | 534 |
| 510 visitField(FieldInfo info) { | 535 visitField(FieldInfo info) { |
| 511 info.closures.forEach(visitFunction); | 536 info.closures.forEach(visitClosure); |
| 512 } | 537 } |
| 513 | 538 |
| 514 visitConstant(ConstantInfo info) {} | 539 visitConstant(ConstantInfo info) {} |
| 515 | 540 |
| 516 visitFunction(FunctionInfo info) { | 541 visitFunction(FunctionInfo info) { |
| 517 info.closures.forEach(visitFunction); | 542 info.closures.forEach(visitClosure); |
| 518 } | 543 } |
| 519 | 544 |
| 520 visitTypedef(TypedefInfo info) {} | 545 visitTypedef(TypedefInfo info) {} |
| 521 visitOutput(OutputUnitInfo info) {} | 546 visitOutput(OutputUnitInfo info) {} |
| 547 visitClosure(ClosureInfo info) { |
| 548 visitFunction(info.function); |
| 549 } |
| 522 } | 550 } |
| OLD | NEW |