| 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 import 'serialization_util.dart'; | 16 import 'serialization_util.dart'; |
| 17 | 17 |
| 18 /// Enum kinds used for encoding [Element]s. | 18 /// Enum kinds used for encoding [Element]s. |
| 19 enum SerializedElementKind { | 19 enum SerializedElementKind { |
| 20 LIBRARY, | 20 LIBRARY, |
| 21 COMPILATION_UNIT, | 21 COMPILATION_UNIT, |
| 22 CLASS, | 22 CLASS, |
| 23 ENUM, | 23 ENUM, |
| 24 NAMED_MIXIN_APPLICATION, | 24 NAMED_MIXIN_APPLICATION, |
| 25 GENERATIVE_CONSTRUCTOR, | 25 GENERATIVE_CONSTRUCTOR, |
| 26 DEFAULT_CONSTRUCTOR, |
| 26 FACTORY_CONSTRUCTOR, | 27 FACTORY_CONSTRUCTOR, |
| 27 REDIRECTING_FACTORY_CONSTRUCTOR, | 28 REDIRECTING_FACTORY_CONSTRUCTOR, |
| 28 FORWARDING_CONSTRUCTOR, | 29 FORWARDING_CONSTRUCTOR, |
| 29 TOPLEVEL_FIELD, | 30 TOPLEVEL_FIELD, |
| 30 STATIC_FIELD, | 31 STATIC_FIELD, |
| 31 INSTANCE_FIELD, | 32 INSTANCE_FIELD, |
| 32 ENUM_CONSTANT, | 33 ENUM_CONSTANT, |
| 33 TOPLEVEL_FUNCTION, | 34 TOPLEVEL_FUNCTION, |
| 34 TOPLEVEL_GETTER, | 35 TOPLEVEL_GETTER, |
| 35 TOPLEVEL_SETTER, | 36 TOPLEVEL_SETTER, |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 encoder.setType(Key.MIXIN, mixinElement.mixinType); | 336 encoder.setType(Key.MIXIN, mixinElement.mixinType); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 class ConstructorSerializer implements ElementSerializer { | 341 class ConstructorSerializer implements ElementSerializer { |
| 341 const ConstructorSerializer(); | 342 const ConstructorSerializer(); |
| 342 | 343 |
| 343 SerializedElementKind getSerializedKind(Element element) { | 344 SerializedElementKind getSerializedKind(Element element) { |
| 344 if (element.isGenerativeConstructor) { | 345 if (element.isGenerativeConstructor) { |
| 345 if (element.enclosingClass.isNamedMixinApplication) { | 346 ConstructorElement constructor = element; |
| 347 if (constructor.enclosingClass.isNamedMixinApplication) { |
| 346 return SerializedElementKind.FORWARDING_CONSTRUCTOR; | 348 return SerializedElementKind.FORWARDING_CONSTRUCTOR; |
| 349 } else if (constructor.definingConstructor != null) { |
| 350 return SerializedElementKind.DEFAULT_CONSTRUCTOR; |
| 347 } else { | 351 } else { |
| 348 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; | 352 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; |
| 349 } | 353 } |
| 350 } else if (element.isFactoryConstructor) { | 354 } else if (element.isFactoryConstructor) { |
| 351 ConstructorElement constructor = element; | 355 ConstructorElement constructor = element; |
| 352 if (constructor.isRedirectingFactory) { | 356 if (constructor.isRedirectingFactory) { |
| 353 return SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR; | 357 return SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR; |
| 354 } else { | 358 } else { |
| 355 return SerializedElementKind.FACTORY_CONSTRUCTOR; | 359 return SerializedElementKind.FACTORY_CONSTRUCTOR; |
| 356 } | 360 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 369 SerializerUtil.serializePosition(element, encoder); | 373 SerializerUtil.serializePosition(element, encoder); |
| 370 SerializerUtil.serializeParameters(element, encoder); | 374 SerializerUtil.serializeParameters(element, encoder); |
| 371 encoder.setBool(Key.IS_CONST, element.isConst); | 375 encoder.setBool(Key.IS_CONST, element.isConst); |
| 372 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); | 376 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); |
| 373 if (element.isConst && !element.isFromEnvironmentConstructor) { | 377 if (element.isConst && !element.isFromEnvironmentConstructor) { |
| 374 ConstantConstructor constantConstructor = element.constantConstructor; | 378 ConstantConstructor constantConstructor = element.constantConstructor; |
| 375 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); | 379 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); |
| 376 const ConstantConstructorSerializer() | 380 const ConstantConstructorSerializer() |
| 377 .visit(constantConstructor, constantEncoder); | 381 .visit(constantConstructor, constantEncoder); |
| 378 } | 382 } |
| 379 if (element.definingConstructor != null) { | |
| 380 assert(invariant( | |
| 381 element, | |
| 382 element.definingConstructor.enclosingClass == | |
| 383 element.enclosingClass.superclass, | |
| 384 message: "Unexpected defining constructor: " | |
| 385 "${element.definingConstructor}")); | |
| 386 encoder.setString( | |
| 387 Key.DEFINING_CONSTRUCTOR, element.definingConstructor.name); | |
| 388 } | |
| 389 if (kind == SerializedElementKind.GENERATIVE_CONSTRUCTOR) { | 383 if (kind == SerializedElementKind.GENERATIVE_CONSTRUCTOR) { |
| 390 encoder.setBool(Key.IS_REDIRECTING, element.isRedirectingGenerative); | 384 encoder.setBool(Key.IS_REDIRECTING, element.isRedirectingGenerative); |
| 391 } | 385 } |
| 392 encoder.setElement(Key.EFFECTIVE_TARGET, element.effectiveTarget); | 386 encoder.setElement(Key.EFFECTIVE_TARGET, element.effectiveTarget); |
| 393 if (kind == SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR) { | 387 if (kind == SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR) { |
| 394 encoder.setType( | 388 encoder.setType( |
| 395 Key.EFFECTIVE_TARGET_TYPE, | 389 Key.EFFECTIVE_TARGET_TYPE, |
| 396 element | 390 element |
| 397 .computeEffectiveTargetType(element.enclosingClass.thisType)); | 391 .computeEffectiveTargetType(element.enclosingClass.thisType)); |
| 398 encoder.setElement(Key.IMMEDIATE_REDIRECTION_TARGET, | 392 encoder.setElement(Key.IMMEDIATE_REDIRECTION_TARGET, |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 case SerializedElementKind.TOPLEVEL_FIELD: | 676 case SerializedElementKind.TOPLEVEL_FIELD: |
| 683 return new TopLevelFieldElementZ(decoder); | 677 return new TopLevelFieldElementZ(decoder); |
| 684 case SerializedElementKind.STATIC_FIELD: | 678 case SerializedElementKind.STATIC_FIELD: |
| 685 return new StaticFieldElementZ(decoder); | 679 return new StaticFieldElementZ(decoder); |
| 686 case SerializedElementKind.ENUM_CONSTANT: | 680 case SerializedElementKind.ENUM_CONSTANT: |
| 687 return new EnumConstantElementZ(decoder); | 681 return new EnumConstantElementZ(decoder); |
| 688 case SerializedElementKind.INSTANCE_FIELD: | 682 case SerializedElementKind.INSTANCE_FIELD: |
| 689 return new InstanceFieldElementZ(decoder); | 683 return new InstanceFieldElementZ(decoder); |
| 690 case SerializedElementKind.GENERATIVE_CONSTRUCTOR: | 684 case SerializedElementKind.GENERATIVE_CONSTRUCTOR: |
| 691 return new GenerativeConstructorElementZ(decoder); | 685 return new GenerativeConstructorElementZ(decoder); |
| 686 case SerializedElementKind.DEFAULT_CONSTRUCTOR: |
| 687 return new DefaultConstructorElementZ(decoder); |
| 692 case SerializedElementKind.FACTORY_CONSTRUCTOR: | 688 case SerializedElementKind.FACTORY_CONSTRUCTOR: |
| 693 return new FactoryConstructorElementZ(decoder); | 689 return new FactoryConstructorElementZ(decoder); |
| 694 case SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR: | 690 case SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR: |
| 695 return new RedirectingFactoryConstructorElementZ(decoder); | 691 return new RedirectingFactoryConstructorElementZ(decoder); |
| 696 case SerializedElementKind.FORWARDING_CONSTRUCTOR: | 692 case SerializedElementKind.FORWARDING_CONSTRUCTOR: |
| 697 return new ForwardingConstructorElementZ( | 693 return new ForwardingConstructorElementZ( |
| 698 decoder.getElement(Key.CLASS), decoder.getElement(Key.ELEMENT)); | 694 decoder.getElement(Key.CLASS), decoder.getElement(Key.ELEMENT)); |
| 699 case SerializedElementKind.TOPLEVEL_FUNCTION: | 695 case SerializedElementKind.TOPLEVEL_FUNCTION: |
| 700 return new TopLevelFunctionElementZ(decoder); | 696 return new TopLevelFunctionElementZ(decoder); |
| 701 case SerializedElementKind.STATIC_FUNCTION: | 697 case SerializedElementKind.STATIC_FUNCTION: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 return new LocalVariableElementZ(decoder); | 730 return new LocalVariableElementZ(decoder); |
| 735 case SerializedElementKind.EXTERNAL_LIBRARY: | 731 case SerializedElementKind.EXTERNAL_LIBRARY: |
| 736 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: | 732 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: |
| 737 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: | 733 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: |
| 738 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: | 734 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: |
| 739 break; | 735 break; |
| 740 } | 736 } |
| 741 throw new UnsupportedError("Unexpected element kind '${elementKind}."); | 737 throw new UnsupportedError("Unexpected element kind '${elementKind}."); |
| 742 } | 738 } |
| 743 } | 739 } |
| OLD | NEW |