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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 mapEncoder.setElement(name, member); | 99 mapEncoder.setElement(name, member); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 /// Serialize the source position of [element] into [encoder]. | 103 /// Serialize the source position of [element] into [encoder]. |
104 static void serializePosition(Element element, ObjectEncoder encoder) { | 104 static void serializePosition(Element element, ObjectEncoder encoder) { |
105 if (element.sourcePosition != null) { | 105 if (element.sourcePosition != null) { |
106 SourceSpan position = element.sourcePosition; | 106 SourceSpan position = element.sourcePosition; |
107 encoder.setInt(Key.OFFSET, position.begin); | 107 encoder.setInt(Key.OFFSET, position.begin); |
| 108 // TODO(johnniwinther): What is the base URI in the case? |
108 if (position.uri != element.compilationUnit.script.resourceUri) { | 109 if (position.uri != element.compilationUnit.script.resourceUri) { |
109 // TODO(johnniwinther): What is the base URI in the case? | |
110 encoder.setUri(Key.URI, element.library.canonicalUri, position.uri); | 110 encoder.setUri(Key.URI, element.library.canonicalUri, position.uri); |
111 } | 111 } |
112 int length = position.end - position.begin; | 112 int length = position.end - position.begin; |
113 if (element.name.length != length) { | 113 if (element.name.length != length) { |
114 encoder.setInt(Key.LENGTH, length); | 114 encoder.setInt(Key.LENGTH, length); |
115 } | 115 } |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
| 119 /// Serialize the parent relation for [element] into [encoder], i.e library, |
| 120 /// enclosing class, and compilation unit references. |
| 121 static void serializeParentRelation(Element element, ObjectEncoder encoder) { |
| 122 if (element.enclosingClass != null) { |
| 123 encoder.setElement(Key.CLASS, element.enclosingClass); |
| 124 if (element.enclosingClass.declaration.compilationUnit != |
| 125 element.compilationUnit) { |
| 126 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); |
| 127 } |
| 128 } else { |
| 129 encoder.setElement(Key.LIBRARY, element.library); |
| 130 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); |
| 131 } |
| 132 } |
| 133 |
119 /// Serialize the parameters of [element] into [encoder]. | 134 /// Serialize the parameters of [element] into [encoder]. |
120 static void serializeParameters( | 135 static void serializeParameters( |
121 FunctionElement element, ObjectEncoder encoder) { | 136 FunctionElement element, ObjectEncoder encoder) { |
122 FunctionType type = element.type; | 137 FunctionType type = element.type; |
123 encoder.setType(Key.RETURN_TYPE, type.returnType); | 138 encoder.setType(Key.RETURN_TYPE, type.returnType); |
124 encoder.setElements(Key.PARAMETERS, element.parameters); | 139 encoder.setElements(Key.PARAMETERS, element.parameters); |
125 } | 140 } |
126 | 141 |
127 /// Returns a function that adds the underlying declared elements for a | 142 /// Returns a function that adds the underlying declared elements for a |
128 /// particular element into [set]. | 143 /// particular element into [set]. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 if (element.isGenerativeConstructor) { | 341 if (element.isGenerativeConstructor) { |
327 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; | 342 return SerializedElementKind.GENERATIVE_CONSTRUCTOR; |
328 } else if (element.isFactoryConstructor) { | 343 } else if (element.isFactoryConstructor) { |
329 return SerializedElementKind.FACTORY_CONSTRUCTOR; | 344 return SerializedElementKind.FACTORY_CONSTRUCTOR; |
330 } | 345 } |
331 return null; | 346 return null; |
332 } | 347 } |
333 | 348 |
334 void serialize(ConstructorElement element, ObjectEncoder encoder, | 349 void serialize(ConstructorElement element, ObjectEncoder encoder, |
335 SerializedElementKind kind) { | 350 SerializedElementKind kind) { |
336 encoder.setElement(Key.CLASS, element.enclosingClass); | 351 SerializerUtil.serializeParentRelation(element, encoder); |
337 encoder.setType(Key.TYPE, element.type); | 352 encoder.setType(Key.TYPE, element.type); |
338 encoder.setString(Key.NAME, element.name); | 353 encoder.setString(Key.NAME, element.name); |
339 SerializerUtil.serializePosition(element, encoder); | 354 SerializerUtil.serializePosition(element, encoder); |
340 SerializerUtil.serializeParameters(element, encoder); | 355 SerializerUtil.serializeParameters(element, encoder); |
341 encoder.setBool(Key.IS_CONST, element.isConst); | 356 encoder.setBool(Key.IS_CONST, element.isConst); |
342 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); | 357 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); |
343 if (element.isExternal) return; | 358 if (element.isExternal) return; |
344 if (element.isConst && !element.isFromEnvironmentConstructor) { | 359 if (element.isConst && !element.isFromEnvironmentConstructor) { |
345 ConstantConstructor constantConstructor = element.constantConstructor; | 360 ConstantConstructor constantConstructor = element.constantConstructor; |
346 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); | 361 ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR); |
(...skipping 24 matching lines...) Expand all Loading... |
371 FieldElement element, ObjectEncoder encoder, SerializedElementKind kind) { | 386 FieldElement element, ObjectEncoder encoder, SerializedElementKind kind) { |
372 encoder.setString(Key.NAME, element.name); | 387 encoder.setString(Key.NAME, element.name); |
373 SerializerUtil.serializePosition(element, encoder); | 388 SerializerUtil.serializePosition(element, encoder); |
374 encoder.setType(Key.TYPE, element.type); | 389 encoder.setType(Key.TYPE, element.type); |
375 encoder.setBool(Key.IS_FINAL, element.isFinal); | 390 encoder.setBool(Key.IS_FINAL, element.isFinal); |
376 encoder.setBool(Key.IS_CONST, element.isConst); | 391 encoder.setBool(Key.IS_CONST, element.isConst); |
377 if (element.isConst) { | 392 if (element.isConst) { |
378 ConstantExpression constant = element.constant; | 393 ConstantExpression constant = element.constant; |
379 encoder.setConstant(Key.CONSTANT, constant); | 394 encoder.setConstant(Key.CONSTANT, constant); |
380 } | 395 } |
381 if (kind != SerializedElementKind.TOPLEVEL_FIELD) { | 396 SerializerUtil.serializeParentRelation(element, encoder); |
382 encoder.setElement(Key.CLASS, element.enclosingClass); | |
383 } else { | |
384 encoder.setElement(Key.LIBRARY, element.library); | |
385 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); | |
386 } | |
387 if (element is EnumConstantElement) { | 397 if (element is EnumConstantElement) { |
388 EnumConstantElement enumConstant = element; | 398 EnumConstantElement enumConstant = element; |
389 encoder.setInt(Key.INDEX, enumConstant.index); | 399 encoder.setInt(Key.INDEX, enumConstant.index); |
390 } | 400 } |
391 } | 401 } |
392 } | 402 } |
393 | 403 |
394 class FunctionSerializer implements ElementSerializer { | 404 class FunctionSerializer implements ElementSerializer { |
395 const FunctionSerializer(); | 405 const FunctionSerializer(); |
396 | 406 |
(...skipping 27 matching lines...) Expand all Loading... |
424 | 434 |
425 void serialize(FunctionElement element, ObjectEncoder encoder, | 435 void serialize(FunctionElement element, ObjectEncoder encoder, |
426 SerializedElementKind kind) { | 436 SerializedElementKind kind) { |
427 encoder.setString(Key.NAME, element.name); | 437 encoder.setString(Key.NAME, element.name); |
428 SerializerUtil.serializePosition(element, encoder); | 438 SerializerUtil.serializePosition(element, encoder); |
429 SerializerUtil.serializeParameters(element, encoder); | 439 SerializerUtil.serializeParameters(element, encoder); |
430 encoder.setType(Key.TYPE, element.type); | 440 encoder.setType(Key.TYPE, element.type); |
431 if (element.isFunction) { | 441 if (element.isFunction) { |
432 encoder.setBool(Key.IS_OPERATOR, element.isOperator); | 442 encoder.setBool(Key.IS_OPERATOR, element.isOperator); |
433 } | 443 } |
434 if (element.enclosingClass != null) { | 444 SerializerUtil.serializeParentRelation(element, encoder); |
435 encoder.setElement(Key.CLASS, element.enclosingClass); | |
436 } else { | |
437 encoder.setElement(Key.LIBRARY, element.library); | |
438 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); | |
439 } | |
440 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); | 445 encoder.setBool(Key.IS_EXTERNAL, element.isExternal); |
441 if (element.isLocal) { | 446 if (element.isLocal) { |
442 LocalFunctionElement localFunction = element; | 447 LocalFunctionElement localFunction = element; |
443 encoder.setElement( | 448 encoder.setElement( |
444 Key.EXECUTABLE_CONTEXT, localFunction.executableContext); | 449 Key.EXECUTABLE_CONTEXT, localFunction.executableContext); |
445 } | 450 } |
446 } | 451 } |
447 } | 452 } |
448 | 453 |
449 class TypedefSerializer implements ElementSerializer { | 454 class TypedefSerializer implements ElementSerializer { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 return new LocalVariableElementZ(decoder); | 687 return new LocalVariableElementZ(decoder); |
683 case SerializedElementKind.EXTERNAL_LIBRARY: | 688 case SerializedElementKind.EXTERNAL_LIBRARY: |
684 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: | 689 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: |
685 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: | 690 case SerializedElementKind.EXTERNAL_STATIC_MEMBER: |
686 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: | 691 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: |
687 break; | 692 break; |
688 } | 693 } |
689 throw new UnsupportedError("Unexpected element kind '${elementKind}."); | 694 throw new UnsupportedError("Unexpected element kind '${elementKind}."); |
690 } | 695 } |
691 } | 696 } |
OLD | NEW |