Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.js_emitter.metadata_collector; | 5 library dart2js.js_emitter.metadata_collector; |
| 6 | 6 |
| 7 import 'package:js_ast/src/precedence.dart' as js_precedence; | 7 import 'package:js_ast/src/precedence.dart' as js_precedence; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| 11 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit; | 11 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit; |
| 12 import '../elements/elements.dart' | 12 import '../elements/elements.dart' |
| 13 show | 13 show |
| 14 ClassElement, | 14 ClassElement, |
| 15 ConstructorElement, | 15 ConstructorElement, |
| 16 Element, | 16 Element, |
| 17 FieldElement, | 17 FieldElement, |
| 18 FunctionSignature, | 18 FunctionSignature, |
| 19 LibraryElement, | 19 LibraryElement, |
| 20 MemberElement, | 20 MemberElement, |
| 21 MethodElement, | 21 MethodElement, |
| 22 MetadataAnnotation, | 22 MetadataAnnotation, |
| 23 ParameterElement; | 23 ParameterElement; |
| 24 import '../elements/entities.dart'; | 24 import '../elements/entities.dart'; |
| 25 import '../elements/resolution_types.dart' | 25 import '../elements/resolution_types.dart' |
| 26 show ResolutionDartType, ResolutionTypedefType; | 26 show ResolutionDartType, ResolutionTypedefType; |
|
Emily Fortuna
2017/08/02 17:49:55
you can remove ResolutionDartType here then.
Johnni Winther
2017/08/03 08:58:34
Done.
| |
| 27 import '../elements/types.dart'; | 27 import '../elements/types.dart'; |
| 28 import '../js/js.dart' as jsAst; | 28 import '../js/js.dart' as jsAst; |
| 29 import '../js/js.dart' show js; | 29 import '../js/js.dart' show js; |
| 30 import '../js_backend/constant_handler_javascript.dart'; | 30 import '../js_backend/constant_handler_javascript.dart'; |
| 31 import '../js_backend/mirrors_data.dart'; | 31 import '../js_backend/mirrors_data.dart'; |
| 32 import '../js_backend/runtime_types.dart' show RuntimeTypesEncoder; | 32 import '../js_backend/runtime_types.dart' show RuntimeTypesEncoder; |
| 33 import '../js_backend/type_variable_handler.dart' | 33 import '../js_backend/type_variable_handler.dart' |
| 34 show TypeVariableCodegenAnalysis; | 34 show TypeVariableCodegenAnalysis; |
| 35 import '../options.dart'; | 35 import '../options.dart'; |
| 36 | 36 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 /// output unit. Once finalized, the entries represent types including | 160 /// output unit. Once finalized, the entries represent types including |
| 161 /// function types and typedefs. | 161 /// function types and typedefs. |
| 162 Map<OutputUnit, _MetadataList> _typesTokens = | 162 Map<OutputUnit, _MetadataList> _typesTokens = |
| 163 new Map<OutputUnit, _MetadataList>(); | 163 new Map<OutputUnit, _MetadataList>(); |
| 164 | 164 |
| 165 jsAst.Expression getTypesForOutputUnit(OutputUnit outputUnit) { | 165 jsAst.Expression getTypesForOutputUnit(OutputUnit outputUnit) { |
| 166 return _typesTokens.putIfAbsent(outputUnit, () => new _MetadataList()); | 166 return _typesTokens.putIfAbsent(outputUnit, () => new _MetadataList()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 /// A map used to canonicalize the entries of types. | 169 /// A map used to canonicalize the entries of types. |
| 170 Map<OutputUnit, Map<ResolutionDartType, _BoundMetadataEntry>> _typesMap = | 170 Map<OutputUnit, Map<DartType, _BoundMetadataEntry>> _typesMap = |
| 171 <OutputUnit, Map<ResolutionDartType, _BoundMetadataEntry>>{}; | 171 <OutputUnit, Map<DartType, _BoundMetadataEntry>>{}; |
| 172 | 172 |
| 173 MetadataCollector( | 173 MetadataCollector( |
| 174 this._options, | 174 this._options, |
| 175 this.reporter, | 175 this.reporter, |
| 176 this._deferredLoadTask, | 176 this._deferredLoadTask, |
| 177 this._emitter, | 177 this._emitter, |
| 178 this._constants, | 178 this._constants, |
| 179 this._typeVariableCodegenAnalysis, | 179 this._typeVariableCodegenAnalysis, |
| 180 this._mirrorsData, | 180 this._mirrorsData, |
| 181 this._rtiEncoder) { | 181 this._rtiEncoder) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 return null; | 326 return null; |
| 327 } | 327 } |
| 328 return _addGlobalMetadata(_emitter.constantReference(constant)); | 328 return _addGlobalMetadata(_emitter.constantReference(constant)); |
| 329 } | 329 } |
| 330 | 330 |
| 331 jsAst.Expression reifyType(DartType type, {ignoreTypeVariables: false}) { | 331 jsAst.Expression reifyType(DartType type, {ignoreTypeVariables: false}) { |
| 332 return reifyTypeForOutputUnit(type, _deferredLoadTask.mainOutputUnit, | 332 return reifyTypeForOutputUnit(type, _deferredLoadTask.mainOutputUnit, |
| 333 ignoreTypeVariables: ignoreTypeVariables); | 333 ignoreTypeVariables: ignoreTypeVariables); |
| 334 } | 334 } |
| 335 | 335 |
| 336 jsAst.Expression reifyTypeForOutputUnit( | 336 jsAst.Expression reifyTypeForOutputUnit(DartType type, OutputUnit outputUnit, |
| 337 ResolutionDartType type, OutputUnit outputUnit, | |
| 338 {ignoreTypeVariables: false}) { | 337 {ignoreTypeVariables: false}) { |
| 339 return addTypeInOutputUnit(type, outputUnit, | 338 return addTypeInOutputUnit(type, outputUnit, |
| 340 ignoreTypeVariables: ignoreTypeVariables); | 339 ignoreTypeVariables: ignoreTypeVariables); |
| 341 } | 340 } |
| 342 | 341 |
| 343 jsAst.Expression reifyName(String name) { | 342 jsAst.Expression reifyName(String name) { |
| 344 return _addGlobalMetadata(js.string(name)); | 343 return _addGlobalMetadata(js.string(name)); |
| 345 } | 344 } |
| 346 | 345 |
| 347 jsAst.Expression reifyExpression(jsAst.Expression expression) { | 346 jsAst.Expression reifyExpression(jsAst.Expression expression) { |
| 348 return _addGlobalMetadata(expression); | 347 return _addGlobalMetadata(expression); |
| 349 } | 348 } |
| 350 | 349 |
| 351 Placeholder getMetadataPlaceholder([debug]) { | 350 Placeholder getMetadataPlaceholder([debug]) { |
| 352 return new _ForwardingMetadataEntry(debug); | 351 return new _ForwardingMetadataEntry(debug); |
| 353 } | 352 } |
| 354 | 353 |
| 355 _MetadataEntry _addGlobalMetadata(jsAst.Node node) { | 354 _MetadataEntry _addGlobalMetadata(jsAst.Node node) { |
| 356 String nameToKey(jsAst.Name name) => "${name.key}"; | 355 String nameToKey(jsAst.Name name) => "${name.key}"; |
| 357 String printed = | 356 String printed = |
| 358 jsAst.prettyPrint(node, _options, renamerForNames: nameToKey); | 357 jsAst.prettyPrint(node, _options, renamerForNames: nameToKey); |
| 359 return _globalMetadataMap.putIfAbsent(printed, () { | 358 return _globalMetadataMap.putIfAbsent(printed, () { |
| 360 return new _BoundMetadataEntry(node); | 359 return new _BoundMetadataEntry(node); |
| 361 }); | 360 }); |
| 362 } | 361 } |
| 363 | 362 |
| 364 jsAst.Expression _computeTypeRepresentation(ResolutionDartType type, | 363 jsAst.Expression _computeTypeRepresentation(DartType type, |
| 365 {ignoreTypeVariables: false}) { | 364 {ignoreTypeVariables: false}) { |
| 366 jsAst.Expression representation = | 365 jsAst.Expression representation = |
| 367 _rtiEncoder.getTypeRepresentation(_emitter, type, (variable) { | 366 _rtiEncoder.getTypeRepresentation(_emitter, type, (variable) { |
| 368 if (ignoreTypeVariables) return new jsAst.LiteralNull(); | 367 if (ignoreTypeVariables) return new jsAst.LiteralNull(); |
| 369 return _typeVariableCodegenAnalysis.reifyTypeVariable(variable.element); | 368 return _typeVariableCodegenAnalysis.reifyTypeVariable(variable.element); |
| 370 }, (ResolutionTypedefType typedef) { | 369 }, (ResolutionTypedefType typedef) { |
| 371 return _mirrorsData.isTypedefAccessibleByReflection(typedef.element); | 370 return _mirrorsData.isTypedefAccessibleByReflection(typedef.element); |
| 372 }); | 371 }); |
| 373 | 372 |
| 374 if (representation is jsAst.LiteralString) { | 373 if (representation is jsAst.LiteralString) { |
| 375 // We don't want the representation to be a string, since we use | 374 // We don't want the representation to be a string, since we use |
| 376 // strings as indicator for non-initialized types in the lazy emitter. | 375 // strings as indicator for non-initialized types in the lazy emitter. |
| 377 reporter.internalError( | 376 reporter.internalError( |
| 378 NO_LOCATION_SPANNABLE, 'reified types should not be strings.'); | 377 NO_LOCATION_SPANNABLE, 'reified types should not be strings.'); |
| 379 } | 378 } |
| 380 | 379 |
| 381 return representation; | 380 return representation; |
| 382 } | 381 } |
| 383 | 382 |
| 384 jsAst.Expression addTypeInOutputUnit( | 383 jsAst.Expression addTypeInOutputUnit(DartType type, OutputUnit outputUnit, |
| 385 ResolutionDartType type, OutputUnit outputUnit, | |
| 386 {ignoreTypeVariables: false}) { | 384 {ignoreTypeVariables: false}) { |
| 387 if (_typesMap[outputUnit] == null) { | 385 if (_typesMap[outputUnit] == null) { |
| 388 _typesMap[outputUnit] = | 386 _typesMap[outputUnit] = new Map<DartType, _BoundMetadataEntry>(); |
| 389 new Map<ResolutionDartType, _BoundMetadataEntry>(); | |
| 390 } | 387 } |
| 391 return _typesMap[outputUnit].putIfAbsent(type, () { | 388 return _typesMap[outputUnit].putIfAbsent(type, () { |
| 392 return new _BoundMetadataEntry(_computeTypeRepresentation(type, | 389 return new _BoundMetadataEntry(_computeTypeRepresentation(type, |
| 393 ignoreTypeVariables: ignoreTypeVariables)); | 390 ignoreTypeVariables: ignoreTypeVariables)); |
| 394 }); | 391 }); |
| 395 } | 392 } |
| 396 | 393 |
| 397 List<jsAst.DeferredNumber> computeMetadata(MethodElement element) { | 394 List<jsAst.DeferredNumber> computeMetadata(MethodElement element) { |
| 398 return reporter.withCurrentElement(element, () { | 395 return reporter.withCurrentElement(element, () { |
| 399 if (!_mustEmitMetadataForMember(element)) | 396 if (!_mustEmitMetadataForMember(element)) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 if (token is _ForwardingMetadataEntry && !token.isBound) { | 468 if (token is _ForwardingMetadataEntry && !token.isBound) { |
| 472 _foundUnboundToken = true; | 469 _foundUnboundToken = true; |
| 473 } | 470 } |
| 474 } | 471 } |
| 475 | 472 |
| 476 bool findUnboundPlaceholders(jsAst.Node node) { | 473 bool findUnboundPlaceholders(jsAst.Node node) { |
| 477 node.accept(this); | 474 node.accept(this); |
| 478 return _foundUnboundToken; | 475 return _foundUnboundToken; |
| 479 } | 476 } |
| 480 } | 477 } |
| OLD | NEW |