| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 nameVariable); | 191 nameVariable); |
| 192 | 192 |
| 193 FunctionSignatureX constructorSignature = new FunctionSignatureX( | 193 FunctionSignatureX constructorSignature = new FunctionSignatureX( |
| 194 requiredParameters: builder.linkedList([indexFormal, nameFormal]), | 194 requiredParameters: builder.linkedList([indexFormal, nameFormal]), |
| 195 requiredParameterCount: 2, | 195 requiredParameterCount: 2, |
| 196 type: new FunctionType(constructor, const VoidType(), | 196 type: new FunctionType(constructor, const VoidType(), |
| 197 <DartType>[intType, stringType])); | 197 <DartType>[intType, stringType])); |
| 198 constructor.functionSignatureCache = constructorSignature; | 198 constructor.functionSignatureCache = constructorSignature; |
| 199 enumClass.addMember(constructor, compiler); | 199 enumClass.addMember(constructor, compiler); |
| 200 | 200 |
| 201 List<FieldElement> enumValues = <FieldElement>[]; |
| 201 VariableList variableList = new VariableList(builder.staticConstModifiers); | 202 VariableList variableList = new VariableList(builder.staticConstModifiers); |
| 202 variableList.type = enumType; | 203 variableList.type = enumType; |
| 203 int index = 0; | 204 int index = 0; |
| 204 List<Node> valueReferences = <Node>[]; | 205 List<Node> valueReferences = <Node>[]; |
| 205 for (Link<Node> link = node.names.nodes; | 206 for (Link<Node> link = node.names.nodes; |
| 206 !link.isEmpty; | 207 !link.isEmpty; |
| 207 link = link.tail) { | 208 link = link.tail) { |
| 208 Identifier name = link.head; | 209 Identifier name = link.head; |
| 209 AstBuilder valueBuilder = new AstBuilder(name.token); | 210 AstBuilder valueBuilder = new AstBuilder(name.token); |
| 210 valueReferences.add(new Send(null, name)); | 211 valueReferences.add(new Send(null, name)); |
| 211 | 212 |
| 212 Expression initializer = valueBuilder.newExpression( | 213 Expression initializer = valueBuilder.newExpression( |
| 213 enumClass.name, | 214 enumClass.name, |
| 214 valueBuilder.argumentList([ | 215 valueBuilder.argumentList([ |
| 215 valueBuilder.literalInt(index), | 216 valueBuilder.literalInt(index), |
| 216 valueBuilder.literalString('${name.source}') | 217 valueBuilder.literalString('${name.source}') |
| 217 ]), | 218 ]), |
| 218 isConst: true); | 219 isConst: true); |
| 219 SendSet definition = valueBuilder.createDefinition(name, initializer); | 220 SendSet definition = valueBuilder.createDefinition(name, initializer); |
| 220 | 221 |
| 221 EnumFieldElementX field = new EnumFieldElementX( | 222 EnumFieldElementX field = new EnumFieldElementX( |
| 222 name, enumClass, variableList, definition, initializer); | 223 name, enumClass, variableList, definition, initializer); |
| 224 enumValues.add(field); |
| 223 enumClass.addMember(field, compiler); | 225 enumClass.addMember(field, compiler); |
| 224 index++; | 226 index++; |
| 225 } | 227 } |
| 226 | 228 |
| 227 VariableList valuesVariableList = | 229 VariableList valuesVariableList = |
| 228 new VariableList(builder.staticConstModifiers); | 230 new VariableList(builder.staticConstModifiers); |
| 229 InterfaceType listType = compiler.listClass.computeType(compiler); | 231 InterfaceType listType = compiler.listClass.computeType(compiler); |
| 230 valuesVariableList.type = listType.createInstantiation([enumType]); | 232 valuesVariableList.type = listType.createInstantiation([enumType]); |
| 231 | 233 |
| 232 Identifier valuesIdentifier = builder.identifier('values'); | 234 Identifier valuesIdentifier = builder.identifier('values'); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 256 builder.literalString('', prefix: ''))) | 258 builder.literalString('', prefix: ''))) |
| 257 )) | 259 )) |
| 258 ); | 260 ); |
| 259 | 261 |
| 260 EnumMethodElementX toString = new EnumMethodElementX('toString', | 262 EnumMethodElementX toString = new EnumMethodElementX('toString', |
| 261 enumClass, Modifiers.EMPTY, toStringNode); | 263 enumClass, Modifiers.EMPTY, toStringNode); |
| 262 FunctionSignatureX toStringSignature = new FunctionSignatureX( | 264 FunctionSignatureX toStringSignature = new FunctionSignatureX( |
| 263 type: new FunctionType(toString, stringType)); | 265 type: new FunctionType(toString, stringType)); |
| 264 toString.functionSignatureCache = toStringSignature; | 266 toString.functionSignatureCache = toStringSignature; |
| 265 enumClass.addMember(toString, compiler); | 267 enumClass.addMember(toString, compiler); |
| 268 |
| 269 enumClass.enumValues = enumValues; |
| 266 } | 270 } |
| 267 } | 271 } |
| OLD | NEW |