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 /// Implementation of the element model used for deserialiation. | 5 /// Implementation of the element model used for deserialiation. |
6 /// | 6 /// |
7 /// These classes are created by [ElementDeserializer] triggered by the | 7 /// These classes are created by [ElementDeserializer] triggered by the |
8 /// [Deserializer]. | 8 /// [Deserializer]. |
9 | 9 |
10 library dart2js.serialization.modelz; | 10 library dart2js.serialization.modelz; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 return element; | 189 return element; |
190 } | 190 } |
191 } | 191 } |
192 if (members == null) { | 192 if (members == null) { |
193 return null; | 193 return null; |
194 } | 194 } |
195 bool hasId = members.containsKey(name); | 195 bool hasId = members.containsKey(name); |
196 String setterName = '$name,='; | 196 String setterName = '$name,='; |
197 bool hasSetterId = members.containsKey(setterName); | 197 bool hasSetterId = members.containsKey(setterName); |
198 Element element; | 198 Element element; |
199 Element setterElement; | 199 SetterElement setterElement; |
200 if (!hasId && !hasSetterId) { | 200 if (!hasId && !hasSetterId) { |
201 _lookupCache[name] = null; | 201 _lookupCache[name] = null; |
202 return null; | 202 return null; |
203 } | 203 } |
204 bool isAccessor = false; | 204 bool isAccessor = false; |
205 if (hasId) { | 205 if (hasId) { |
206 element = members.getElement(name); | 206 element = members.getElement(name); |
207 isAccessor = element.isGetter; | 207 isAccessor = element.isGetter; |
208 } | 208 } |
209 if (hasSetterId) { | 209 if (hasSetterId) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 class AbstractFieldElementZ extends ElementZ | 330 class AbstractFieldElementZ extends ElementZ |
331 with AbstractFieldElementCommon | 331 with AbstractFieldElementCommon |
332 implements AbstractFieldElement { | 332 implements AbstractFieldElement { |
333 final String name; | 333 final String name; |
334 final GetterElementZ getter; | 334 final GetterElementZ getter; |
335 final SetterElementZ setter; | 335 final SetterElementZ setter; |
336 | 336 |
337 AbstractFieldElementZ(this.name, this.getter, this.setter) { | 337 factory AbstractFieldElementZ( |
338 String name, GetterElement getter, SetterElement setter) { | |
339 if (getter != null && getter.abstractField != null) { | |
Harry Terkelsen
2016/07/13 18:06:46
if (getter?.abstractField != null)
Johnni Winther
2016/07/15 08:15:20
Done.
| |
340 return getter.abstractField; | |
341 } else if (setter != null && setter.abstractField != null) { | |
342 return setter.abstractField; | |
343 } else { | |
344 return new AbstractFieldElementZ._(name, getter, setter); | |
345 } | |
346 } | |
347 | |
348 AbstractFieldElementZ._(this.name, this.getter, this.setter) { | |
338 if (getter != null) { | 349 if (getter != null) { |
339 getter.abstractField = this; | 350 getter.abstractField = this; |
340 getter.setter = setter; | 351 getter.setter = setter; |
341 } | 352 } |
342 if (setter != null) { | 353 if (setter != null) { |
343 setter.abstractField = this; | 354 setter.abstractField = this; |
344 setter.getter = getter; | 355 setter.getter = getter; |
345 } | 356 } |
346 } | 357 } |
347 | 358 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 class LibraryElementZ extends DeserializedElementZ | 402 class LibraryElementZ extends DeserializedElementZ |
392 with AnalyzableElementMixin, ContainerMixin, LibraryElementCommon | 403 with AnalyzableElementMixin, ContainerMixin, LibraryElementCommon |
393 implements LibraryElement { | 404 implements LibraryElement { |
394 Uri _canonicalUri; | 405 Uri _canonicalUri; |
395 CompilationUnitElement _entryCompilationUnit; | 406 CompilationUnitElement _entryCompilationUnit; |
396 Link<CompilationUnitElement> _compilationUnits; | 407 Link<CompilationUnitElement> _compilationUnits; |
397 List<ImportElement> _imports; | 408 List<ImportElement> _imports; |
398 List<ExportElement> _exports; | 409 List<ExportElement> _exports; |
399 ListedContainer _exportsMap; | 410 ListedContainer _exportsMap; |
400 ListedContainer _importsMap; | 411 ListedContainer _importsMap; |
412 Map<Element, List<ImportElement>> _importsFor; | |
401 | 413 |
402 LibraryElementZ(ObjectDecoder decoder) : super(decoder); | 414 LibraryElementZ(ObjectDecoder decoder) : super(decoder); |
403 | 415 |
404 @override | 416 @override |
405 ElementKind get kind => ElementKind.LIBRARY; | 417 ElementKind get kind => ElementKind.LIBRARY; |
406 | 418 |
407 @override | 419 @override |
408 Element get enclosingElement => null; | 420 Element get enclosingElement => null; |
409 | 421 |
410 @override | 422 @override |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 } | 502 } |
491 | 503 |
492 @override | 504 @override |
493 Element findExported(String elementName) { | 505 Element findExported(String elementName) { |
494 _ensureExports(); | 506 _ensureExports(); |
495 return _exportsMap.lookup(elementName); | 507 return _exportsMap.lookup(elementName); |
496 } | 508 } |
497 | 509 |
498 void _ensureImports() { | 510 void _ensureImports() { |
499 if (_importsMap == null) { | 511 if (_importsMap == null) { |
500 _importsMap = new ListedContainer(_decoder.getElements(Key.IMPORT_SCOPE)); | 512 _importsMap = new ListedContainer( |
513 _decoder.getElements(Key.IMPORT_SCOPE, isOptional: true)); | |
514 _importsFor = <Element, List<ImportElement>>{}; | |
515 | |
516 ListDecoder importsDecoder = _decoder.getList(Key.IMPORTS_FOR); | |
517 for (int index = 0; index < importsDecoder.length; index++) { | |
518 ObjectDecoder objectDecoder = importsDecoder.getObject(index); | |
Harry Terkelsen
2016/07/13 18:06:46
maybe ListDecoder can implement Iterable<Decoder>?
Johnni Winther
2016/07/15 08:15:20
The elements are either ObjectDecoder or MapDecode
| |
519 Element key = objectDecoder.getElement(Key.ELEMENT); | |
520 List<ImportElement> imports = | |
521 objectDecoder.getElements(Key.IMPORTS, isOptional: true); | |
522 | |
523 // Imports are mapped to [AbstractFieldElement] which are not serialized | |
524 // so we use getter (or setter if there is no getter) as the key. | |
525 Element importedElement = key; | |
526 if (key.isDeferredLoaderGetter) { | |
527 // Use as [importedElement]. | |
528 } else if (key.isAccessor) { | |
529 AccessorElement accessor = key; | |
530 importedElement = accessor.abstractField; | |
531 } | |
532 _importsFor[importedElement] = imports; | |
533 } | |
501 } | 534 } |
502 } | 535 } |
503 | 536 |
504 @override | 537 @override |
505 void forEachImport(f(Element element)) { | 538 void forEachImport(f(Element element)) { |
506 _ensureImports(); | 539 _ensureImports(); |
507 _importsMap.forEach(f); | 540 _importsMap.forEach(f); |
508 } | 541 } |
509 | 542 |
510 @override | 543 @override |
511 Iterable<ImportElement> getImportsFor(Element element) { | 544 Iterable<ImportElement> getImportsFor(Element element) { |
512 // TODO(johnniwinther): Serialize this to support deferred access to | 545 _ensureImports(); |
513 // serialized entities. | 546 return _importsFor[element] ?? const <ImportElement>[]; |
514 return <ImportElement>[]; | |
515 } | 547 } |
516 | 548 |
517 String toString() { | 549 String toString() { |
518 return 'Zlibrary(${canonicalUri})'; | 550 return 'Zlibrary(${canonicalUri})'; |
519 } | 551 } |
520 | 552 |
521 @override | 553 @override |
522 Iterable<ExportElement> get exports { | 554 Iterable<ExportElement> get exports { |
523 if (_exports == null) { | 555 if (_exports == null) { |
524 _exports = _decoder.getElements(Key.EXPORTS, isOptional: true); | 556 _exports = _decoder.getElements(Key.EXPORTS, isOptional: true); |
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2359 } | 2391 } |
2360 | 2392 |
2361 @override | 2393 @override |
2362 Node get node => throw new UnsupportedError('${this}.node'); | 2394 Node get node => throw new UnsupportedError('${this}.node'); |
2363 | 2395 |
2364 @override | 2396 @override |
2365 bool get hasNode => false; | 2397 bool get hasNode => false; |
2366 | 2398 |
2367 String toString() => 'MetadataAnnotationZ(${constant.toDartText()})'; | 2399 String toString() => 'MetadataAnnotationZ(${constant.toDartText()})'; |
2368 } | 2400 } |
OLD | NEW |