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 15 matching lines...) Expand all Loading... |
26 * constants should be inlined or not. | 26 * constants should be inlined or not. |
27 */ | 27 */ |
28 class ConstantEmitter implements ConstantValueVisitor<jsAst.Expression, Null> { | 28 class ConstantEmitter implements ConstantValueVisitor<jsAst.Expression, Null> { |
29 // Matches blank lines, comment lines and trailing comments that can't be part | 29 // Matches blank lines, comment lines and trailing comments that can't be part |
30 // of a string. | 30 // of a string. |
31 static final RegExp COMMENT_RE = | 31 static final RegExp COMMENT_RE = |
32 new RegExp(r'''^ *(//.*)?\n| *//[^''"\n]*$''', multiLine: true); | 32 new RegExp(r'''^ *(//.*)?\n| *//[^''"\n]*$''', multiLine: true); |
33 | 33 |
34 final Compiler compiler; | 34 final Compiler compiler; |
35 final Namer namer; | 35 final Namer namer; |
36 final _ConstantReferenceGenerator constantReferenceGenerator; | 36 final ConstantValue->jsAst.Expression constantReferenceGenerator; |
37 final _ConstantListGenerator makeConstantList; | 37 final (jsAst.Expression array) -> jsAst.Expression makeConstantList; |
38 | 38 |
39 /** | 39 /** |
40 * The given [constantReferenceGenerator] function must, when invoked with a | 40 * The given [constantReferenceGenerator] function must, when invoked with a |
41 * constant, either return a reference or return its literal expression if it | 41 * constant, either return a reference or return its literal expression if it |
42 * can be inlined. | 42 * can be inlined. |
43 */ | 43 */ |
44 ConstantEmitter( | 44 ConstantEmitter( |
45 this.compiler, | 45 this.compiler, |
46 this.namer, | 46 this.namer, |
47 jsAst.Expression this.constantReferenceGenerator(ConstantValue constant), | 47 ConstantValue->jsAst.Expression this.constantReferenceGenerator, |
48 this.makeConstantList); | 48 this.makeConstantList); |
49 | 49 |
50 DiagnosticReporter get reporter => compiler.reporter; | 50 DiagnosticReporter get reporter => compiler.reporter; |
51 | 51 |
52 /** | 52 /** |
53 * Constructs a literal expression that evaluates to the constant. Uses a | 53 * Constructs a literal expression that evaluates to the constant. Uses a |
54 * canonical name unless the constant can be emitted multiple times (as for | 54 * canonical name unless the constant can be emitted multiple times (as for |
55 * numbers and strings). | 55 * numbers and strings). |
56 */ | 56 */ |
57 jsAst.Expression generate(ConstantValue constant) { | 57 jsAst.Expression generate(ConstantValue constant) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 arguments.add(rtiEncoder.getTypeRepresentation(argument, unexpected)); | 349 arguments.add(rtiEncoder.getTypeRepresentation(argument, unexpected)); |
350 } | 350 } |
351 return new jsAst.ArrayInitializer(arguments); | 351 return new jsAst.ArrayInitializer(arguments); |
352 } | 352 } |
353 | 353 |
354 @override | 354 @override |
355 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { | 355 jsAst.Expression visitDeferred(DeferredConstantValue constant, [_]) { |
356 return constantReferenceGenerator(constant.referenced); | 356 return constantReferenceGenerator(constant.referenced); |
357 } | 357 } |
358 } | 358 } |
OLD | NEW |