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

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 InfoKind kind; 47 final InfoKind kind;
45 final int id; 48 final int id;
46 int size; 49 int size;
50 Info parent;
47 51
48 String get serializedId => '${_kindToString(kind)}/$id'; 52 String get serializedId => '${_kindToString(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 = _kindFromSerializedId(serializedId), 63 : kind = _kindFromSerializedId(serializedId),
60 id = _idFromSerializedId(serializedId); 64 id = _idFromSerializedId(serializedId);
61 65
62 Map toJson() { 66 Map toJson() {
63 var res = { 67 var res = {
64 'id': serializedId, 68 'id': serializedId,
65 'kind': _kindToString(kind), 69 'kind': _kindToString(kind),
66 'name': name, 70 'name': name,
67 'size': size, 71 'size': size,
68 }; 72 };
69 // TODO(sigmund): omit this also when outputUnit.id == 0 73 // TODO(sigmund): omit this also when outputUnit.id == 0
70 // (most code is by default in the main output unit) 74 // (most code is by default in the main output unit)
71 if (outputUnit != null) res['outputUnit'] = outputUnit.serializedId; 75 if (outputUnit != null) res['outputUnit'] = outputUnit.serializedId;
76 if (parent != null) res['parent'] = parent.serializedId;
72 return res; 77 return res;
73 } 78 }
74 79
75 String toString() => '$serializedId $name [$size]'; 80 String toString() => '$serializedId $name [$size]';
76 } 81 }
77 82
78 /// Info associated with elements containing executable code (like fields and 83 /// Info associated with elements containing executable code (like fields and
79 /// methods) 84 /// methods)
80 abstract class CodeInfo implements Info { 85 abstract class CodeInfo implements Info {
81 /// How does this function or field depend on others. 86 /// How does this function or field depend on others.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 /// Major version indicating breaking changes in the format. A new version 122 /// Major version indicating breaking changes in the format. A new version
118 /// means that an old deserialization algorithm will not work with the new 123 /// means that an old deserialization algorithm will not work with the new
119 /// format. 124 /// format.
120 final int version = 3; 125 final int version = 3;
121 126
122 /// Minor version indicating non-breaking changes in the format. A change in 127 /// Minor version indicating non-breaking changes in the format. A change in
123 /// this version number means that the json parsing in this library from a 128 /// this version number means that the json parsing in this library from a
124 /// previous will continue to work after the change. This is typically 129 /// previous will continue to work after the change. This is typically
125 /// increased when adding new entries to the file format. 130 /// increased when adding new entries to the file format.
126 // Note: the dump-info.viewer app was written using a json parser version 3.2. 131 // Note: the dump-info.viewer app was written using a json parser version 3.2.
127 final int minorVersion = 3; 132 final int minorVersion = 4;
128 133
129 AllInfo(); 134 AllInfo();
130 135
131 static AllInfo parseFromJson(Map map) => new _ParseHelper().parseAll(map); 136 static AllInfo parseFromJson(Map map) => new _ParseHelper().parseAll(map);
132 137
133 Map _listAsJsonMap(List<Info> list) { 138 Map _listAsJsonMap(List<Info> list) {
134 var map = <String, Map>{}; 139 var map = <String, Map>{};
135 for (var info in list) { 140 for (var info in list) {
136 map['${info.id}'] = info.toJson(); 141 map['${info.id}'] = info.toJson();
137 } 142 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 assert(child is TypedefInfo); 262 assert(child is TypedefInfo);
258 result.typedefs.add(child); 263 result.typedefs.add(child);
259 } 264 }
260 } 265 }
261 return result; 266 return result;
262 } 267 }
263 268
264 ClassInfo parseClass(Map json) { 269 ClassInfo parseClass(Map json) {
265 ClassInfo result = parseId(json['id']); 270 ClassInfo result = parseId(json['id']);
266 result..name = json['name'] 271 result..name = json['name']
272 ..parent = parseId(json['parent'])
267 ..outputUnit = parseId(json['outputUnit']) 273 ..outputUnit = parseId(json['outputUnit'])
268 ..size = json['size'] 274 ..size = json['size']
269 ..isAbstract = json['modifiers']['abstract'] == true; 275 ..isAbstract = json['modifiers']['abstract'] == true;
270 assert(result is ClassInfo); 276 assert(result is ClassInfo);
271 for (var child in json['children'].map(parseId)) { 277 for (var child in json['children'].map(parseId)) {
272 if (child is FunctionInfo) { 278 if (child is FunctionInfo) {
273 result.functions.add(child); 279 result.functions.add(child);
274 } else { 280 } else {
275 assert(child is FieldInfo); 281 assert(child is FieldInfo);
276 result.fields.add(child); 282 result.fields.add(child);
277 } 283 }
278 } 284 }
279 return result; 285 return result;
280 } 286 }
281 287
282 FieldInfo parseField(Map json) { 288 FieldInfo parseField(Map json) {
283 FieldInfo result = parseId(json['id']); 289 FieldInfo result = parseId(json['id']);
284 return result..name = json['name'] 290 return result..name = json['name']
291 ..parent = parseId(json['parent'])
285 ..outputUnit = parseId(json['outputUnit']) 292 ..outputUnit = parseId(json['outputUnit'])
286 ..size = json['size'] 293 ..size = json['size']
287 ..type = json['type'] 294 ..type = json['type']
288 ..inferredType = json['inferredType'] 295 ..inferredType = json['inferredType']
289 ..code = json['code'] 296 ..code = json['code']
290 ..closures = json['children'].map(parseId).toList(); 297 ..closures = json['children'].map(parseId).toList();
291 } 298 }
292 299
293 TypedefInfo parseTypedef(Map json) { 300 TypedefInfo parseTypedef(Map json) {
294 TypedefInfo result = parseId(json['id']); 301 TypedefInfo result = parseId(json['id']);
295 return result..name = json['name'] 302 return result..name = json['name']
303 ..parent = parseId(json['parent'])
296 ..type = json['type'] 304 ..type = json['type']
297 ..size = 0; 305 ..size = 0;
298 } 306 }
299 307
300 ProgramInfo parseProgram(Map json) => 308 ProgramInfo parseProgram(Map json) =>
301 new ProgramInfo()..size = json['size']; 309 new ProgramInfo()..size = json['size'];
302 310
303 FunctionInfo parseFunction(Map json) { 311 FunctionInfo parseFunction(Map json) {
304 FunctionInfo result = parseId(json['id']); 312 FunctionInfo result = parseId(json['id']);
305 return result..name = json['name'] 313 return result..name = json['name']
314 ..parent = parseId(json['parent'])
306 ..outputUnit = parseId(json['outputUnit']) 315 ..outputUnit = parseId(json['outputUnit'])
307 ..size = json['size'] 316 ..size = json['size']
308 ..type = json['type'] 317 ..type = json['type']
309 ..returnType = json['returnType'] 318 ..returnType = json['returnType']
310 ..inferredReturnType = json['inferredReturnType'] 319 ..inferredReturnType = json['inferredReturnType']
311 ..parameters = json['parameters'].map(parseParameter).toList() 320 ..parameters = json['parameters'].map(parseParameter).toList()
312 ..code = json['code'] 321 ..code = json['code']
313 ..sideEffects = json['sideEffects'] 322 ..sideEffects = json['sideEffects']
314 ..modifiers = parseModifiers(json['modifiers']) 323 ..modifiers = parseModifiers(json['modifiers'])
315 ..closures = json['children'].map(parseId).toList(); 324 ..closures = json['children'].map(parseId).toList();
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 705 }
697 706
698 visitField(FieldInfo info) { 707 visitField(FieldInfo info) {
699 info.closures.forEach(visitFunction); 708 info.closures.forEach(visitFunction);
700 } 709 }
701 710
702 visitFunction(FunctionInfo info) { 711 visitFunction(FunctionInfo info) {
703 info.closures.forEach(visitFunction); 712 info.closures.forEach(visitFunction);
704 } 713 }
705 } 714 }
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