OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../compiler.dart' show Compiler; | 6 import '../compiler.dart' show Compiler; |
7 import '../constants/values.dart'; | 7 import '../constants/values.dart'; |
8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../io/code_output.dart'; | 10 import '../io/code_output.dart'; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 emittedArgumentCount != 4) || | 247 emittedArgumentCount != 4) || |
248 (className == JavaScriptMapConstant.DART_GENERAL_CLASS && | 248 (className == JavaScriptMapConstant.DART_GENERAL_CLASS && |
249 emittedArgumentCount != 1)) { | 249 emittedArgumentCount != 1)) { |
250 reporter.internalError(classElement, | 250 reporter.internalError(classElement, |
251 "Compiler and ${className} disagree on number of fields."); | 251 "Compiler and ${className} disagree on number of fields."); |
252 } | 252 } |
253 | 253 |
254 jsAst.Expression constructor = | 254 jsAst.Expression constructor = |
255 backend.emitter.constructorAccess(classElement); | 255 backend.emitter.constructorAccess(classElement); |
256 jsAst.Expression value = new jsAst.New(constructor, arguments); | 256 jsAst.Expression value = new jsAst.New(constructor, arguments); |
257 // Fix. Add an argument. | |
Siggi Cherem (dart-lang)
2016/08/19 16:39:46
did you indent to fix this one with this CL too?
| |
257 return maybeAddTypeArguments(constant.type, value); | 258 return maybeAddTypeArguments(constant.type, value); |
258 } | 259 } |
259 | 260 |
260 JavaScriptBackend get backend => compiler.backend; | 261 JavaScriptBackend get backend => compiler.backend; |
261 | 262 |
262 jsAst.PropertyAccess getHelperProperty(Element helper) { | 263 jsAst.PropertyAccess getHelperProperty(Element helper) { |
263 return backend.emitter.staticFunctionAccess(helper); | 264 return backend.emitter.staticFunctionAccess(helper); |
264 } | 265 } |
265 | 266 |
266 @override | 267 @override |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 StringConstantValue str = constant.fields.values.single; | 301 StringConstantValue str = constant.fields.values.single; |
301 String value = str.primitiveValue.slowToString(); | 302 String value = str.primitiveValue.slowToString(); |
302 return new jsAst.LiteralExpression(stripComments(value)); | 303 return new jsAst.LiteralExpression(stripComments(value)); |
303 } | 304 } |
304 jsAst.Expression constructor = | 305 jsAst.Expression constructor = |
305 backend.emitter.constructorAccess(constant.type.element); | 306 backend.emitter.constructorAccess(constant.type.element); |
306 List<jsAst.Expression> fields = <jsAst.Expression>[]; | 307 List<jsAst.Expression> fields = <jsAst.Expression>[]; |
307 element.forEachInstanceField((_, FieldElement field) { | 308 element.forEachInstanceField((_, FieldElement field) { |
308 fields.add(constantReferenceGenerator(constant.fields[field])); | 309 fields.add(constantReferenceGenerator(constant.fields[field])); |
309 }, includeSuperAndInjectedMembers: true); | 310 }, includeSuperAndInjectedMembers: true); |
311 if (backend.classNeedsRti(constant.type.element)) { | |
312 fields.add(_reifiedTypeArguments(constant.type)); | |
313 } | |
310 jsAst.New instantiation = new jsAst.New(constructor, fields); | 314 jsAst.New instantiation = new jsAst.New(constructor, fields); |
311 return maybeAddTypeArguments(constant.type, instantiation); | 315 return instantiation; |
312 } | 316 } |
313 | 317 |
314 String stripComments(String rawJavaScript) { | 318 String stripComments(String rawJavaScript) { |
315 return rawJavaScript.replaceAll(COMMENT_RE, ''); | 319 return rawJavaScript.replaceAll(COMMENT_RE, ''); |
316 } | 320 } |
317 | 321 |
318 jsAst.Expression maybeAddTypeArguments( | 322 jsAst.Expression maybeAddTypeArguments( |
319 InterfaceType type, jsAst.Expression value) { | 323 InterfaceType type, jsAst.Expression value) { |
320 if (type is InterfaceType && | 324 if (type is InterfaceType && |
321 !type.treatAsRaw && | 325 !type.treatAsRaw && |
322 backend.classNeedsRti(type.element)) { | 326 backend.classNeedsRti(type.element)) { |
323 InterfaceType interface = type; | |
324 RuntimeTypesEncoder rtiEncoder = backend.rtiEncoder; | |
325 Iterable<jsAst.Expression> arguments = interface.typeArguments.map( | |
326 (DartType type) => | |
327 rtiEncoder.getTypeRepresentationWithPlaceholders(type, (_) {})); | |
328 jsAst.Expression argumentList = | |
329 new jsAst.ArrayInitializer(arguments.toList()); | |
330 return new jsAst.Call( | 327 return new jsAst.Call( |
331 getHelperProperty(backend.helpers.setRuntimeTypeInfo), | 328 getHelperProperty(backend.helpers.setRuntimeTypeInfo), |
332 [value, argumentList]); | 329 [value, _reifiedTypeArguments(type)]); |
333 } | 330 } |
334 return value; | 331 return value; |
335 } | 332 } |
336 | 333 |
334 jsAst.Expression _reifiedTypeArguments(InterfaceType type) { | |
335 RuntimeTypesEncoder rtiEncoder = backend.rtiEncoder; | |
336 Iterable<jsAst.Expression> arguments = type.typeArguments.map( | |
337 (DartType type) => | |
338 rtiEncoder.getTypeRepresentationWithPlaceholders(type, (_) {})); | |
339 jsAst.Expression argumentList = | |
340 new jsAst.ArrayInitializer(arguments.toList()); | |
341 return argumentList; | |
342 } | |
343 | |
337 @override | 344 @override |
338 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { | 345 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { |
339 return constantReferenceGenerator(constant.referenced); | 346 return constantReferenceGenerator(constant.referenced); |
340 } | 347 } |
341 } | 348 } |
OLD | NEW |