| 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 '../compiler.dart'; | 7 import '../compiler.dart'; |
| 8 import '../core_types.dart'; |
| 8 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 10 import '../elements/modelx.dart'; | 11 import '../elements/modelx.dart'; |
| 11 import '../tokens/keyword.dart' show | 12 import '../tokens/keyword.dart' show |
| 12 Keyword; | 13 Keyword; |
| 13 import '../tokens/precedence.dart'; | 14 import '../tokens/precedence.dart'; |
| 14 import '../tokens/precedence_constants.dart' as Precedence; | 15 import '../tokens/precedence_constants.dart' as Precedence; |
| 15 import '../tokens/token.dart'; | 16 import '../tokens/token.dart'; |
| 16 import '../tree/tree.dart'; | 17 import '../tree/tree.dart'; |
| 17 import '../util/util.dart'; | 18 import '../util/util.dart'; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 isConst ? keywordToken('const') : null); | 178 isConst ? keywordToken('const') : null); |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 | 181 |
| 181 class EnumCreator { | 182 class EnumCreator { |
| 182 final Compiler compiler; | 183 final Compiler compiler; |
| 183 final EnumClassElementX enumClass; | 184 final EnumClassElementX enumClass; |
| 184 | 185 |
| 185 EnumCreator(this.compiler, this.enumClass); | 186 EnumCreator(this.compiler, this.enumClass); |
| 186 | 187 |
| 188 CoreTypes get coreTypes => compiler.coreTypes; |
| 189 |
| 187 void createMembers() { | 190 void createMembers() { |
| 188 Enum node = enumClass.node; | 191 Enum node = enumClass.node; |
| 189 InterfaceType enumType = enumClass.thisType; | 192 InterfaceType enumType = enumClass.thisType; |
| 190 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); | 193 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); |
| 191 | 194 |
| 192 InterfaceType intType = compiler.intClass.computeType(compiler); | 195 InterfaceType intType = coreTypes.intType; |
| 193 InterfaceType stringType = compiler.stringClass.computeType(compiler); | 196 InterfaceType stringType = coreTypes.stringType; |
| 194 | 197 |
| 195 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { | 198 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { |
| 196 Identifier identifier = builder.identifier(name); | 199 Identifier identifier = builder.identifier(name); |
| 197 VariableList variableList = | 200 VariableList variableList = |
| 198 new VariableList(builder.modifiers(isFinal: true)); | 201 new VariableList(builder.modifiers(isFinal: true)); |
| 199 variableList.type = type; | 202 variableList.type = type; |
| 200 EnumFieldElementX variable = new EnumFieldElementX( | 203 EnumFieldElementX variable = new EnumFieldElementX( |
| 201 identifier, enumClass, variableList, identifier); | 204 identifier, enumClass, variableList, identifier); |
| 202 enumClass.addMember(variable, compiler); | 205 enumClass.addMember(variable, compiler); |
| 203 return variable; | 206 return variable; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 264 |
| 262 EnumFieldElementX field = new EnumFieldElementX( | 265 EnumFieldElementX field = new EnumFieldElementX( |
| 263 name, enumClass, variableList, definition, initializer); | 266 name, enumClass, variableList, definition, initializer); |
| 264 enumValues.add(field); | 267 enumValues.add(field); |
| 265 enumClass.addMember(field, compiler); | 268 enumClass.addMember(field, compiler); |
| 266 index++; | 269 index++; |
| 267 } | 270 } |
| 268 | 271 |
| 269 VariableList valuesVariableList = | 272 VariableList valuesVariableList = |
| 270 new VariableList(builder.modifiers(isStatic: true, isConst: true)); | 273 new VariableList(builder.modifiers(isStatic: true, isConst: true)); |
| 271 InterfaceType listType = compiler.listClass.computeType(compiler); | 274 valuesVariableList.type = coreTypes.listType(enumType); |
| 272 valuesVariableList.type = listType.createInstantiation([enumType]); | |
| 273 | 275 |
| 274 Identifier valuesIdentifier = builder.identifier('values'); | 276 Identifier valuesIdentifier = builder.identifier('values'); |
| 275 // TODO(johnniwinther): Add type argument. | 277 // TODO(johnniwinther): Add type argument. |
| 276 Expression initializer = builder.listLiteral( | 278 Expression initializer = builder.listLiteral( |
| 277 valueReferences, isConst: true); | 279 valueReferences, isConst: true); |
| 278 | 280 |
| 279 Node definition = builder.createDefinition(valuesIdentifier, initializer); | 281 Node definition = builder.createDefinition(valuesIdentifier, initializer); |
| 280 | 282 |
| 281 EnumFieldElementX valuesVariable = new EnumFieldElementX( | 283 EnumFieldElementX valuesVariable = new EnumFieldElementX( |
| 282 valuesIdentifier, enumClass, valuesVariableList, | 284 valuesIdentifier, enumClass, valuesVariableList, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 300 EnumMethodElementX toString = new EnumMethodElementX('toString', | 302 EnumMethodElementX toString = new EnumMethodElementX('toString', |
| 301 enumClass, Modifiers.EMPTY, toStringNode); | 303 enumClass, Modifiers.EMPTY, toStringNode); |
| 302 FunctionSignatureX toStringSignature = new FunctionSignatureX( | 304 FunctionSignatureX toStringSignature = new FunctionSignatureX( |
| 303 type: new FunctionType(toString, stringType)); | 305 type: new FunctionType(toString, stringType)); |
| 304 toString.functionSignatureCache = toStringSignature; | 306 toString.functionSignatureCache = toStringSignature; |
| 305 enumClass.addMember(toString, compiler); | 307 enumClass.addMember(toString, compiler); |
| 306 | 308 |
| 307 enumClass.enumValues = enumValues; | 309 enumClass.enumValues = enumValues; |
| 308 } | 310 } |
| 309 } | 311 } |
| OLD | NEW |