| 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 HtmlEscape, JsonEncoder, StringConversionSink, ChunkedConversionSink; | 8 show HtmlEscape, JsonEncoder, StringConversionSink, ChunkedConversionSink; |
| 9 | 9 |
| 10 import 'elements/elements.dart'; | 10 import 'elements/elements.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 int size = compiler.dumpInfoTask.sizeOf(element); | 66 int size = compiler.dumpInfoTask.sizeOf(element); |
| 67 LibraryInfo info = | 67 LibraryInfo info = |
| 68 new LibraryInfo(libname, element.canonicalUri, null, size); | 68 new LibraryInfo(libname, element.canonicalUri, null, size); |
| 69 _elementToInfo[element] = info; | 69 _elementToInfo[element] = info; |
| 70 | 70 |
| 71 LibraryElement realElement = element.isPatched ? element.patch : element; | 71 LibraryElement realElement = element.isPatched ? element.patch : element; |
| 72 realElement.forEachLocalMember((Element member) { | 72 realElement.forEachLocalMember((Element member) { |
| 73 Info child = this.process(member); | 73 Info child = this.process(member); |
| 74 if (child is ClassInfo) { | 74 if (child is ClassInfo) { |
| 75 info.classes.add(child); | 75 info.classes.add(child); |
| 76 child.parent = info; |
| 76 } else if (child is FunctionInfo) { | 77 } else if (child is FunctionInfo) { |
| 77 info.topLevelFunctions.add(child); | 78 info.topLevelFunctions.add(child); |
| 79 child.parent = info; |
| 78 } else if (child is FieldInfo) { | 80 } else if (child is FieldInfo) { |
| 79 info.topLevelVariables.add(child); | 81 info.topLevelVariables.add(child); |
| 82 child.parent = info; |
| 80 } else if (child is TypedefInfo) { | 83 } else if (child is TypedefInfo) { |
| 81 info.typedefs.add(child); | 84 info.typedefs.add(child); |
| 85 child.parent = info; |
| 82 } else if (child != null) { | 86 } else if (child != null) { |
| 83 print('unexpected child of $info: $child ==> ${child.runtimeType}'); | 87 print('unexpected child of $info: $child ==> ${child.runtimeType}'); |
| 84 assert(false); | 88 assert(false); |
| 85 } | 89 } |
| 86 }); | 90 }); |
| 87 | 91 |
| 88 if (info.isEmpty && !shouldKeep(element)) return null; | 92 if (info.isEmpty && !shouldKeep(element)) return null; |
| 89 result.libraries.add(info); | 93 result.libraries.add(info); |
| 90 return info; | 94 return info; |
| 91 } | 95 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 isAbstract: element.isAbstract, | 151 isAbstract: element.isAbstract, |
| 148 outputUnit: _unitInfoForElement(element)); | 152 outputUnit: _unitInfoForElement(element)); |
| 149 _elementToInfo[element] = classInfo; | 153 _elementToInfo[element] = classInfo; |
| 150 | 154 |
| 151 int size = compiler.dumpInfoTask.sizeOf(element); | 155 int size = compiler.dumpInfoTask.sizeOf(element); |
| 152 element.forEachLocalMember((Element member) { | 156 element.forEachLocalMember((Element member) { |
| 153 Info info = this.process(member); | 157 Info info = this.process(member); |
| 154 if (info == null) return; | 158 if (info == null) return; |
| 155 if (info is FieldInfo) { | 159 if (info is FieldInfo) { |
| 156 classInfo.fields.add(info); | 160 classInfo.fields.add(info); |
| 161 info.parent = classInfo; |
| 157 } else { | 162 } else { |
| 158 assert(info is FunctionInfo); | 163 assert(info is FunctionInfo); |
| 159 classInfo.functions.add(info); | 164 classInfo.functions.add(info); |
| 165 info.parent = classInfo; |
| 160 } | 166 } |
| 161 | 167 |
| 162 // Closures are placed in the library namespace, but we want to attribute | 168 // Closures are placed in the library namespace, but we want to attribute |
| 163 // them to a function, and by extension, this class. Process and add the | 169 // them to a function, and by extension, this class. Process and add the |
| 164 // sizes here. | 170 // sizes here. |
| 165 if (member is MemberElement) { | 171 if (member is MemberElement) { |
| 166 for (Element closure in member.nestedClosures) { | 172 for (Element closure in member.nestedClosures) { |
| 167 FunctionInfo closureInfo = this.process(closure); | 173 FunctionInfo closureInfo = this.process(closure); |
| 168 if (closureInfo == null) continue; | 174 if (closureInfo == null) continue; |
| 169 | 175 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 if (element is MemberElement) { | 277 if (element is MemberElement) { |
| 272 MemberElement member = element as MemberElement; | 278 MemberElement member = element as MemberElement; |
| 273 for (Element closure in member.nestedClosures) { | 279 for (Element closure in member.nestedClosures) { |
| 274 Info child = this.process(closure); | 280 Info child = this.process(closure); |
| 275 if (child != null) { | 281 if (child != null) { |
| 276 BasicInfo parent = this.process(closure.enclosingElement); | 282 BasicInfo parent = this.process(closure.enclosingElement); |
| 277 if (parent != null) { | 283 if (parent != null) { |
| 278 child.name = "${parent.name}.${child.name}"; | 284 child.name = "${parent.name}.${child.name}"; |
| 279 } | 285 } |
| 280 nestedClosures.add(child); | 286 nestedClosures.add(child); |
| 287 child.parent = parent; |
| 281 size += child.size; | 288 size += child.size; |
| 282 } | 289 } |
| 283 } | 290 } |
| 284 } | 291 } |
| 285 info.closures = nestedClosures; | 292 info.closures = nestedClosures; |
| 286 result.functions.add(info); | 293 result.functions.add(info); |
| 287 return info; | 294 return info; |
| 288 } | 295 } |
| 289 | 296 |
| 290 OutputUnitInfo _unitInfoForElement(Element element) { | 297 OutputUnitInfo _unitInfoForElement(Element element) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 510 |
| 504 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( | 511 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( |
| 505 new StringConversionSink.fromStringSink(buffer)); | 512 new StringConversionSink.fromStringSink(buffer)); |
| 506 sink.add(result.toJson()); | 513 sink.add(result.toJson()); |
| 507 compiler.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { | 514 compiler.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { |
| 508 'text': "View the dumped .info.json file at " | 515 'text': "View the dumped .info.json file at " |
| 509 "https://dart-lang.github.io/dump-info-visualizer" | 516 "https://dart-lang.github.io/dump-info-visualizer" |
| 510 }); | 517 }); |
| 511 } | 518 } |
| 512 } | 519 } |
| OLD | NEW |