| 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 CommonElements; | 8 import '../core_types.dart' show CommonElements; |
| 9 import '../elements/resolution_types.dart'; | 9 import '../elements/resolution_types.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // removed. | 199 // removed. |
| 200 class EnumCreator { | 200 class EnumCreator { |
| 201 final DiagnosticReporter reporter; | 201 final DiagnosticReporter reporter; |
| 202 final CommonElements commonElements; | 202 final CommonElements commonElements; |
| 203 final EnumClassElementX enumClass; | 203 final EnumClassElementX enumClass; |
| 204 | 204 |
| 205 EnumCreator(this.reporter, this.commonElements, 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 ResolutionInterfaceType enumType = enumClass.thisType; |
| 210 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); | 210 AstBuilder builder = new AstBuilder(enumClass.position.charOffset); |
| 211 | 211 |
| 212 InterfaceType intType = commonElements.intType; | 212 ResolutionInterfaceType intType = commonElements.intType; |
| 213 InterfaceType stringType = commonElements.stringType; | 213 ResolutionInterfaceType stringType = commonElements.stringType; |
| 214 | 214 |
| 215 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { | 215 EnumFieldElementX addInstanceMember( |
| 216 String name, ResolutionInterfaceType type) { |
| 216 Identifier identifier = builder.identifier(name); | 217 Identifier identifier = builder.identifier(name); |
| 217 VariableList variableList = | 218 VariableList variableList = |
| 218 new VariableList(builder.modifiers(isFinal: true)); | 219 new VariableList(builder.modifiers(isFinal: true)); |
| 219 variableList.type = type; | 220 variableList.type = type; |
| 220 EnumFieldElementX variable = new EnumFieldElementX( | 221 EnumFieldElementX variable = new EnumFieldElementX( |
| 221 identifier, enumClass, variableList, identifier); | 222 identifier, enumClass, variableList, identifier); |
| 222 enumClass.addMember(variable, reporter); | 223 enumClass.addMember(variable, reporter); |
| 223 return variable; | 224 return variable; |
| 224 } | 225 } |
| 225 | 226 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 | 237 |
| 237 EnumConstructorElementX constructor = new EnumConstructorElementX( | 238 EnumConstructorElementX constructor = new EnumConstructorElementX( |
| 238 enumClass, builder.modifiers(isConst: true), constructorNode); | 239 enumClass, builder.modifiers(isConst: true), constructorNode); |
| 239 | 240 |
| 240 EnumFormalElementX indexFormal = new EnumFormalElementX(constructor, | 241 EnumFormalElementX indexFormal = new EnumFormalElementX(constructor, |
| 241 indexDefinition, builder.identifier('index'), indexVariable); | 242 indexDefinition, builder.identifier('index'), indexVariable); |
| 242 | 243 |
| 243 FunctionSignatureX constructorSignature = new FunctionSignatureX( | 244 FunctionSignatureX constructorSignature = new FunctionSignatureX( |
| 244 requiredParameters: [indexFormal], | 245 requiredParameters: [indexFormal], |
| 245 requiredParameterCount: 1, | 246 requiredParameterCount: 1, |
| 246 type: new FunctionType( | 247 type: new ResolutionFunctionType(constructor, |
| 247 constructor, const DynamicType(), <DartType>[intType])); | 248 const ResolutionDynamicType(), <ResolutionDartType>[intType])); |
| 248 constructor.functionSignature = constructorSignature; | 249 constructor.functionSignature = constructorSignature; |
| 249 enumClass.addMember(constructor, reporter); | 250 enumClass.addMember(constructor, reporter); |
| 250 | 251 |
| 251 List<EnumConstantElement> enumValues = <EnumConstantElement>[]; | 252 List<EnumConstantElement> enumValues = <EnumConstantElement>[]; |
| 252 int index = 0; | 253 int index = 0; |
| 253 List<Node> valueReferences = <Node>[]; | 254 List<Node> valueReferences = <Node>[]; |
| 254 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; | 255 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; |
| 255 for (Link<Node> link = node.names.nodes; !link.isEmpty; link = link.tail) { | 256 for (Link<Node> link = node.names.nodes; !link.isEmpty; link = link.tail) { |
| 256 Identifier name = link.head; | 257 Identifier name = link.head; |
| 257 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); | 258 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 Modifiers.EMPTY, | 302 Modifiers.EMPTY, |
| 302 'toString', | 303 'toString', |
| 303 null, // typeVariables | 304 null, // typeVariables |
| 304 builder.argumentList([]), | 305 builder.argumentList([]), |
| 305 builder.returnStatement(builder.indexGet( | 306 builder.returnStatement(builder.indexGet( |
| 306 builder.mapLiteral(mapEntries, isConst: true), | 307 builder.mapLiteral(mapEntries, isConst: true), |
| 307 builder.reference(builder.identifier('index'))))); | 308 builder.reference(builder.identifier('index'))))); |
| 308 | 309 |
| 309 EnumMethodElementX toString = new EnumMethodElementX( | 310 EnumMethodElementX toString = new EnumMethodElementX( |
| 310 'toString', enumClass, Modifiers.EMPTY, toStringNode); | 311 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
| 311 FunctionSignatureX toStringSignature = | 312 FunctionSignatureX toStringSignature = new FunctionSignatureX( |
| 312 new FunctionSignatureX(type: new FunctionType(toString, stringType)); | 313 type: new ResolutionFunctionType(toString, stringType)); |
| 313 toString.functionSignature = toStringSignature; | 314 toString.functionSignature = toStringSignature; |
| 314 enumClass.addMember(toString, reporter); | 315 enumClass.addMember(toString, reporter); |
| 315 | 316 |
| 316 enumClass.enumValues = enumValues; | 317 enumClass.enumValues = enumValues; |
| 317 } | 318 } |
| 318 } | 319 } |
| OLD | NEW |