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

Side by Side Diff: pkg/compiler/lib/src/serialization/element_serialization.dart

Issue 1924053003: Serialize more properties of ConstructorElement. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: dartfmt Created 4 years, 7 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
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 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 17
17 /// Enum kinds used for encoding [Element]s. 18 /// Enum kinds used for encoding [Element]s.
18 enum SerializedElementKind { 19 enum SerializedElementKind {
19 LIBRARY, 20 LIBRARY,
20 COMPILATION_UNIT, 21 COMPILATION_UNIT,
21 CLASS, 22 CLASS,
22 ENUM, 23 ENUM,
23 NAMED_MIXIN_APPLICATION, 24 NAMED_MIXIN_APPLICATION,
24 GENERATIVE_CONSTRUCTOR, 25 GENERATIVE_CONSTRUCTOR,
25 FACTORY_CONSTRUCTOR, 26 FACTORY_CONSTRUCTOR,
27 REDIRECTING_FACTORY_CONSTRUCTOR,
26 FORWARDING_CONSTRUCTOR, 28 FORWARDING_CONSTRUCTOR,
27 TOPLEVEL_FIELD, 29 TOPLEVEL_FIELD,
28 STATIC_FIELD, 30 STATIC_FIELD,
29 INSTANCE_FIELD, 31 INSTANCE_FIELD,
30 ENUM_CONSTANT, 32 ENUM_CONSTANT,
31 TOPLEVEL_FUNCTION, 33 TOPLEVEL_FUNCTION,
32 TOPLEVEL_GETTER, 34 TOPLEVEL_GETTER,
33 TOPLEVEL_SETTER, 35 TOPLEVEL_SETTER,
34 STATIC_FUNCTION, 36 STATIC_FUNCTION,
35 STATIC_GETTER, 37 STATIC_GETTER,
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 const ConstructorSerializer(); 341 const ConstructorSerializer();
340 342
341 SerializedElementKind getSerializedKind(Element element) { 343 SerializedElementKind getSerializedKind(Element element) {
342 if (element.isGenerativeConstructor) { 344 if (element.isGenerativeConstructor) {
343 if (element.enclosingClass.isNamedMixinApplication) { 345 if (element.enclosingClass.isNamedMixinApplication) {
344 return SerializedElementKind.FORWARDING_CONSTRUCTOR; 346 return SerializedElementKind.FORWARDING_CONSTRUCTOR;
345 } else { 347 } else {
346 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; 348 return SerializedElementKind.GENERATIVE_CONSTRUCTOR;
347 } 349 }
348 } else if (element.isFactoryConstructor) { 350 } else if (element.isFactoryConstructor) {
349 return SerializedElementKind.FACTORY_CONSTRUCTOR; 351 ConstructorElement constructor = element;
352 if (constructor.isRedirectingFactory) {
353 return SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR;
354 } else {
355 return SerializedElementKind.FACTORY_CONSTRUCTOR;
356 }
350 } 357 }
351 return null; 358 return null;
352 } 359 }
353 360
354 void serialize(ConstructorElement element, ObjectEncoder encoder, 361 void serialize(ConstructorElement element, ObjectEncoder encoder,
355 SerializedElementKind kind) { 362 SerializedElementKind kind) {
356 SerializerUtil.serializeParentRelation(element, encoder); 363 SerializerUtil.serializeParentRelation(element, encoder);
357 if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) { 364 if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) {
358 encoder.setElement(Key.ELEMENT, element.definingConstructor); 365 encoder.setElement(Key.ELEMENT, element.definingConstructor);
359 } else { 366 } else {
360 encoder.setType(Key.TYPE, element.type); 367 encoder.setType(Key.TYPE, element.type);
361 encoder.setString(Key.NAME, element.name); 368 encoder.setString(Key.NAME, element.name);
362 SerializerUtil.serializePosition(element, encoder); 369 SerializerUtil.serializePosition(element, encoder);
363 SerializerUtil.serializeParameters(element, encoder); 370 SerializerUtil.serializeParameters(element, encoder);
364 encoder.setBool(Key.IS_CONST, element.isConst); 371 encoder.setBool(Key.IS_CONST, element.isConst);
365 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); 372 encoder.setBool(Key.IS_EXTERNAL, element.isExternal);
366 if (element.isExternal) return;
367 if (element.isConst && !element.isFromEnvironmentConstructor) { 373 if (element.isConst && !element.isFromEnvironmentConstructor) {
368 ConstantConstructor constantConstructor = element.constantConstructor; 374 ConstantConstructor constantConstructor = element.constantConstructor;
369 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); 375 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR);
370 const ConstantConstructorSerializer() 376 const ConstantConstructorSerializer()
371 .visit(constantConstructor, constantEncoder); 377 .visit(constantConstructor, constantEncoder);
372 } 378 }
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) {
390 encoder.setBool(Key.IS_REDIRECTING, element.isRedirectingGenerative);
391 }
392 encoder.setElement(Key.EFFECTIVE_TARGET, element.effectiveTarget);
393 if (kind == SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR) {
394 encoder.setType(
395 Key.EFFECTIVE_TARGET_TYPE,
396 element
397 .computeEffectiveTargetType(element.enclosingClass.thisType));
398 encoder.setElement(Key.IMMEDIATE_REDIRECTION_TARGET,
399 element.immediateRedirectionTarget);
400 if (element.redirectionDeferredPrefix != null) {
401 encoder.setElement(Key.PREFIX, element.redirectionDeferredPrefix);
402 }
403 }
373 } 404 }
374 } 405 }
375 } 406 }
376 407
377 class FieldSerializer implements ElementSerializer { 408 class FieldSerializer implements ElementSerializer {
378 const FieldSerializer(); 409 const FieldSerializer();
379 410
380 SerializedElementKind getSerializedKind(Element element) { 411 SerializedElementKind getSerializedKind(Element element) {
381 if (element.isField) { 412 if (element.isField) {
382 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FIELD; 413 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FIELD;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 case SerializedElementKind.STATIC_FIELD: 684 case SerializedElementKind.STATIC_FIELD:
654 return new StaticFieldElementZ(decoder); 685 return new StaticFieldElementZ(decoder);
655 case SerializedElementKind.ENUM_CONSTANT: 686 case SerializedElementKind.ENUM_CONSTANT:
656 return new EnumConstantElementZ(decoder); 687 return new EnumConstantElementZ(decoder);
657 case SerializedElementKind.INSTANCE_FIELD: 688 case SerializedElementKind.INSTANCE_FIELD:
658 return new InstanceFieldElementZ(decoder); 689 return new InstanceFieldElementZ(decoder);
659 case SerializedElementKind.GENERATIVE_CONSTRUCTOR: 690 case SerializedElementKind.GENERATIVE_CONSTRUCTOR:
660 return new GenerativeConstructorElementZ(decoder); 691 return new GenerativeConstructorElementZ(decoder);
661 case SerializedElementKind.FACTORY_CONSTRUCTOR: 692 case SerializedElementKind.FACTORY_CONSTRUCTOR:
662 return new FactoryConstructorElementZ(decoder); 693 return new FactoryConstructorElementZ(decoder);
694 case SerializedElementKind.REDIRECTING_FACTORY_CONSTRUCTOR:
695 return new RedirectingFactoryConstructorElementZ(decoder);
663 case SerializedElementKind.FORWARDING_CONSTRUCTOR: 696 case SerializedElementKind.FORWARDING_CONSTRUCTOR:
664 return new ForwardingConstructorElementZ( 697 return new ForwardingConstructorElementZ(
665 decoder.getElement(Key.CLASS), decoder.getElement(Key.ELEMENT)); 698 decoder.getElement(Key.CLASS), decoder.getElement(Key.ELEMENT));
666 case SerializedElementKind.TOPLEVEL_FUNCTION: 699 case SerializedElementKind.TOPLEVEL_FUNCTION:
667 return new TopLevelFunctionElementZ(decoder); 700 return new TopLevelFunctionElementZ(decoder);
668 case SerializedElementKind.STATIC_FUNCTION: 701 case SerializedElementKind.STATIC_FUNCTION:
669 return new StaticFunctionElementZ(decoder); 702 return new StaticFunctionElementZ(decoder);
670 case SerializedElementKind.INSTANCE_FUNCTION: 703 case SerializedElementKind.INSTANCE_FUNCTION:
671 return new InstanceFunctionElementZ(decoder); 704 return new InstanceFunctionElementZ(decoder);
672 case SerializedElementKind.LOCAL_FUNCTION: 705 case SerializedElementKind.LOCAL_FUNCTION:
(...skipping 28 matching lines...) Expand all
701 return new LocalVariableElementZ(decoder); 734 return new LocalVariableElementZ(decoder);
702 case SerializedElementKind.EXTERNAL_LIBRARY: 735 case SerializedElementKind.EXTERNAL_LIBRARY:
703 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: 736 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER:
704 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: 737 case SerializedElementKind.EXTERNAL_STATIC_MEMBER:
705 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: 738 case SerializedElementKind.EXTERNAL_CONSTRUCTOR:
706 break; 739 break;
707 } 740 }
708 throw new UnsupportedError("Unexpected element kind '${elementKind}."); 741 throw new UnsupportedError("Unexpected element kind '${elementKind}.");
709 } 742 }
710 } 743 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/serialization/keys.dart » ('j') | pkg/compiler/lib/src/serialization/modelz.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698