Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: pkg/compiler/lib/src/constants/evaluation.dart

Issue 2686243004: Handler the last native annotations (Closed)
Patch Set: Cleanup. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 '../common.dart';
7 import '../common/backend_api.dart' show BackendClasses; 8 import '../common/backend_api.dart' show BackendClasses;
8 import '../core_types.dart' show CommonElements; 9 import '../core_types.dart' show CommonElements;
9 import '../elements/entities.dart'; 10 import '../elements/entities.dart';
10 import '../elements/types.dart'; 11 import '../elements/types.dart';
11 import '../universe/call_structure.dart' show CallStructure; 12 import '../universe/call_structure.dart' show CallStructure;
12 import 'constructors.dart'; 13 import 'constructors.dart';
13 import 'expressions.dart'; 14 import 'expressions.dart';
14 15
15 /// Environment used for evaluating constant expressions. 16 /// Environment used for evaluating constant expressions.
16 abstract class Environment { 17 abstract class Environment {
(...skipping 28 matching lines...) Expand all
45 final CallStructure callStructure; 46 final CallStructure callStructure;
46 final List<ConstantExpression> arguments; 47 final List<ConstantExpression> arguments;
47 48
48 NormalizedArguments(this.defaultValues, this.callStructure, this.arguments); 49 NormalizedArguments(this.defaultValues, this.callStructure, this.arguments);
49 50
50 /// Returns the normalized named argument [name]. 51 /// Returns the normalized named argument [name].
51 ConstantExpression getNamedArgument(String name) { 52 ConstantExpression getNamedArgument(String name) {
52 int index = callStructure.namedArguments.indexOf(name); 53 int index = callStructure.namedArguments.indexOf(name);
53 if (index == -1) { 54 if (index == -1) {
54 // The named argument is not provided. 55 // The named argument is not provided.
56 invariant(CURRENT_ELEMENT_SPANNABLE, defaultValues[name] != null,
57 message: "No default value for named argument '$name' in $this.");
55 return defaultValues[name]; 58 return defaultValues[name];
56 } 59 }
57 return arguments[index + callStructure.positionalArgumentCount]; 60 ConstantExpression value =
61 arguments[index + callStructure.positionalArgumentCount];
62 invariant(CURRENT_ELEMENT_SPANNABLE, value != null,
63 message: "No value for named argument '$name' in $this.");
64 return value;
58 } 65 }
59 66
60 /// Returns the normalized [index]th positional argument. 67 /// Returns the normalized [index]th positional argument.
61 ConstantExpression getPositionalArgument(int index) { 68 ConstantExpression getPositionalArgument(int index) {
62 if (index >= callStructure.positionalArgumentCount) { 69 if (index >= callStructure.positionalArgumentCount) {
63 // The positional argument is not provided. 70 // The positional argument is not provided.
71 invariant(CURRENT_ELEMENT_SPANNABLE, defaultValues[index] != null,
72 message: "No default value for positional argument $index in $this.");
64 return defaultValues[index]; 73 return defaultValues[index];
65 } 74 }
66 return arguments[index]; 75 ConstantExpression value = arguments[index];
76 invariant(CURRENT_ELEMENT_SPANNABLE, value != null,
77 message: "No value for positional argument $index in $this.");
78 return value;
79 }
80
81 String toString() {
82 StringBuffer sb = new StringBuffer();
83 sb.write('NormalizedArguments[');
84 sb.write('defaultValues={');
85 bool needsComma = false;
86 defaultValues.forEach((var key, ConstantExpression value) {
87 if (needsComma) {
88 sb.write(',');
89 }
90 if (key is String) {
91 sb.write('"');
92 sb.write(key);
93 sb.write('"');
94 } else {
95 sb.write(key);
96 }
97 sb.write(':');
98 sb.write(value.toStructuredText());
99 needsComma = true;
100 });
101 sb.write('},callStructure=');
102 sb.write(callStructure);
103 sb.write(',arguments=[');
104 arguments.forEach((ConstantExpression value) {
105 if (needsComma) {
106 sb.write(',');
107 }
108 sb.write(value.toStructuredText());
109 needsComma = true;
110 });
111 sb.write(']]');
112 return sb.toString();
67 } 113 }
68 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698