| 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 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); | 7 typedef jsAst.Expression _ConstantReferenceGenerator(ConstantValue constant); |
| 8 | 8 |
| 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); | 9 typedef jsAst.Expression _ConstantListGenerator(jsAst.Expression array); |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 reporter.internalError(NO_LOCATION_SPANNABLE, | 59 reporter.internalError(NO_LOCATION_SPANNABLE, |
| 60 "The function constant does not need specific JS code."); | 60 "The function constant does not need specific JS code."); |
| 61 return null; | 61 return null; |
| 62 } | 62 } |
| 63 | 63 |
| 64 @override | 64 @override |
| 65 jsAst.Expression visitNull(NullConstantValue constant, [_]) { | 65 jsAst.Expression visitNull(NullConstantValue constant, [_]) { |
| 66 return new jsAst.LiteralNull(); | 66 return new jsAst.LiteralNull(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 @override |
| 70 jsAst.Expression visitNonConstant(NonConstantValue constant, [_]) { |
| 71 return new jsAst.LiteralNull(); |
| 72 } |
| 73 |
| 69 static final _exponentialRE = new RegExp( | 74 static final _exponentialRE = new RegExp( |
| 70 '^' | 75 '^' |
| 71 '\([-+]?\)' // 1: sign | 76 '\([-+]?\)' // 1: sign |
| 72 '\([0-9]+\)' // 2: leading digit(s) | 77 '\([0-9]+\)' // 2: leading digit(s) |
| 73 '\(\.\([0-9]*\)\)?' // 4: fraction digits | 78 '\(\.\([0-9]*\)\)?' // 4: fraction digits |
| 74 'e\([-+]?[0-9]+\)' // 5: exponent with sign | 79 'e\([-+]?[0-9]+\)' // 5: exponent with sign |
| 75 r'$'); | 80 r'$'); |
| 76 | 81 |
| 77 /// Reduces the size of exponential representations when minification is | 82 /// Reduces the size of exponential representations when minification is |
| 78 /// enabled. | 83 /// enabled. |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) { | 290 jsAst.Expression visitConstructed(ConstructedConstantValue constant, [_]) { |
| 286 Element element = constant.type.element; | 291 Element element = constant.type.element; |
| 287 if (backend.isForeign(element) | 292 if (backend.isForeign(element) |
| 288 && element.name == 'JS_CONST') { | 293 && element.name == 'JS_CONST') { |
| 289 StringConstantValue str = constant.fields.values.single; | 294 StringConstantValue str = constant.fields.values.single; |
| 290 String value = str.primitiveValue.slowToString(); | 295 String value = str.primitiveValue.slowToString(); |
| 291 return new jsAst.LiteralExpression(stripComments(value)); | 296 return new jsAst.LiteralExpression(stripComments(value)); |
| 292 } | 297 } |
| 293 jsAst.Expression constructor = | 298 jsAst.Expression constructor = |
| 294 backend.emitter.constructorAccess(constant.type.element); | 299 backend.emitter.constructorAccess(constant.type.element); |
| 295 List<jsAst.Expression> fields = | 300 List<jsAst.Expression> fields = <jsAst.Expression>[]; |
| 296 constant.fields.values.map(constantReferenceGenerator) | 301 constant.type.element.implementation.forEachInstanceField( |
| 297 .toList(growable: false); | 302 (ClassElement enclosingClass, VariableElement member) { |
| 303 fields.add(constantReferenceGenerator(constant.fields[member])); |
| 304 }, includeSuperAndInjectedMembers: true); |
| 298 jsAst.New instantiation = new jsAst.New(constructor, fields); | 305 jsAst.New instantiation = new jsAst.New(constructor, fields); |
| 299 return maybeAddTypeArguments(constant.type, instantiation); | 306 return maybeAddTypeArguments(constant.type, instantiation); |
| 300 } | 307 } |
| 301 | 308 |
| 302 String stripComments(String rawJavaScript) { | 309 String stripComments(String rawJavaScript) { |
| 303 return rawJavaScript.replaceAll(COMMENT_RE, ''); | 310 return rawJavaScript.replaceAll(COMMENT_RE, ''); |
| 304 } | 311 } |
| 305 | 312 |
| 306 jsAst.Expression maybeAddTypeArguments(InterfaceType type, | 313 jsAst.Expression maybeAddTypeArguments(InterfaceType type, |
| 307 jsAst.Expression value) { | 314 jsAst.Expression value) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 320 [value, argumentList]); | 327 [value, argumentList]); |
| 321 } | 328 } |
| 322 return value; | 329 return value; |
| 323 } | 330 } |
| 324 | 331 |
| 325 @override | 332 @override |
| 326 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { | 333 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { |
| 327 return constantReferenceGenerator(constant.referenced); | 334 return constantReferenceGenerator(constant.referenced); |
| 328 } | 335 } |
| 329 } | 336 } |
| OLD | NEW |