| 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 '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../dart2jslib.dart'; | 8 import '../dart2jslib.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../elements/modelx.dart'; | 10 import '../elements/modelx.dart'; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 indexVariable); | 221 indexVariable); |
| 222 | 222 |
| 223 FunctionSignatureX constructorSignature = new FunctionSignatureX( | 223 FunctionSignatureX constructorSignature = new FunctionSignatureX( |
| 224 requiredParameters: builder.linkedList([indexFormal]), | 224 requiredParameters: builder.linkedList([indexFormal]), |
| 225 requiredParameterCount: 1, | 225 requiredParameterCount: 1, |
| 226 type: new FunctionType(constructor, const VoidType(), | 226 type: new FunctionType(constructor, const VoidType(), |
| 227 <DartType>[intType])); | 227 <DartType>[intType])); |
| 228 constructor.functionSignatureCache = constructorSignature; | 228 constructor.functionSignatureCache = constructorSignature; |
| 229 enumClass.addMember(constructor, compiler); | 229 enumClass.addMember(constructor, compiler); |
| 230 | 230 |
| 231 List<FieldElement> enumValues = <FieldElement>[]; |
| 231 VariableList variableList = | 232 VariableList variableList = |
| 232 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 233 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 233 variableList.type = enumType; | 234 variableList.type = enumType; |
| 234 int index = 0; | 235 int index = 0; |
| 235 List<Node> valueReferences = <Node>[]; | 236 List<Node> valueReferences = <Node>[]; |
| 236 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; | 237 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; |
| 237 for (Link<Node> link = node.names.nodes; | 238 for (Link<Node> link = node.names.nodes; |
| 238 !link.isEmpty; | 239 !link.isEmpty; |
| 239 link = link.tail) { | 240 link = link.tail) { |
| 240 Identifier name = link.head; | 241 Identifier name = link.head; |
| 241 AstBuilder valueBuilder = new AstBuilder(name.token); | 242 AstBuilder valueBuilder = new AstBuilder(name.token); |
| 242 | 243 |
| 243 // Add reference for the `values` field. | 244 // Add reference for the `values` field. |
| 244 valueReferences.add(valueBuilder.reference(name)); | 245 valueReferences.add(valueBuilder.reference(name)); |
| 245 | 246 |
| 246 // Add map entry for `toString` implementation. | 247 // Add map entry for `toString` implementation. |
| 247 mapEntries.add(valueBuilder.mapLiteralEntry( | 248 mapEntries.add(valueBuilder.mapLiteralEntry( |
| 248 valueBuilder.literalInt(index), | 249 valueBuilder.literalInt(index), |
| 249 valueBuilder.literalString('${enumClass.name}.${name.source}'))); | 250 valueBuilder.literalString('${enumClass.name}.${name.source}'))); |
| 250 | 251 |
| 251 Expression initializer = valueBuilder.newExpression( | 252 Expression initializer = valueBuilder.newExpression( |
| 252 enumClass.name, | 253 enumClass.name, |
| 253 valueBuilder.argumentList([valueBuilder.literalInt(index)]), | 254 valueBuilder.argumentList([valueBuilder.literalInt(index)]), |
| 254 isConst: true); | 255 isConst: true); |
| 255 SendSet definition = valueBuilder.createDefinition(name, initializer); | 256 SendSet definition = valueBuilder.createDefinition(name, initializer); |
| 256 | 257 |
| 257 EnumFieldElementX field = new EnumFieldElementX( | 258 EnumFieldElementX field = new EnumFieldElementX( |
| 258 name, enumClass, variableList, definition, initializer); | 259 name, enumClass, variableList, definition, initializer); |
| 260 enumValues.add(field); |
| 259 enumClass.addMember(field, compiler); | 261 enumClass.addMember(field, compiler); |
| 260 index++; | 262 index++; |
| 261 } | 263 } |
| 262 | 264 |
| 263 VariableList valuesVariableList = | 265 VariableList valuesVariableList = |
| 264 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 266 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 265 InterfaceType listType = compiler.listClass.computeType(compiler); | 267 InterfaceType listType = compiler.listClass.computeType(compiler); |
| 266 valuesVariableList.type = listType.createInstantiation([enumType]); | 268 valuesVariableList.type = listType.createInstantiation([enumType]); |
| 267 | 269 |
| 268 Identifier valuesIdentifier = builder.identifier('values'); | 270 Identifier valuesIdentifier = builder.identifier('values'); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 290 builder.reference(builder.identifier('index'))) | 292 builder.reference(builder.identifier('index'))) |
| 291 ) | 293 ) |
| 292 ); | 294 ); |
| 293 | 295 |
| 294 EnumMethodElementX toString = new EnumMethodElementX('toString', | 296 EnumMethodElementX toString = new EnumMethodElementX('toString', |
| 295 enumClass, Modifiers.EMPTY, toStringNode); | 297 enumClass, Modifiers.EMPTY, toStringNode); |
| 296 FunctionSignatureX toStringSignature = new FunctionSignatureX( | 298 FunctionSignatureX toStringSignature = new FunctionSignatureX( |
| 297 type: new FunctionType(toString, stringType)); | 299 type: new FunctionType(toString, stringType)); |
| 298 toString.functionSignatureCache = toStringSignature; | 300 toString.functionSignatureCache = toStringSignature; |
| 299 enumClass.addMember(toString, compiler); | 301 enumClass.addMember(toString, compiler); |
| 302 |
| 303 enumClass.enumValues = enumValues; |
| 300 } | 304 } |
| 301 } | 305 } |
| OLD | NEW |