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 library dart2js.serialization.elements; | 5 library dart2js.serialization.elements; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../constants/constructors.dart'; | 8 import '../constants/constructors.dart'; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
12 import 'constant_serialization.dart'; | 12 import 'constant_serialization.dart'; |
13 import 'keys.dart'; | 13 import 'keys.dart'; |
14 import 'modelz.dart'; | 14 import 'modelz.dart'; |
15 import 'serialization.dart'; | 15 import 'serialization.dart'; |
16 | 16 |
17 /// Enum kinds used for encoding [Element]s. | 17 /// Enum kinds used for encoding [Element]s. |
18 enum SerializedElementKind { | 18 enum SerializedElementKind { |
19 LIBRARY, | 19 LIBRARY, |
20 COMPILATION_UNIT, | 20 COMPILATION_UNIT, |
21 CLASS, | 21 CLASS, |
22 ENUM, | 22 ENUM, |
23 NAMED_MIXIN_APPLICATION, | 23 NAMED_MIXIN_APPLICATION, |
24 GENERATIVE_CONSTRUCTOR, | 24 GENERATIVE_CONSTRUCTOR, |
25 FACTORY_CONSTRUCTOR, | 25 FACTORY_CONSTRUCTOR, |
| 26 FORWARDING_CONSTRUCTOR, |
26 TOPLEVEL_FIELD, | 27 TOPLEVEL_FIELD, |
27 STATIC_FIELD, | 28 STATIC_FIELD, |
28 INSTANCE_FIELD, | 29 INSTANCE_FIELD, |
29 ENUM_CONSTANT, | 30 ENUM_CONSTANT, |
30 TOPLEVEL_FUNCTION, | 31 TOPLEVEL_FUNCTION, |
31 TOPLEVEL_GETTER, | 32 TOPLEVEL_GETTER, |
32 TOPLEVEL_SETTER, | 33 TOPLEVEL_SETTER, |
33 STATIC_FUNCTION, | 34 STATIC_FUNCTION, |
34 STATIC_GETTER, | 35 STATIC_GETTER, |
35 STATIC_SETTER, | 36 STATIC_SETTER, |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 encoder.setType(Key.MIXIN, mixinElement.mixinType); | 333 encoder.setType(Key.MIXIN, mixinElement.mixinType); |
333 } | 334 } |
334 } | 335 } |
335 } | 336 } |
336 | 337 |
337 class ConstructorSerializer implements ElementSerializer { | 338 class ConstructorSerializer implements ElementSerializer { |
338 const ConstructorSerializer(); | 339 const ConstructorSerializer(); |
339 | 340 |
340 SerializedElementKind getSerializedKind(Element element) { | 341 SerializedElementKind getSerializedKind(Element element) { |
341 if (element.isGenerativeConstructor) { | 342 if (element.isGenerativeConstructor) { |
342 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; | 343 if (element.enclosingClass.isNamedMixinApplication) { |
| 344 return SerializedElementKind.FORWARDING_CONSTRUCTOR; |
| 345 } else { |
| 346 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; |
| 347 } |
343 } else if (element.isFactoryConstructor) { | 348 } else if (element.isFactoryConstructor) { |
344 return SerializedElementKind.FACTORY_CONSTRUCTOR; | 349 return SerializedElementKind.FACTORY_CONSTRUCTOR; |
345 } | 350 } |
346 return null; | 351 return null; |
347 } | 352 } |
348 | 353 |
349 void serialize(ConstructorElement element, ObjectEncoder encoder, | 354 void serialize(ConstructorElement element, ObjectEncoder encoder, |
350 SerializedElementKind kind) { | 355 SerializedElementKind kind) { |
351 SerializerUtil.serializeParentRelation(element, encoder); | 356 SerializerUtil.serializeParentRelation(element, encoder); |
352 encoder.setType(Key.TYPE, element.type); | 357 if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) { |
353 encoder.setString(Key.NAME, element.name); | 358 encoder.setElement(Key.ELEMENT, element.definingConstructor); |
354 SerializerUtil.serializePosition(element, encoder); | 359 } else { |
355 SerializerUtil.serializeParameters(element, encoder); | 360 encoder.setType(Key.TYPE, element.type); |
356 encoder.setBool(Key.IS_CONST, element.isConst); | 361 encoder.setString(Key.NAME, element.name); |
357 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); | 362 SerializerUtil.serializePosition(element, encoder); |
358 if (element.isExternal) return; | 363 SerializerUtil.serializeParameters(element, encoder); |
359 if (element.isConst && !element.isFromEnvironmentConstructor) { | 364 encoder.setBool(Key.IS_CONST, element.isConst); |
360 ConstantConstructor constantConstructor = element.constantConstructor; | 365 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); |
361 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); | 366 if (element.isExternal) return; |
362 const ConstantConstructorSerializer() | 367 if (element.isConst && !element.isFromEnvironmentConstructor) { |
363 .visit(constantConstructor, constantEncoder); | 368 ConstantConstructor constantConstructor = element.constantConstructor; |
| 369 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); |
| 370 const ConstantConstructorSerializer() |
| 371 .visit(constantConstructor, constantEncoder); |
| 372 } |
364 } | 373 } |
365 } | 374 } |
366 } | 375 } |
367 | 376 |
368 class FieldSerializer implements ElementSerializer { | 377 class FieldSerializer implements ElementSerializer { |
369 const FieldSerializer(); | 378 const FieldSerializer(); |
370 | 379 |
371 SerializedElementKind getSerializedKind(Element element) { | 380 SerializedElementKind getSerializedKind(Element element) { |
372 if (element.isField) { | 381 if (element.isField) { |
373 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FIELD; | 382 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FIELD; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 case SerializedElementKind.STATIC_FIELD: | 651 case SerializedElementKind.STATIC_FIELD: |
643 return new StaticFieldElementZ(decoder); | 652 return new StaticFieldElementZ(decoder); |
644 case SerializedElementKind.ENUM_CONSTANT: | 653 case SerializedElementKind.ENUM_CONSTANT: |
645 return new EnumConstantElementZ(decoder); | 654 return new EnumConstantElementZ(decoder); |
646 case SerializedElementKind.INSTANCE_FIELD: | 655 case SerializedElementKind.INSTANCE_FIELD: |
647 return new InstanceFieldElementZ(decoder); | 656 return new InstanceFieldElementZ(decoder); |
648 case SerializedElementKind.GENERATIVE_CONSTRUCTOR: | 657 case SerializedElementKind.GENERATIVE_CONSTRUCTOR: |
649 return new GenerativeConstructorElementZ(decoder); | 658 return new GenerativeConstructorElementZ(decoder); |
650 case SerializedElementKind.FACTORY_CONSTRUCTOR: | 659 case SerializedElementKind.FACTORY_CONSTRUCTOR: |
651 return new FactoryConstructorElementZ(decoder); | 660 return new FactoryConstructorElementZ(decoder); |
| 661 case SerializedElementKind.FORWARDING_CONSTRUCTOR: |
| 662 return new ForwardingConstructorElementZ( |
| 663 decoder.getElement(Key.CLASS), decoder.getElement(Key.ELEMENT)); |
652 case SerializedElementKind.TOPLEVEL_FUNCTION: | 664 case SerializedElementKind.TOPLEVEL_FUNCTION: |
653 return new TopLevelFunctionElementZ(decoder); | 665 return new TopLevelFunctionElementZ(decoder); |
654 case SerializedElementKind.STATIC_FUNCTION: | 666 case SerializedElementKind.STATIC_FUNCTION: |
655 return new StaticFunctionElementZ(decoder); | 667 return new StaticFunctionElementZ(decoder); |
656 case SerializedElementKind.INSTANCE_FUNCTION: | 668 case SerializedElementKind.INSTANCE_FUNCTION: |
657 return new InstanceFunctionElementZ(decoder); | 669 return new InstanceFunctionElementZ(decoder); |
658 case SerializedElementKind.LOCAL_FUNCTION: | 670 case SerializedElementKind.LOCAL_FUNCTION: |
659 return new LocalFunctionElementZ(decoder); | 671 return new LocalFunctionElementZ(decoder); |
660 case SerializedElementKind.TOPLEVEL_GETTER: | 672 case SerializedElementKind.TOPLEVEL_GETTER: |
661 return new TopLevelGetterElementZ(decoder); | 673 return new TopLevelGetterElementZ(decoder); |
(...skipping 25 matching lines...) Expand all Loading... |
687 return new LocalVariableElementZ(decoder); | 699 return new LocalVariableElementZ(decoder); |
688 case SerializedElementKind.EXTERNAL_LIBRARY: | 700 case SerializedElementKind.EXTERNAL_LIBRARY: |
689 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: | 701 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: |
690 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: | 702 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: |
691 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: | 703 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: |
692 break; | 704 break; |
693 } | 705 } |
694 throw new UnsupportedError("Unexpected element kind '${elementKind}."); | 706 throw new UnsupportedError("Unexpected element kind '${elementKind}."); |
695 } | 707 } |
696 } | 708 } |
OLD | NEW |