| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 indexDefinition, builder.identifier('index'), indexVariable); | 216 indexDefinition, builder.identifier('index'), indexVariable); |
| 217 | 217 |
| 218 FunctionSignatureX constructorSignature = new FunctionSignatureX( | 218 FunctionSignatureX constructorSignature = new FunctionSignatureX( |
| 219 requiredParameters: [indexFormal], | 219 requiredParameters: [indexFormal], |
| 220 requiredParameterCount: 1, | 220 requiredParameterCount: 1, |
| 221 type: new FunctionType( | 221 type: new FunctionType( |
| 222 constructor, const VoidType(), <DartType>[intType])); | 222 constructor, const VoidType(), <DartType>[intType])); |
| 223 constructor.functionSignature = constructorSignature; | 223 constructor.functionSignature = constructorSignature; |
| 224 enumClass.addMember(constructor, reporter); | 224 enumClass.addMember(constructor, reporter); |
| 225 | 225 |
| 226 List<FieldElement> enumValues = <FieldElement>[]; | 226 List<EnumConstantElement> enumValues = <EnumConstantElement>[]; |
| 227 VariableList variableList = | 227 VariableList variableList = |
| 228 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 228 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 229 variableList.type = enumType; | 229 variableList.type = enumType; |
| 230 int index = 0; | 230 int index = 0; |
| 231 List<Node> valueReferences = <Node>[]; | 231 List<Node> valueReferences = <Node>[]; |
| 232 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; | 232 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; |
| 233 for (Link<Node> link = node.names.nodes; !link.isEmpty; link = link.tail) { | 233 for (Link<Node> link = node.names.nodes; !link.isEmpty; link = link.tail) { |
| 234 Identifier name = link.head; | 234 Identifier name = link.head; |
| 235 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); | 235 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); |
| 236 | 236 |
| 237 // Add reference for the `values` field. | 237 // Add reference for the `values` field. |
| 238 valueReferences.add(valueBuilder.reference(name)); | 238 valueReferences.add(valueBuilder.reference(name)); |
| 239 | 239 |
| 240 // Add map entry for `toString` implementation. | 240 // Add map entry for `toString` implementation. |
| 241 mapEntries.add(valueBuilder.mapLiteralEntry( | 241 mapEntries.add(valueBuilder.mapLiteralEntry( |
| 242 valueBuilder.literalInt(index), | 242 valueBuilder.literalInt(index), |
| 243 valueBuilder.literalString('${enumClass.name}.${name.source}'))); | 243 valueBuilder.literalString('${enumClass.name}.${name.source}'))); |
| 244 | 244 |
| 245 Expression initializer = valueBuilder.newExpression(enumClass.name, | 245 Expression initializer = valueBuilder.newExpression(enumClass.name, |
| 246 valueBuilder.argumentList([valueBuilder.literalInt(index)]), | 246 valueBuilder.argumentList([valueBuilder.literalInt(index)]), |
| 247 isConst: true); | 247 isConst: true); |
| 248 SendSet definition = valueBuilder.createDefinition(name, initializer); | 248 SendSet definition = valueBuilder.createDefinition(name, initializer); |
| 249 | 249 |
| 250 EnumFieldElementX field = new EnumFieldElementX( | 250 EnumConstantElementX field = new EnumConstantElementX( |
| 251 name, enumClass, variableList, definition, initializer); | 251 name, enumClass, variableList, definition, initializer, index); |
| 252 enumValues.add(field); | 252 enumValues.add(field); |
| 253 enumClass.addMember(field, reporter); | 253 enumClass.addMember(field, reporter); |
| 254 index++; | 254 index++; |
| 255 } | 255 } |
| 256 | 256 |
| 257 VariableList valuesVariableList = | 257 VariableList valuesVariableList = |
| 258 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 258 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 259 valuesVariableList.type = coreTypes.listType(enumType); | 259 valuesVariableList.type = coreTypes.listType(enumType); |
| 260 | 260 |
| 261 Identifier valuesIdentifier = builder.identifier('values'); | 261 Identifier valuesIdentifier = builder.identifier('values'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 283 EnumMethodElementX toString = new EnumMethodElementX( | 283 EnumMethodElementX toString = new EnumMethodElementX( |
| 284 'toString', enumClass, Modifiers.EMPTY, toStringNode); | 284 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
| 285 FunctionSignatureX toStringSignature = | 285 FunctionSignatureX toStringSignature = |
| 286 new FunctionSignatureX(type: new FunctionType(toString, stringType)); | 286 new FunctionSignatureX(type: new FunctionType(toString, stringType)); |
| 287 toString.functionSignature = toStringSignature; | 287 toString.functionSignature = toStringSignature; |
| 288 enumClass.addMember(toString, reporter); | 288 enumClass.addMember(toString, reporter); |
| 289 | 289 |
| 290 enumClass.enumValues = enumValues; | 290 enumClass.enumValues = enumValues; |
| 291 } | 291 } |
| 292 } | 292 } |
| OLD | NEW |