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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 class ConstantEmitter { | 7 class ConstantEmitter { |
8 ConstantReferenceEmitter _referenceEmitter; | 8 ConstantReferenceEmitter _referenceEmitter; |
9 ConstantInitializerEmitter _initializerEmitter; | 9 ConstantInitializerEmitter _initializerEmitter; |
10 | 10 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 arguments); | 293 arguments); |
294 } | 294 } |
295 | 295 |
296 js.Expression visitType(TypeConstant constant) { | 296 js.Expression visitType(TypeConstant constant) { |
297 SourceString helperSourceName = const SourceString('createRuntimeType'); | 297 SourceString helperSourceName = const SourceString('createRuntimeType'); |
298 Element helper = compiler.findHelper(helperSourceName); | 298 Element helper = compiler.findHelper(helperSourceName); |
299 JavaScriptBackend backend = compiler.backend; | 299 JavaScriptBackend backend = compiler.backend; |
300 String helperName = backend.namer.getName(helper); | 300 String helperName = backend.namer.getName(helper); |
301 DartType type = constant.representedType; | 301 DartType type = constant.representedType; |
302 Element element = type.element; | 302 Element element = type.element; |
303 String typeName; | 303 String name = backend.rti.getRawTypeRepresentation(type); |
304 if (type.kind == TypeKind.INTERFACE) { | 304 js.Expression typeName = new js.LiteralString("'$name'"); |
305 typeName = | |
306 backend.rti.getStringRepresentation(type, expandRawType: true); | |
307 } else { | |
308 assert(type.kind == TypeKind.TYPEDEF); | |
309 typeName = element.name.slowToString(); | |
310 } | |
311 return new js.Call( | 305 return new js.Call( |
312 new js.PropertyAccess.field( | 306 new js.PropertyAccess.field( |
313 new js.VariableUse(namer.CURRENT_ISOLATE), | 307 new js.VariableUse(namer.CURRENT_ISOLATE), |
314 helperName), | 308 helperName), |
315 [new js.LiteralString("'$typeName'")]); | 309 [typeName]); |
316 } | 310 } |
317 | 311 |
318 js.Expression visitConstructed(ConstructedConstant constant) { | 312 js.Expression visitConstructed(ConstructedConstant constant) { |
319 return new js.New( | 313 return new js.New( |
320 new js.VariableUse(getJsConstructor(constant.type.element)), | 314 new js.VariableUse(getJsConstructor(constant.type.element)), |
321 _array(constant.fields)); | 315 _array(constant.fields)); |
322 } | 316 } |
323 | 317 |
324 List<js.Expression> _array(List<Constant> values) { | 318 List<js.Expression> _array(List<Constant> values) { |
325 List<js.Expression> valueList = <js.Expression>[]; | 319 List<js.Expression> valueList = <js.Expression>[]; |
326 for (int i = 0; i < values.length; i++) { | 320 for (int i = 0; i < values.length; i++) { |
327 valueList.add(_reference(values[i])); | 321 valueList.add(_reference(values[i])); |
328 } | 322 } |
329 return valueList; | 323 return valueList; |
330 } | 324 } |
331 } | 325 } |
OLD | NEW |