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