| 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 CommonElements; |
| 9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 11 import '../elements/modelx.dart'; | 11 import '../elements/modelx.dart'; |
| 12 import '../tokens/keyword.dart' show Keyword; | 12 import '../tokens/keyword.dart' show Keyword; |
| 13 import '../tokens/precedence.dart'; | 13 import '../tokens/precedence.dart'; |
| 14 import '../tokens/precedence_constants.dart' as Precedence; | 14 import '../tokens/precedence_constants.dart' as Precedence; |
| 15 import '../tokens/token.dart'; | 15 import '../tokens/token.dart'; |
| 16 import '../tree/tree.dart'; | 16 import '../tree/tree.dart'; |
| 17 import '../util/util.dart'; | 17 import '../util/util.dart'; |
| 18 | 18 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 /// static const A b = const A(0); | 192 /// static const A b = const A(0); |
| 193 /// static const A c = const A(1); | 193 /// static const A c = const A(1); |
| 194 /// | 194 /// |
| 195 /// static const List<A> values = const <A>[b, c]; | 195 /// static const List<A> values = const <A>[b, c]; |
| 196 /// } | 196 /// } |
| 197 /// | 197 /// |
| 198 // TODO(johnniwinther): Avoid creating synthesized ASTs for enums when SSA is | 198 // TODO(johnniwinther): Avoid creating synthesized ASTs for enums when SSA is |
| 199 // removed. | 199 // removed. |
| 200 class EnumCreator { | 200 class EnumCreator { |
| 201 final DiagnosticReporter reporter; | 201 final DiagnosticReporter reporter; |
| 202 final CoreTypes coreTypes; | 202 final CommonElements commonElements; |
| 203 final EnumClassElementX enumClass; | 203 final EnumClassElementX enumClass; |
| 204 | 204 |
| 205 EnumCreator(this.reporter, this.coreTypes, this.enumClass); | 205 EnumCreator(this.reporter, this.commonElements, this.enumClass); |
| 206 | 206 |
| 207 void createMembers() { | 207 void createMembers() { |
| 208 Enum node = enumClass.node; | 208 Enum node = enumClass.node; |
| 209 InterfaceType enumType = enumClass.thisType; | 209 InterfaceType enumType = enumClass.thisType; |
| 210 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); | 210 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); |
| 211 | 211 |
| 212 InterfaceType intType = coreTypes.intType; | 212 InterfaceType intType = commonElements.intType; |
| 213 InterfaceType stringType = coreTypes.stringType; | 213 InterfaceType stringType = commonElements.stringType; |
| 214 | 214 |
| 215 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { | 215 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { |
| 216 Identifier identifier = builder.identifier(name); | 216 Identifier identifier = builder.identifier(name); |
| 217 VariableList variableList = | 217 VariableList variableList = |
| 218 new VariableList(builder.modifiers(isFinal: true)); | 218 new VariableList(builder.modifiers(isFinal: true)); |
| 219 variableList.type = type; | 219 variableList.type = type; |
| 220 EnumFieldElementX variable = new EnumFieldElementX( | 220 EnumFieldElementX variable = new EnumFieldElementX( |
| 221 identifier, enumClass, variableList, identifier); | 221 identifier, enumClass, variableList, identifier); |
| 222 enumClass.addMember(variable, reporter); | 222 enumClass.addMember(variable, reporter); |
| 223 return variable; | 223 return variable; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 EnumConstantElementX field = new EnumConstantElementX( | 275 EnumConstantElementX field = new EnumConstantElementX( |
| 276 name, enumClass, variableList, definition, initializer, index); | 276 name, enumClass, variableList, definition, initializer, index); |
| 277 enumValues.add(field); | 277 enumValues.add(field); |
| 278 enumClass.addMember(field, reporter); | 278 enumClass.addMember(field, reporter); |
| 279 index++; | 279 index++; |
| 280 } | 280 } |
| 281 | 281 |
| 282 VariableList valuesVariableList = | 282 VariableList valuesVariableList = |
| 283 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 283 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 284 valuesVariableList.type = coreTypes.listType(enumType); | 284 valuesVariableList.type = commonElements.listType(enumType); |
| 285 | 285 |
| 286 Identifier valuesIdentifier = builder.identifier('values'); | 286 Identifier valuesIdentifier = builder.identifier('values'); |
| 287 // TODO(johnniwinther): Add type argument. | 287 // TODO(johnniwinther): Add type argument. |
| 288 Expression initializer = | 288 Expression initializer = |
| 289 builder.listLiteral(valueReferences, isConst: true); | 289 builder.listLiteral(valueReferences, isConst: true); |
| 290 | 290 |
| 291 Node definition = builder.createDefinition(valuesIdentifier, initializer); | 291 Node definition = builder.createDefinition(valuesIdentifier, initializer); |
| 292 | 292 |
| 293 EnumFieldElementX valuesVariable = new EnumFieldElementX(valuesIdentifier, | 293 EnumFieldElementX valuesVariable = new EnumFieldElementX(valuesIdentifier, |
| 294 enumClass, valuesVariableList, definition, initializer); | 294 enumClass, valuesVariableList, definition, initializer); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 309 EnumMethodElementX toString = new EnumMethodElementX( | 309 EnumMethodElementX toString = new EnumMethodElementX( |
| 310 'toString', enumClass, Modifiers.EMPTY, toStringNode); | 310 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
| 311 FunctionSignatureX toStringSignature = | 311 FunctionSignatureX toStringSignature = |
| 312 new FunctionSignatureX(type: new FunctionType(toString, stringType)); | 312 new FunctionSignatureX(type: new FunctionType(toString, stringType)); |
| 313 toString.functionSignature = toStringSignature; | 313 toString.functionSignature = toStringSignature; |
| 314 enumClass.addMember(toString, reporter); | 314 enumClass.addMember(toString, reporter); |
| 315 | 315 |
| 316 enumClass.enumValues = enumValues; | 316 enumClass.enumValues = enumValues; |
| 317 } | 317 } |
| 318 } | 318 } |
| OLD | NEW |