Chromium Code Reviews| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 jsAst.Expression visitFalse(FalseConstant constant) { | 202 jsAst.Expression visitFalse(FalseConstant constant) { |
| 203 return _reference(constant); | 203 return _reference(constant); |
| 204 } | 204 } |
| 205 | 205 |
| 206 jsAst.Expression visitString(StringConstant constant) { | 206 jsAst.Expression visitString(StringConstant constant) { |
| 207 // TODO(sra): Some larger strings are worth sharing. | 207 // TODO(sra): Some larger strings are worth sharing. |
| 208 return _reference(constant); | 208 return _reference(constant); |
| 209 } | 209 } |
| 210 | 210 |
| 211 jsAst.Expression visitList(ListConstant constant) { | 211 jsAst.Expression visitList(ListConstant constant) { |
| 212 return new jsAst.Call( | 212 jsAst.Expression value = new jsAst.Call( |
| 213 new jsAst.PropertyAccess.field( | 213 new jsAst.PropertyAccess.field( |
| 214 new jsAst.VariableUse(namer.isolateName), | 214 new jsAst.VariableUse(namer.isolateName), |
| 215 'makeConstantList'), | 215 'makeConstantList'), |
| 216 [new jsAst.ArrayInitializer.from(_array(constant.entries))]); | 216 [new jsAst.ArrayInitializer.from(_array(constant.entries))]); |
| 217 return maybeAddTypeArguments(constant.type, value); | |
| 217 } | 218 } |
| 218 | 219 |
| 219 String getJsConstructor(ClassElement element) { | 220 String getJsConstructor(ClassElement element) { |
| 220 return namer.isolateAccess(element); | 221 return namer.isolateAccess(element); |
| 221 } | 222 } |
| 222 | 223 |
| 223 jsAst.Expression visitMap(MapConstant constant) { | 224 jsAst.Expression visitMap(MapConstant constant) { |
| 224 jsAst.Expression jsMap() { | 225 jsAst.Expression jsMap() { |
| 225 List<jsAst.Property> properties = <jsAst.Property>[]; | 226 List<jsAst.Property> properties = <jsAst.Property>[]; |
| 226 int valueIndex = 0; | 227 int valueIndex = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 } | 270 } |
| 270 emittedArgumentCount++; | 271 emittedArgumentCount++; |
| 271 }, | 272 }, |
| 272 includeSuperAndInjectedMembers: true); | 273 includeSuperAndInjectedMembers: true); |
| 273 | 274 |
| 274 if ((constant.protoValue == null && emittedArgumentCount != 3) || | 275 if ((constant.protoValue == null && emittedArgumentCount != 3) || |
| 275 (constant.protoValue != null && emittedArgumentCount != 4)) { | 276 (constant.protoValue != null && emittedArgumentCount != 4)) { |
| 276 badFieldCountError(); | 277 badFieldCountError(); |
| 277 } | 278 } |
| 278 | 279 |
| 279 return new jsAst.New( | 280 jsAst.Expression value = new jsAst.New( |
| 280 new jsAst.VariableUse(getJsConstructor(classElement)), | 281 new jsAst.VariableUse(getJsConstructor(classElement)), |
| 281 arguments); | 282 arguments); |
| 283 return maybeAddTypeArguments(constant.type, value); | |
| 284 } | |
| 285 | |
| 286 JavaScriptBackend get backend => compiler.backend; | |
| 287 | |
| 288 jsAst.PropertyAccess getHelperProperty(Element helper) { | |
| 289 String helperName = backend.namer.getName(helper); | |
| 290 return new jsAst.PropertyAccess.field( | |
| 291 new jsAst.VariableUse(namer.CURRENT_ISOLATE), | |
| 292 helperName); | |
| 282 } | 293 } |
| 283 | 294 |
| 284 jsAst.Expression visitType(TypeConstant constant) { | 295 jsAst.Expression visitType(TypeConstant constant) { |
| 285 JavaScriptBackend backend = compiler.backend; | |
| 286 Element helper = backend.getCreateRuntimeType(); | |
| 287 String helperName = backend.namer.getName(helper); | |
| 288 DartType type = constant.representedType; | 296 DartType type = constant.representedType; |
| 289 String name = namer.getRuntimeTypeName(type.element); | 297 String name = namer.getRuntimeTypeName(type.element); |
| 290 jsAst.Expression typeName = new jsAst.LiteralString("'$name'"); | 298 jsAst.Expression typeName = new jsAst.LiteralString("'$name'"); |
| 291 return new jsAst.Call( | 299 return new jsAst.Call(getHelperProperty(backend.getCreateRuntimeType()), |
| 292 new jsAst.PropertyAccess.field( | 300 [typeName]); |
| 293 new jsAst.VariableUse(namer.CURRENT_ISOLATE), | |
| 294 helperName), | |
| 295 [typeName]); | |
| 296 } | 301 } |
| 297 | 302 |
| 298 jsAst.Expression visitInterceptor(InterceptorConstant constant) { | 303 jsAst.Expression visitInterceptor(InterceptorConstant constant) { |
| 299 return new jsAst.PropertyAccess.field( | 304 return new jsAst.PropertyAccess.field( |
| 300 new jsAst.VariableUse( | 305 new jsAst.VariableUse( |
| 301 getJsConstructor(constant.dispatchedType.element)), | 306 getJsConstructor(constant.dispatchedType.element)), |
| 302 'prototype'); | 307 'prototype'); |
| 303 } | 308 } |
| 304 | 309 |
| 305 jsAst.Expression visitConstructed(ConstructedConstant constant) { | 310 jsAst.Expression visitConstructed(ConstructedConstant constant) { |
| 306 return new jsAst.New( | 311 jsAst.New instantiation = new jsAst.New( |
| 307 new jsAst.VariableUse(getJsConstructor(constant.type.element)), | 312 new jsAst.VariableUse(getJsConstructor(constant.type.element)), |
| 308 _array(constant.fields)); | 313 _array(constant.fields)); |
| 314 return maybeAddTypeArguments(constant.type, instantiation); | |
| 309 } | 315 } |
| 310 | 316 |
| 311 List<jsAst.Expression> _array(List<Constant> values) { | 317 List<jsAst.Expression> _array(List<Constant> values) { |
| 312 List<jsAst.Expression> valueList = <jsAst.Expression>[]; | 318 List<jsAst.Expression> valueList = <jsAst.Expression>[]; |
| 313 for (int i = 0; i < values.length; i++) { | 319 for (int i = 0; i < values.length; i++) { |
| 314 valueList.add(_reference(values[i])); | 320 valueList.add(_reference(values[i])); |
| 315 } | 321 } |
| 316 return valueList; | 322 return valueList; |
| 317 } | 323 } |
| 324 | |
| 325 jsAst.Expression maybeAddTypeArguments(InterfaceType type, | |
| 326 jsAst.Expression value) { | |
| 327 if (type is InterfaceType && !type.isRaw && | |
|
ngeoffray
2013/06/19 19:55:48
nit: move && !type.isRaw to a new line.
karlklose
2013/06/20 09:25:23
Why?
ngeoffray
2013/06/20 09:31:56
http://www.dartlang.org/articles/style-guide/: DO
karlklose
2013/06/20 10:23:28
But your comment was about moving every part expre
ngeoffray
2013/06/20 10:32:07
The guide does not explicitly say it, but if you l
karlklose
2013/06/20 12:49:21
Done.
| |
| 328 backend.needsRti(type.element)) { | |
| 329 InterfaceType interface = type; | |
| 330 RuntimeTypes rti = backend.rti; | |
| 331 Iterable<String> arguments = interface.typeArguments | |
| 332 .toList(growable: false) | |
| 333 .map((DartType type) => rti.getTypeRepresentation(type, (_){})); | |
| 334 jsAst.Expression argumentList = | |
| 335 new jsAst.LiteralString('[${arguments.join(', ')}]'); | |
| 336 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()), | |
| 337 [value, argumentList]); | |
| 338 } | |
| 339 return value; | |
| 340 } | |
| 318 } | 341 } |
| OLD | NEW |