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

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

Issue 2060183002: Serialize metadata (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 4 years, 6 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';
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (position.uri != element.compilationUnit.script.resourceUri) { 113 if (position.uri != element.compilationUnit.script.resourceUri) {
114 encoder.setUri(Key.URI, element.library.canonicalUri, position.uri); 114 encoder.setUri(Key.URI, element.library.canonicalUri, position.uri);
115 } 115 }
116 int length = position.end - position.begin; 116 int length = position.end - position.begin;
117 if (element.name.length != length) { 117 if (element.name.length != length) {
118 encoder.setInt(Key.LENGTH, length); 118 encoder.setInt(Key.LENGTH, length);
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 /// Serialize the metadata of [element] into [encoder].
124 static void serializeMetadata(Element element, ObjectEncoder encoder) {
125 if (element.metadata.isNotEmpty) {
126 ListEncoder list = encoder.createList(Key.METADATA);
127 for (MetadataAnnotation metadata in element.metadata) {
128 ObjectEncoder object = list.createObject();
129 object.setElement(Key.ELEMENT, metadata.annotatedElement);
130 SourceSpan sourcePosition = metadata.sourcePosition;
131 // TODO(johnniwinther): What is the base URI here?
132 object.setUri(Key.URI, sourcePosition.uri, sourcePosition.uri);
133 object.setInt(Key.OFFSET, sourcePosition.begin);
134 object.setInt(Key.LENGTH, sourcePosition.end - sourcePosition.begin);
135 object.setConstant(Key.CONSTANT, metadata.constant);
136 }
137 }
138 }
139
123 /// Serialize the parent relation for [element] into [encoder], i.e library, 140 /// Serialize the parent relation for [element] into [encoder], i.e library,
124 /// enclosing class, and compilation unit references. 141 /// enclosing class, and compilation unit references.
125 static void serializeParentRelation(Element element, ObjectEncoder encoder) { 142 static void serializeParentRelation(Element element, ObjectEncoder encoder) {
126 if (element.enclosingClass != null) { 143 if (element.enclosingClass != null) {
127 encoder.setElement(Key.CLASS, element.enclosingClass); 144 encoder.setElement(Key.CLASS, element.enclosingClass);
128 if (element.enclosingClass.declaration.compilationUnit != 145 if (element.enclosingClass.declaration.compilationUnit !=
129 element.compilationUnit) { 146 element.compilationUnit) {
130 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); 147 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
131 } 148 }
132 } else { 149 } else {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 235 }
219 236
220 static List<Element> getExportedElements(LibraryElement element) { 237 static List<Element> getExportedElements(LibraryElement element) {
221 Set<Element> exportedElements = new Set<Element>(); 238 Set<Element> exportedElements = new Set<Element>();
222 element.forEachExport(SerializerUtil.flattenElements(exportedElements)); 239 element.forEachExport(SerializerUtil.flattenElements(exportedElements));
223 return exportedElements.toList(); 240 return exportedElements.toList();
224 } 241 }
225 242
226 void serialize(LibraryElement element, ObjectEncoder encoder, 243 void serialize(LibraryElement element, ObjectEncoder encoder,
227 SerializedElementKind kind) { 244 SerializedElementKind kind) {
245 SerializerUtil.serializeMetadata(element, encoder);
228 encoder.setUri( 246 encoder.setUri(
229 Key.CANONICAL_URI, element.canonicalUri, element.canonicalUri); 247 Key.CANONICAL_URI, element.canonicalUri, element.canonicalUri);
230 encoder.setString(Key.LIBRARY_NAME, element.libraryName); 248 encoder.setString(Key.LIBRARY_NAME, element.libraryName);
231 SerializerUtil.serializeMembers(getMembers(element), encoder); 249 SerializerUtil.serializeMembers(getMembers(element), encoder);
232 encoder.setElement(Key.COMPILATION_UNIT, element.entryCompilationUnit); 250 encoder.setElement(Key.COMPILATION_UNIT, element.entryCompilationUnit);
233 encoder.setElements(Key.COMPILATION_UNITS, getCompilationUnits(element)); 251 encoder.setElements(Key.COMPILATION_UNITS, getCompilationUnits(element));
234 encoder.setElements(Key.IMPORTS, getImports(element)); 252 encoder.setElements(Key.IMPORTS, getImports(element));
235 encoder.setElements(Key.EXPORTS, element.exports); 253 encoder.setElements(Key.EXPORTS, element.exports);
236 254
237 encoder.setElements(Key.IMPORT_SCOPE, getImportedElements(element)); 255 encoder.setElements(Key.IMPORT_SCOPE, getImportedElements(element));
238 256
239 encoder.setElements(Key.EXPORT_SCOPE, getExportedElements(element)); 257 encoder.setElements(Key.EXPORT_SCOPE, getExportedElements(element));
240 } 258 }
241 } 259 }
242 260
243 class CompilationUnitSerializer implements ElementSerializer { 261 class CompilationUnitSerializer implements ElementSerializer {
244 const CompilationUnitSerializer(); 262 const CompilationUnitSerializer();
245 263
246 SerializedElementKind getSerializedKind(Element element) { 264 SerializedElementKind getSerializedKind(Element element) {
247 if (element.isCompilationUnit) { 265 if (element.isCompilationUnit) {
248 return SerializedElementKind.COMPILATION_UNIT; 266 return SerializedElementKind.COMPILATION_UNIT;
249 } 267 }
250 return null; 268 return null;
251 } 269 }
252 270
253 void serialize(CompilationUnitElement element, ObjectEncoder encoder, 271 void serialize(CompilationUnitElement element, ObjectEncoder encoder,
254 SerializedElementKind kind) { 272 SerializedElementKind kind) {
273 SerializerUtil.serializeMetadata(element, encoder);
255 encoder.setElement(Key.LIBRARY, element.library); 274 encoder.setElement(Key.LIBRARY, element.library);
256 encoder.setUri( 275 encoder.setUri(
257 Key.URI, element.library.canonicalUri, element.script.resourceUri); 276 Key.URI, element.library.canonicalUri, element.script.resourceUri);
258 List<Element> elements = <Element>[]; 277 List<Element> elements = <Element>[];
259 element.forEachLocalMember((e) { 278 element.forEachLocalMember((e) {
260 if (!element.isPatch) { 279 if (!element.isPatch) {
261 elements.add(e); 280 elements.add(e);
262 } 281 }
263 }); 282 });
264 encoder.setElements(Key.ELEMENTS, elements); 283 encoder.setElements(Key.ELEMENTS, elements);
(...skipping 27 matching lines...) Expand all
292 if (!member.isPatch) { 311 if (!member.isPatch) {
293 members.add(member); 312 members.add(member);
294 } 313 }
295 }); 314 });
296 } 315 }
297 return members; 316 return members;
298 } 317 }
299 318
300 void serialize( 319 void serialize(
301 ClassElement element, ObjectEncoder encoder, SerializedElementKind kind) { 320 ClassElement element, ObjectEncoder encoder, SerializedElementKind kind) {
321 SerializerUtil.serializeMetadata(element, encoder);
302 encoder.setElement(Key.LIBRARY, element.library); 322 encoder.setElement(Key.LIBRARY, element.library);
303 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); 323 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
304 encoder.setString(Key.NAME, element.name); 324 encoder.setString(Key.NAME, element.name);
305 SerializerUtil.serializePosition(element, encoder); 325 SerializerUtil.serializePosition(element, encoder);
306 encoder.setTypes(Key.TYPE_VARIABLES, element.typeVariables); 326 encoder.setTypes(Key.TYPE_VARIABLES, element.typeVariables);
307 encoder.setBool(Key.IS_ABSTRACT, element.isAbstract); 327 encoder.setBool(Key.IS_ABSTRACT, element.isAbstract);
308 SerializerUtil.serializeMembers(getMembers(element), encoder); 328 SerializerUtil.serializeMembers(getMembers(element), encoder);
309 encoder.setBool(Key.IS_PROXY, element.isProxy); 329 encoder.setBool(Key.IS_PROXY, element.isProxy);
330 encoder.setBool(Key.IS_INJECTED, element.isInjected);
310 if (kind == SerializedElementKind.ENUM) { 331 if (kind == SerializedElementKind.ENUM) {
311 EnumClassElement enumClass = element; 332 EnumClassElement enumClass = element;
312 encoder.setElements(Key.FIELDS, enumClass.enumValues); 333 encoder.setElements(Key.FIELDS, enumClass.enumValues);
313 } 334 }
314 if (element.isObject) return; 335 if (element.isObject) return;
315 336
316 List<InterfaceType> mixins = <InterfaceType>[]; 337 List<InterfaceType> mixins = <InterfaceType>[];
317 ClassElement superclass = element.superclass; 338 ClassElement superclass = element.superclass;
318 while (superclass.isUnnamedMixinApplication) { 339 while (superclass.isUnnamedMixinApplication) {
319 MixinApplicationElement mixinElement = superclass; 340 MixinApplicationElement mixinElement = superclass;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 382 }
362 return null; 383 return null;
363 } 384 }
364 385
365 void serialize(ConstructorElement element, ObjectEncoder encoder, 386 void serialize(ConstructorElement element, ObjectEncoder encoder,
366 SerializedElementKind kind) { 387 SerializedElementKind kind) {
367 SerializerUtil.serializeParentRelation(element, encoder); 388 SerializerUtil.serializeParentRelation(element, encoder);
368 if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) { 389 if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) {
369 encoder.setElement(Key.ELEMENT, element.definingConstructor); 390 encoder.setElement(Key.ELEMENT, element.definingConstructor);
370 } else { 391 } else {
392 SerializerUtil.serializeMetadata(element, encoder);
371 encoder.setType(Key.TYPE, element.type); 393 encoder.setType(Key.TYPE, element.type);
372 encoder.setString(Key.NAME, element.name); 394 encoder.setString(Key.NAME, element.name);
373 SerializerUtil.serializePosition(element, encoder); 395 SerializerUtil.serializePosition(element, encoder);
374 SerializerUtil.serializeParameters(element, encoder); 396 SerializerUtil.serializeParameters(element, encoder);
375 encoder.setBool(Key.IS_CONST, element.isConst); 397 encoder.setBool(Key.IS_CONST, element.isConst);
376 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); 398 encoder.setBool(Key.IS_EXTERNAL, element.isExternal);
399 encoder.setBool(Key.IS_INJECTED, element.isInjected);
377 if (element.isConst && !element.isFromEnvironmentConstructor) { 400 if (element.isConst && !element.isFromEnvironmentConstructor) {
378 ConstantConstructor constantConstructor = element.constantConstructor; 401 ConstantConstructor constantConstructor = element.constantConstructor;
379 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); 402 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR);
380 const ConstantConstructorSerializer() 403 const ConstantConstructorSerializer()
381 .visit(constantConstructor, constantEncoder); 404 .visit(constantConstructor, constantEncoder);
382 } 405 }
383 if (kind == SerializedElementKind.GENERATIVE_CONSTRUCTOR) { 406 if (kind == SerializedElementKind.GENERATIVE_CONSTRUCTOR) {
384 encoder.setBool(Key.IS_REDIRECTING, element.isRedirectingGenerative); 407 encoder.setBool(Key.IS_REDIRECTING, element.isRedirectingGenerative);
385 } 408 }
386 encoder.setElement(Key.EFFECTIVE_TARGET, element.effectiveTarget); 409 encoder.setElement(Key.EFFECTIVE_TARGET, element.effectiveTarget);
(...skipping 25 matching lines...) Expand all
412 return SerializedElementKind.STATIC_FIELD; 435 return SerializedElementKind.STATIC_FIELD;
413 } 436 }
414 if (element.isInstanceMember) return SerializedElementKind.INSTANCE_FIELD; 437 if (element.isInstanceMember) return SerializedElementKind.INSTANCE_FIELD;
415 } 438 }
416 return null; 439 return null;
417 } 440 }
418 441
419 void serialize( 442 void serialize(
420 FieldElement element, ObjectEncoder encoder, SerializedElementKind kind) { 443 FieldElement element, ObjectEncoder encoder, SerializedElementKind kind) {
421 encoder.setString(Key.NAME, element.name); 444 encoder.setString(Key.NAME, element.name);
445 SerializerUtil.serializeMetadata(element, encoder);
422 SerializerUtil.serializePosition(element, encoder); 446 SerializerUtil.serializePosition(element, encoder);
423 encoder.setType(Key.TYPE, element.type); 447 encoder.setType(Key.TYPE, element.type);
424 encoder.setBool(Key.IS_FINAL, element.isFinal); 448 encoder.setBool(Key.IS_FINAL, element.isFinal);
425 encoder.setBool(Key.IS_CONST, element.isConst); 449 encoder.setBool(Key.IS_CONST, element.isConst);
450 encoder.setBool(Key.IS_INJECTED, element.isInjected);
426 ConstantExpression constant = element.constant; 451 ConstantExpression constant = element.constant;
427 if (constant != null) { 452 if (constant != null) {
428 encoder.setConstant(Key.CONSTANT, constant); 453 encoder.setConstant(Key.CONSTANT, constant);
429 } 454 }
430 SerializerUtil.serializeParentRelation(element, encoder); 455 SerializerUtil.serializeParentRelation(element, encoder);
431 if (element is EnumConstantElement) { 456 if (element is EnumConstantElement) {
432 EnumConstantElement enumConstant = element; 457 EnumConstantElement enumConstant = element;
433 encoder.setInt(Key.INDEX, enumConstant.index); 458 encoder.setInt(Key.INDEX, enumConstant.index);
434 } 459 }
435 } 460 }
(...skipping 26 matching lines...) Expand all
462 if (element.isInstanceMember) { 487 if (element.isInstanceMember) {
463 return SerializedElementKind.INSTANCE_SETTER; 488 return SerializedElementKind.INSTANCE_SETTER;
464 } 489 }
465 } 490 }
466 return null; 491 return null;
467 } 492 }
468 493
469 void serialize(FunctionElement element, ObjectEncoder encoder, 494 void serialize(FunctionElement element, ObjectEncoder encoder,
470 SerializedElementKind kind) { 495 SerializedElementKind kind) {
471 encoder.setString(Key.NAME, element.name); 496 encoder.setString(Key.NAME, element.name);
497 SerializerUtil.serializeMetadata(element, encoder);
472 SerializerUtil.serializePosition(element, encoder); 498 SerializerUtil.serializePosition(element, encoder);
473 SerializerUtil.serializeParameters(element, encoder); 499 SerializerUtil.serializeParameters(element, encoder);
474 encoder.setType(Key.TYPE, element.type); 500 encoder.setType(Key.TYPE, element.type);
475 if (element.isFunction) { 501 if (element.isFunction) {
476 encoder.setBool(Key.IS_OPERATOR, element.isOperator); 502 encoder.setBool(Key.IS_OPERATOR, element.isOperator);
477 encoder.setEnum(Key.ASYNC_MARKER, element.asyncMarker); 503 encoder.setEnum(Key.ASYNC_MARKER, element.asyncMarker);
478 } 504 }
479 SerializerUtil.serializeParentRelation(element, encoder); 505 SerializerUtil.serializeParentRelation(element, encoder);
480 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); 506 encoder.setBool(Key.IS_EXTERNAL, element.isExternal);
481 encoder.setBool(Key.IS_ABSTRACT, element.isAbstract); 507 encoder.setBool(Key.IS_ABSTRACT, element.isAbstract);
508 encoder.setBool(Key.IS_INJECTED, element.isInjected);
482 if (element.isLocal) { 509 if (element.isLocal) {
483 LocalFunctionElement localFunction = element; 510 LocalFunctionElement localFunction = element;
484 encoder.setElement( 511 encoder.setElement(
485 Key.EXECUTABLE_CONTEXT, localFunction.executableContext); 512 Key.EXECUTABLE_CONTEXT, localFunction.executableContext);
486 } 513 }
487 } 514 }
488 } 515 }
489 516
490 class TypedefSerializer implements ElementSerializer { 517 class TypedefSerializer implements ElementSerializer {
491 const TypedefSerializer(); 518 const TypedefSerializer();
492 519
493 SerializedElementKind getSerializedKind(Element element) { 520 SerializedElementKind getSerializedKind(Element element) {
494 if (element.isTypedef) { 521 if (element.isTypedef) {
495 return SerializedElementKind.TYPEDEF; 522 return SerializedElementKind.TYPEDEF;
496 } 523 }
497 return null; 524 return null;
498 } 525 }
499 526
500 void serialize(TypedefElement element, ObjectEncoder encoder, 527 void serialize(TypedefElement element, ObjectEncoder encoder,
501 SerializedElementKind kind) { 528 SerializedElementKind kind) {
502 encoder.setString(Key.NAME, element.name); 529 encoder.setString(Key.NAME, element.name);
530 SerializerUtil.serializeMetadata(element, encoder);
503 SerializerUtil.serializePosition(element, encoder); 531 SerializerUtil.serializePosition(element, encoder);
504 encoder.setType(Key.ALIAS, element.alias); 532 encoder.setType(Key.ALIAS, element.alias);
505 encoder.setElement(Key.LIBRARY, element.library); 533 encoder.setElement(Key.LIBRARY, element.library);
506 encoder.setTypes(Key.TYPE_VARIABLES, element.typeVariables); 534 encoder.setTypes(Key.TYPE_VARIABLES, element.typeVariables);
507 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); 535 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
508 } 536 }
509 } 537 }
510 538
511 class TypeVariableSerializer implements ElementSerializer { 539 class TypeVariableSerializer implements ElementSerializer {
512 const TypeVariableSerializer(); 540 const TypeVariableSerializer();
513 541
514 SerializedElementKind getSerializedKind(Element element) { 542 SerializedElementKind getSerializedKind(Element element) {
515 if (element.isTypeVariable) { 543 if (element.isTypeVariable) {
516 return SerializedElementKind.TYPEVARIABLE; 544 return SerializedElementKind.TYPEVARIABLE;
517 } 545 }
518 return null; 546 return null;
519 } 547 }
520 548
521 void serialize(TypeVariableElement element, ObjectEncoder encoder, 549 void serialize(TypeVariableElement element, ObjectEncoder encoder,
522 SerializedElementKind kind) { 550 SerializedElementKind kind) {
523 encoder.setElement(Key.TYPE_DECLARATION, element.typeDeclaration); 551 encoder.setElement(Key.TYPE_DECLARATION, element.typeDeclaration);
524 encoder.setString(Key.NAME, element.name); 552 encoder.setString(Key.NAME, element.name);
553 SerializerUtil.serializeMetadata(element, encoder);
525 SerializerUtil.serializePosition(element, encoder); 554 SerializerUtil.serializePosition(element, encoder);
526 encoder.setType(Key.TYPE, element.type); 555 encoder.setType(Key.TYPE, element.type);
527 encoder.setInt(Key.INDEX, element.index); 556 encoder.setInt(Key.INDEX, element.index);
528 encoder.setType(Key.BOUND, element.bound); 557 encoder.setType(Key.BOUND, element.bound);
529 } 558 }
530 } 559 }
531 560
532 class ParameterSerializer implements ElementSerializer { 561 class ParameterSerializer implements ElementSerializer {
533 const ParameterSerializer(); 562 const ParameterSerializer();
534 563
535 SerializedElementKind getSerializedKind(Element element) { 564 SerializedElementKind getSerializedKind(Element element) {
536 if (element.isParameter) { 565 if (element.isParameter) {
537 return SerializedElementKind.PARAMETER; 566 return SerializedElementKind.PARAMETER;
538 } else if (element.isInitializingFormal) { 567 } else if (element.isInitializingFormal) {
539 return SerializedElementKind.INITIALIZING_FORMAL; 568 return SerializedElementKind.INITIALIZING_FORMAL;
540 } 569 }
541 return null; 570 return null;
542 } 571 }
543 572
544 void serialize(ParameterElement element, ObjectEncoder encoder, 573 void serialize(ParameterElement element, ObjectEncoder encoder,
545 SerializedElementKind kind) { 574 SerializedElementKind kind) {
546 encoder.setElement(Key.FUNCTION, element.functionDeclaration); 575 encoder.setElement(Key.FUNCTION, element.functionDeclaration);
547 encoder.setString(Key.NAME, element.name); 576 encoder.setString(Key.NAME, element.name);
577 SerializerUtil.serializeMetadata(element, encoder);
548 SerializerUtil.serializePosition(element, encoder); 578 SerializerUtil.serializePosition(element, encoder);
549 encoder.setType(Key.TYPE, element.type); 579 encoder.setType(Key.TYPE, element.type);
550 encoder.setBool(Key.IS_OPTIONAL, element.isOptional); 580 encoder.setBool(Key.IS_OPTIONAL, element.isOptional);
551 encoder.setBool(Key.IS_NAMED, element.isNamed); 581 encoder.setBool(Key.IS_NAMED, element.isNamed);
552 encoder.setBool(Key.IS_FINAL, element.isFinal); 582 encoder.setBool(Key.IS_FINAL, element.isFinal);
553 if (element.isOptional) { 583 if (element.isOptional) {
554 encoder.setConstant(Key.CONSTANT, element.constant); 584 encoder.setConstant(Key.CONSTANT, element.constant);
555 } 585 }
556 if (element.isInitializingFormal) { 586 if (element.isInitializingFormal) {
557 InitializingFormalElement initializingFormal = element; 587 InitializingFormalElement initializingFormal = element;
558 encoder.setElement(Key.FIELD, initializingFormal.fieldElement); 588 encoder.setElement(Key.FIELD, initializingFormal.fieldElement);
559 } 589 }
560 } 590 }
561 } 591 }
562 592
563 class LocalVariableSerializer implements ElementSerializer { 593 class LocalVariableSerializer implements ElementSerializer {
564 const LocalVariableSerializer(); 594 const LocalVariableSerializer();
565 595
566 SerializedElementKind getSerializedKind(Element element) { 596 SerializedElementKind getSerializedKind(Element element) {
567 if (element.isVariable) { 597 if (element.isVariable) {
568 return SerializedElementKind.LOCAL_VARIABLE; 598 return SerializedElementKind.LOCAL_VARIABLE;
569 } 599 }
570 return null; 600 return null;
571 } 601 }
572 602
573 void serialize(LocalVariableElement element, ObjectEncoder encoder, 603 void serialize(LocalVariableElement element, ObjectEncoder encoder,
574 SerializedElementKind kind) { 604 SerializedElementKind kind) {
575 encoder.setString(Key.NAME, element.name); 605 encoder.setString(Key.NAME, element.name);
606 SerializerUtil.serializeMetadata(element, encoder);
576 SerializerUtil.serializePosition(element, encoder); 607 SerializerUtil.serializePosition(element, encoder);
577 encoder.setType(Key.TYPE, element.type); 608 encoder.setType(Key.TYPE, element.type);
578 encoder.setBool(Key.IS_FINAL, element.isFinal); 609 encoder.setBool(Key.IS_FINAL, element.isFinal);
579 encoder.setBool(Key.IS_CONST, element.isConst); 610 encoder.setBool(Key.IS_CONST, element.isConst);
580 if (element.isConst) { 611 if (element.isConst) {
581 ConstantExpression constant = element.constant; 612 ConstantExpression constant = element.constant;
582 encoder.setConstant(Key.CONSTANT, constant); 613 encoder.setConstant(Key.CONSTANT, constant);
583 } 614 }
584 encoder.setElement(Key.EXECUTABLE_CONTEXT, element.executableContext); 615 encoder.setElement(Key.EXECUTABLE_CONTEXT, element.executableContext);
585 } 616 }
586 } 617 }
587 618
588 class ImportSerializer implements ElementSerializer { 619 class ImportSerializer implements ElementSerializer {
589 const ImportSerializer(); 620 const ImportSerializer();
590 621
591 SerializedElementKind getSerializedKind(Element element) { 622 SerializedElementKind getSerializedKind(Element element) {
592 if (element.isImport) { 623 if (element.isImport) {
593 return SerializedElementKind.IMPORT; 624 return SerializedElementKind.IMPORT;
594 } 625 }
595 return null; 626 return null;
596 } 627 }
597 628
598 void serialize(ImportElement element, ObjectEncoder encoder, 629 void serialize(ImportElement element, ObjectEncoder encoder,
599 SerializedElementKind kind) { 630 SerializedElementKind kind) {
631 SerializerUtil.serializeMetadata(element, encoder);
600 encoder.setElement(Key.LIBRARY, element.library); 632 encoder.setElement(Key.LIBRARY, element.library);
601 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); 633 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
602 encoder.setElement(Key.LIBRARY_DEPENDENCY, element.importedLibrary); 634 encoder.setElement(Key.LIBRARY_DEPENDENCY, element.importedLibrary);
603 if (element.prefix != null) { 635 if (element.prefix != null) {
604 encoder.setElement(Key.PREFIX, element.prefix); 636 encoder.setElement(Key.PREFIX, element.prefix);
605 } 637 }
606 encoder.setBool(Key.IS_DEFERRED, element.isDeferred); 638 encoder.setBool(Key.IS_DEFERRED, element.isDeferred);
607 // TODO(johnniwinther): What is the base for the URI? 639 // TODO(johnniwinther): What is the base for the URI?
608 encoder.setUri(Key.URI, element.uri, element.uri); 640 encoder.setUri(Key.URI, element.uri, element.uri);
609 } 641 }
610 } 642 }
611 643
612 class ExportSerializer implements ElementSerializer { 644 class ExportSerializer implements ElementSerializer {
613 const ExportSerializer(); 645 const ExportSerializer();
614 646
615 SerializedElementKind getSerializedKind(Element element) { 647 SerializedElementKind getSerializedKind(Element element) {
616 if (element.isExport) { 648 if (element.isExport) {
617 return SerializedElementKind.EXPORT; 649 return SerializedElementKind.EXPORT;
618 } 650 }
619 return null; 651 return null;
620 } 652 }
621 653
622 void serialize(ExportElement element, ObjectEncoder encoder, 654 void serialize(ExportElement element, ObjectEncoder encoder,
623 SerializedElementKind kind) { 655 SerializedElementKind kind) {
656 SerializerUtil.serializeMetadata(element, encoder);
624 encoder.setElement(Key.LIBRARY, element.library); 657 encoder.setElement(Key.LIBRARY, element.library);
625 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); 658 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
626 encoder.setElement(Key.LIBRARY_DEPENDENCY, element.exportedLibrary); 659 encoder.setElement(Key.LIBRARY_DEPENDENCY, element.exportedLibrary);
627 // TODO(johnniwinther): What is the base for the URI? 660 // TODO(johnniwinther): What is the base for the URI?
628 encoder.setUri(Key.URI, element.uri, element.uri); 661 encoder.setUri(Key.URI, element.uri, element.uri);
629 } 662 }
630 } 663 }
631 664
632 class PrefixSerializer implements ElementSerializer { 665 class PrefixSerializer implements ElementSerializer {
633 const PrefixSerializer(); 666 const PrefixSerializer();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 return new LocalVariableElementZ(decoder); 764 return new LocalVariableElementZ(decoder);
732 case SerializedElementKind.EXTERNAL_LIBRARY: 765 case SerializedElementKind.EXTERNAL_LIBRARY:
733 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: 766 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER:
734 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: 767 case SerializedElementKind.EXTERNAL_CLASS_MEMBER:
735 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: 768 case SerializedElementKind.EXTERNAL_CONSTRUCTOR:
736 break; 769 break;
737 } 770 }
738 throw new UnsupportedError("Unexpected element kind '${elementKind}."); 771 throw new UnsupportedError("Unexpected element kind '${elementKind}.");
739 } 772 }
740 } 773 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | pkg/compiler/lib/src/serialization/equivalence.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698