OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.resolution.enum_creator; | 5 library dart2js.resolution.enum_creator; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../core_types.dart' show CoreTypes; | 8 import '../core_types.dart' show CoreTypes; |
9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 null, // Type arguments. | 164 null, // Type arguments. |
165 new NodeList( | 165 new NodeList( |
166 symbolToken(Precedence.OPEN_CURLY_BRACKET_INFO), | 166 symbolToken(Precedence.OPEN_CURLY_BRACKET_INFO), |
167 linkedList(entries), | 167 linkedList(entries), |
168 symbolToken(Precedence.CLOSE_CURLY_BRACKET_INFO), | 168 symbolToken(Precedence.CLOSE_CURLY_BRACKET_INFO), |
169 ','), | 169 ','), |
170 isConst ? keywordToken('const') : null); | 170 isConst ? keywordToken('const') : null); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
| 174 /// This class generates the model for an enum class. |
| 175 /// |
| 176 /// For instance |
| 177 /// |
| 178 /// enum A { b, c, } |
| 179 /// |
| 180 /// is modelled as |
| 181 /// |
| 182 /// class A { |
| 183 /// final int index; |
| 184 /// |
| 185 /// const A(this.index); |
| 186 /// |
| 187 /// String toString() { |
| 188 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index]; |
| 189 /// } |
| 190 /// |
| 191 /// static const A b = const A(0); |
| 192 /// static const A c = const A(1); |
| 193 /// |
| 194 /// static const List<A> values = const <A>[b, c]; |
| 195 /// } |
| 196 /// |
174 // TODO(johnniwinther): Avoid creating synthesized ASTs for enums when SSA is | 197 // TODO(johnniwinther): Avoid creating synthesized ASTs for enums when SSA is |
175 // removed. | 198 // removed. |
176 class EnumCreator { | 199 class EnumCreator { |
177 final DiagnosticReporter reporter; | 200 final DiagnosticReporter reporter; |
178 final CoreTypes coreTypes; | 201 final CoreTypes coreTypes; |
179 final EnumClassElementX enumClass; | 202 final EnumClassElementX enumClass; |
180 | 203 |
181 EnumCreator(this.reporter, this.coreTypes, this.enumClass); | 204 EnumCreator(this.reporter, this.coreTypes, this.enumClass); |
182 | 205 |
183 void createMembers() { | 206 void createMembers() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 EnumMethodElementX toString = new EnumMethodElementX( | 306 EnumMethodElementX toString = new EnumMethodElementX( |
284 'toString', enumClass, Modifiers.EMPTY, toStringNode); | 307 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
285 FunctionSignatureX toStringSignature = | 308 FunctionSignatureX toStringSignature = |
286 new FunctionSignatureX(type: new FunctionType(toString, stringType)); | 309 new FunctionSignatureX(type: new FunctionType(toString, stringType)); |
287 toString.functionSignature = toStringSignature; | 310 toString.functionSignature = toStringSignature; |
288 enumClass.addMember(toString, reporter); | 311 enumClass.addMember(toString, reporter); |
289 | 312 |
290 enumClass.enumValues = enumValues; | 313 enumClass.enumValues = enumValues; |
291 } | 314 } |
292 } | 315 } |
OLD | NEW |