Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: pkg/compiler/lib/src/info/info.dart

Issue 1287533002: dart2js: add parent references to some info objects (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/dump_info.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 collected by the dump-info task. 5 /// Data collected by the dump-info task.
6 library compiler.src.lib.info; 6 library compiler.src.lib.info;
7 7
8 // Note: this file intentionally doesn't import anything from the compiler. That 8 // Note: this file intentionally doesn't import anything from the compiler. That
9 // should make it easier for tools to depend on this library. The idea is that 9 // should make it easier for tools to depend on this library. The idea is that
10 // by using this library, tools can consume the information in the same way it 10 // by using this library, tools can consume the information in the same way it
(...skipping 11 matching lines...) Expand all
22 22
23 /// An id to uniquely identify this info among infos of the same [kind]. 23 /// An id to uniquely identify this info among infos of the same [kind].
24 int get id; 24 int get id;
25 25
26 /// A globally unique id combining [kind] and [id] together. 26 /// A globally unique id combining [kind] and [id] together.
27 String get serializedId; 27 String get serializedId;
28 28
29 /// Bytes used in the generated code for the corresponding element. 29 /// Bytes used in the generated code for the corresponding element.
30 int size; 30 int size;
31 31
32 /// Info of the enclosing element.
33 Info parent;
34
32 /// Serializes the information into a JSON format. 35 /// Serializes the information into a JSON format.
33 // TODO(sigmund): refactor and put toJson outside the class, so we can have 2 36 // TODO(sigmund): refactor and put toJson outside the class, so we can have 2
34 // different serializer/deserializers at once. 37 // different serializer/deserializers at once.
35 Map toJson(); 38 Map toJson();
36 39
37 void accept(InfoVisitor visitor); 40 void accept(InfoVisitor visitor);
38 } 41 }
39 42
40 /// Common information used for most kind of elements. 43 /// Common information used for most kind of elements.
41 // TODO(sigmund): add more: 44 // TODO(sigmund): add more:
42 // - inputSize: bytes used in the Dart source program 45 // - inputSize: bytes used in the Dart source program
43 abstract class BasicInfo implements Info { 46 abstract class BasicInfo implements Info {
44 final String kind; 47 final String kind;
45 final int id; 48 final int id;
46 int size; 49 int size;
50 Info parent;
47 51
48 String get serializedId => '$kind/$id'; 52 String get serializedId => '$kind/$id';
49 53
50 String name; 54 String name;
51 55
52 /// If using deferred libraries, where the element associated with this info 56 /// If using deferred libraries, where the element associated with this info
53 /// is generated. 57 /// is generated.
54 OutputUnitInfo outputUnit; 58 OutputUnitInfo outputUnit;
55 59
56 BasicInfo(this.kind, this.id, this.name, this.outputUnit, this.size); 60 BasicInfo(this.kind, this.id, this.name, this.outputUnit, this.size);
57 61
58 BasicInfo._fromId(String serializedId) 62 BasicInfo._fromId(String serializedId)
59 : kind = serializedId.substring(0, serializedId.indexOf('/')), 63 : kind = serializedId.substring(0, serializedId.indexOf('/')),
60 id = int.parse(serializedId.substring(serializedId.indexOf('/') + 1)); 64 id = int.parse(serializedId.substring(serializedId.indexOf('/') + 1));
61 65
62 Map toJson() { 66 Map toJson() {
63 var res = {'id': serializedId, 'kind': kind, 'name': name, 'size': size}; 67 var res = {'id': serializedId, 'kind': kind, 'name': name, 'size': size};
64 // TODO(sigmund): omit this also when outputUnit.id == 0 68 // TODO(sigmund): omit this also when outputUnit.id == 0
65 // (most code is by default in the main output unit) 69 // (most code is by default in the main output unit)
66 if (outputUnit != null) res['outputUnit'] = outputUnit.serializedId; 70 if (outputUnit != null) res['outputUnit'] = outputUnit.serializedId;
71 if (parent != null) res['parent'] = parent.serializedId;
67 return res; 72 return res;
68 } 73 }
69 74
70 String toString() => '$serializedId $name [$size]'; 75 String toString() => '$serializedId $name [$size]';
71 } 76 }
72 77
73 /// Info associated with elements containing executable code (like fields and 78 /// Info associated with elements containing executable code (like fields and
74 /// methods) 79 /// methods)
75 abstract class CodeInfo implements Info { 80 abstract class CodeInfo implements Info {
76 /// How does this function or field depend on others. 81 /// How does this function or field depend on others.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /// Major version indicating breaking changes in the format. A new version 117 /// Major version indicating breaking changes in the format. A new version
113 /// means that an old deserialization algorithm will not work with the new 118 /// means that an old deserialization algorithm will not work with the new
114 /// format. 119 /// format.
115 final int version = 3; 120 final int version = 3;
116 121
117 /// Minor version indicating non-breaking changes in the format. A change in 122 /// Minor version indicating non-breaking changes in the format. A change in
118 /// this version number means that the json parsing in this library from a 123 /// this version number means that the json parsing in this library from a
119 /// previous will continue to work after the change. This is typically 124 /// previous will continue to work after the change. This is typically
120 /// increased when adding new entries to the file format. 125 /// increased when adding new entries to the file format.
121 // Note: the dump-info.viewer app was written using a json parser version 3.2. 126 // Note: the dump-info.viewer app was written using a json parser version 3.2.
122 final int minorVersion = 3; 127 final int minorVersion = 4;
123 128
124 AllInfo(); 129 AllInfo();
125 130
126 static AllInfo parseFromJson(Map map) => new _ParseHelper().parseAll(map); 131 static AllInfo parseFromJson(Map map) => new _ParseHelper().parseAll(map);
127 132
128 Map _listAsJsonMap(List<Info> list) { 133 Map _listAsJsonMap(List<Info> list) {
129 var map = <String, Map>{}; 134 var map = <String, Map>{};
130 for (var info in list) { 135 for (var info in list) {
131 map['${info.id}'] = info.toJson(); 136 map['${info.id}'] = info.toJson();
132 } 137 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 }); 235 });
231 236
232 result.program = parseProgram(json['program']); 237 result.program = parseProgram(json['program']);
233 // todo: version, etc 238 // todo: version, etc
234 return result; 239 return result;
235 } 240 }
236 241
237 LibraryInfo parseLibrary(Map json) { 242 LibraryInfo parseLibrary(Map json) {
238 var result = parseId(json['id']) 243 var result = parseId(json['id'])
239 ..name = json['name'] 244 ..name = json['name']
245 ..parent = parseId(json['parent'])
Harry Terkelsen 2015/08/11 01:23:14 can libraries have parents?
Siggi Cherem (dart-lang) 2015/08/11 16:44:27 Good point, it's always going to be null. Removed.
240 ..uri = Uri.parse(json['canonicalUri']) 246 ..uri = Uri.parse(json['canonicalUri'])
241 ..outputUnit = parseId(json['outputUnit']) 247 ..outputUnit = parseId(json['outputUnit'])
242 ..size = json['size']; 248 ..size = json['size'];
243 assert(result.kind == 'library'); 249 assert(result.kind == 'library');
244 for (var child in json['children'].map(parseId)) { 250 for (var child in json['children'].map(parseId)) {
245 if (child is FunctionInfo) { 251 if (child is FunctionInfo) {
246 result.topLevelFunctions.add(child); 252 result.topLevelFunctions.add(child);
247 } else if (child is FieldInfo) { 253 } else if (child is FieldInfo) {
248 result.topLevelVariables.add(child); 254 result.topLevelVariables.add(child);
249 } else if (child is ClassInfo) { 255 } else if (child is ClassInfo) {
250 result.classes.add(child); 256 result.classes.add(child);
251 } else { 257 } else {
252 assert(child is TypedefInfo); 258 assert(child is TypedefInfo);
253 result.typedefs.add(child); 259 result.typedefs.add(child);
254 } 260 }
255 } 261 }
256 return result; 262 return result;
257 } 263 }
258 264
259 ClassInfo parseClass(Map json) { 265 ClassInfo parseClass(Map json) {
260 var result = parseId(json['id']) 266 var result = parseId(json['id'])
261 ..name = json['name'] 267 ..name = json['name']
268 ..parent = parseId(json['parent'])
262 ..outputUnit = parseId(json['outputUnit']) 269 ..outputUnit = parseId(json['outputUnit'])
263 ..size = json['size'] 270 ..size = json['size']
264 ..isAbstract = json['modifiers']['abstract'] == true; 271 ..isAbstract = json['modifiers']['abstract'] == true;
265 assert(result.kind == 'class'); 272 assert(result.kind == 'class');
266 for (var child in json['children'].map(parseId)) { 273 for (var child in json['children'].map(parseId)) {
267 if (child is FunctionInfo) { 274 if (child is FunctionInfo) {
268 result.functions.add(child); 275 result.functions.add(child);
269 } else { 276 } else {
270 assert(child is FieldInfo); 277 assert(child is FieldInfo);
271 result.fields.add(child); 278 result.fields.add(child);
272 } 279 }
273 } 280 }
274 return result; 281 return result;
275 } 282 }
276 283
277 FieldInfo parseField(Map json) { 284 FieldInfo parseField(Map json) {
278 return parseId(json['id']) 285 return parseId(json['id'])
279 ..name = json['name'] 286 ..name = json['name']
287 ..parent = parseId(json['parent'])
280 ..outputUnit = parseId(json['outputUnit']) 288 ..outputUnit = parseId(json['outputUnit'])
281 ..size = json['size'] 289 ..size = json['size']
282 ..type = json['type'] 290 ..type = json['type']
283 ..inferredType = json['inferredType'] 291 ..inferredType = json['inferredType']
284 ..code = json['code'] 292 ..code = json['code']
285 ..closures = json['children'].map(parseId).toList(); 293 ..closures = json['children'].map(parseId).toList();
286 } 294 }
287 295
288 TypedefInfo parseTypedef(Map json) => parseId(json['id']) 296 TypedefInfo parseTypedef(Map json) => parseId(json['id'])
289 ..name = json['name'] 297 ..name = json['name']
298 ..parent = parseId(json['parent'])
290 ..type = json['type'] 299 ..type = json['type']
291 ..size = 0; 300 ..size = 0;
292 301
293 ProgramInfo parseProgram(Map json) => 302 ProgramInfo parseProgram(Map json) =>
294 new ProgramInfo()..size = json['size']; 303 new ProgramInfo()..size = json['size'];
295 304
296 FunctionInfo parseFunction(Map json) { 305 FunctionInfo parseFunction(Map json) {
297 return parseId(json['id']) 306 return parseId(json['id'])
307 ..parent = parseId(json['parent'])
298 ..name = json['name'] 308 ..name = json['name']
299 ..outputUnit = parseId(json['outputUnit']) 309 ..outputUnit = parseId(json['outputUnit'])
300 ..size = json['size'] 310 ..size = json['size']
301 ..type = json['type'] 311 ..type = json['type']
302 ..returnType = json['returnType'] 312 ..returnType = json['returnType']
303 ..inferredReturnType = json['inferredReturnType'] 313 ..inferredReturnType = json['inferredReturnType']
304 ..parameters = json['parameters'].map(parseParameter).toList() 314 ..parameters = json['parameters'].map(parseParameter).toList()
305 ..code = json['code'] 315 ..code = json['code']
306 ..sideEffects = json['sideEffects'] 316 ..sideEffects = json['sideEffects']
307 ..modifiers = parseModifiers(json['modifiers']) 317 ..modifiers = parseModifiers(json['modifiers'])
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 info.closures.forEach(visitFunction); 630 info.closures.forEach(visitFunction);
621 } 631 }
622 632
623 visitFunction(FunctionInfo info) { 633 visitFunction(FunctionInfo info) {
624 info.closures.forEach(visitFunction); 634 info.closures.forEach(visitFunction);
625 } 635 }
626 636
627 visitTypedef(TypedefInfo info) {} 637 visitTypedef(TypedefInfo info) {}
628 visitOutput(OutputUnitInfo info) {} 638 visitOutput(OutputUnitInfo info) {}
629 } 639 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dump_info.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698