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