OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.constants.evaluation; | 5 library dart2js.constants.evaluation; |
6 | 6 |
7 import '../compiler.dart' show | 7 import '../compiler.dart' show Compiler; |
8 Compiler; | 8 import '../universe/call_structure.dart' show CallStructure; |
9 import '../universe/call_structure.dart' show | |
10 CallStructure; | |
11 import 'expressions.dart'; | 9 import 'expressions.dart'; |
12 | 10 |
13 /// Environment used for evaluating constant expressions. | 11 /// Environment used for evaluating constant expressions. |
14 abstract class Environment { | 12 abstract class Environment { |
15 // TODO(johnniwinther): Replace this with [CoreTypes] and maybe [Backend]. | 13 // TODO(johnniwinther): Replace this with [CoreTypes] and maybe [Backend]. |
16 Compiler get compiler; | 14 Compiler get compiler; |
17 | 15 |
18 /// Read environments string passed in using the '-Dname=value' option. | 16 /// Read environments string passed in using the '-Dname=value' option. |
19 String readFromEnvironment(String name); | 17 String readFromEnvironment(String name); |
20 } | 18 } |
21 | 19 |
22 /// The normalized arguments passed to a const constructor computed from the | 20 /// The normalized arguments passed to a const constructor computed from the |
23 /// actual [arguments] and the [defaultValues] of the called construrctor. | 21 /// actual [arguments] and the [defaultValues] of the called construrctor. |
24 class NormalizedArguments { | 22 class NormalizedArguments { |
25 final Map<dynamic/*int|String*/, ConstantExpression> defaultValues; | 23 final Map<dynamic /*int|String*/, ConstantExpression> defaultValues; |
26 final CallStructure callStructure; | 24 final CallStructure callStructure; |
27 final List<ConstantExpression> arguments; | 25 final List<ConstantExpression> arguments; |
28 | 26 |
29 NormalizedArguments(this.defaultValues, this.callStructure, this.arguments); | 27 NormalizedArguments(this.defaultValues, this.callStructure, this.arguments); |
30 | 28 |
31 /// Returns the normalized named argument [name]. | 29 /// Returns the normalized named argument [name]. |
32 ConstantExpression getNamedArgument(String name) { | 30 ConstantExpression getNamedArgument(String name) { |
33 int index = callStructure.namedArguments.indexOf(name); | 31 int index = callStructure.namedArguments.indexOf(name); |
34 if (index == -1) { | 32 if (index == -1) { |
35 // The named argument is not provided. | 33 // The named argument is not provided. |
36 return defaultValues[name]; | 34 return defaultValues[name]; |
37 } | 35 } |
38 return arguments[index + callStructure.positionalArgumentCount]; | 36 return arguments[index + callStructure.positionalArgumentCount]; |
39 } | 37 } |
40 | 38 |
41 /// Returns the normalized [index]th positional argument. | 39 /// Returns the normalized [index]th positional argument. |
42 ConstantExpression getPositionalArgument(int index) { | 40 ConstantExpression getPositionalArgument(int index) { |
43 if (index >= callStructure.positionalArgumentCount) { | 41 if (index >= callStructure.positionalArgumentCount) { |
44 // The positional argument is not provided. | 42 // The positional argument is not provided. |
45 return defaultValues[index]; | 43 return defaultValues[index]; |
46 } | 44 } |
47 return arguments[index]; | 45 return arguments[index]; |
48 } | 46 } |
49 } | 47 } |
OLD | NEW |