| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 NodeList argumentList(List<Node> nodes) { | 75 NodeList argumentList(List<Node> nodes) { |
| 76 return new NodeList(symbolToken(Precedence.OPEN_PAREN_INFO), | 76 return new NodeList(symbolToken(Precedence.OPEN_PAREN_INFO), |
| 77 linkedList(nodes), symbolToken(Precedence.CLOSE_PAREN_INFO), ','); | 77 linkedList(nodes), symbolToken(Precedence.CLOSE_PAREN_INFO), ','); |
| 78 } | 78 } |
| 79 | 79 |
| 80 Return returnStatement(Expression expression) { | 80 Return returnStatement(Expression expression) { |
| 81 return new Return(keywordToken('return'), | 81 return new Return(keywordToken('return'), |
| 82 symbolToken(Precedence.SEMICOLON_INFO), expression); | 82 symbolToken(Precedence.SEMICOLON_INFO), expression); |
| 83 } | 83 } |
| 84 | 84 |
| 85 FunctionExpression functionExpression( | 85 FunctionExpression functionExpression(Modifiers modifiers, String name, |
| 86 Modifiers modifiers, String name, NodeList argumentList, Statement body, | 86 NodeList typeVariables, NodeList argumentList, Statement body, |
| 87 [TypeAnnotation returnType]) { | 87 [TypeAnnotation returnType]) { |
| 88 return new FunctionExpression( | 88 return new FunctionExpression( |
| 89 identifier(name), | 89 identifier(name), |
| 90 typeVariables, |
| 90 argumentList, | 91 argumentList, |
| 91 body, | 92 body, |
| 92 returnType, | 93 returnType, |
| 93 modifiers, | 94 modifiers, |
| 94 null, // Initializer. | 95 null, // Initializer. |
| 95 null, // get/set. | 96 null, // get/set. |
| 96 null // Async modifier. | 97 null // Async modifier. |
| 97 ); | 98 ); |
| 98 } | 99 } |
| 99 | 100 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return variable; | 223 return variable; |
| 223 } | 224 } |
| 224 | 225 |
| 225 EnumFieldElementX indexVariable = addInstanceMember('index', intType); | 226 EnumFieldElementX indexVariable = addInstanceMember('index', intType); |
| 226 | 227 |
| 227 VariableDefinitions indexDefinition = builder.initializingFormal('index'); | 228 VariableDefinitions indexDefinition = builder.initializingFormal('index'); |
| 228 | 229 |
| 229 FunctionExpression constructorNode = builder.functionExpression( | 230 FunctionExpression constructorNode = builder.functionExpression( |
| 230 builder.modifiers(isConst: true), | 231 builder.modifiers(isConst: true), |
| 231 enumClass.name, | 232 enumClass.name, |
| 233 null, // typeVariables |
| 232 builder.argumentList([indexDefinition]), | 234 builder.argumentList([indexDefinition]), |
| 233 builder.emptyStatement()); | 235 builder.emptyStatement()); |
| 234 | 236 |
| 235 EnumConstructorElementX constructor = new EnumConstructorElementX( | 237 EnumConstructorElementX constructor = new EnumConstructorElementX( |
| 236 enumClass, builder.modifiers(isConst: true), constructorNode); | 238 enumClass, builder.modifiers(isConst: true), constructorNode); |
| 237 | 239 |
| 238 EnumFormalElementX indexFormal = new EnumFormalElementX(constructor, | 240 EnumFormalElementX indexFormal = new EnumFormalElementX(constructor, |
| 239 indexDefinition, builder.identifier('index'), indexVariable); | 241 indexDefinition, builder.identifier('index'), indexVariable); |
| 240 | 242 |
| 241 FunctionSignatureX constructorSignature = new FunctionSignatureX( | 243 FunctionSignatureX constructorSignature = new FunctionSignatureX( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 EnumFieldElementX valuesVariable = new EnumFieldElementX(valuesIdentifier, | 293 EnumFieldElementX valuesVariable = new EnumFieldElementX(valuesIdentifier, |
| 292 enumClass, valuesVariableList, definition, initializer); | 294 enumClass, valuesVariableList, definition, initializer); |
| 293 | 295 |
| 294 enumClass.addMember(valuesVariable, reporter); | 296 enumClass.addMember(valuesVariable, reporter); |
| 295 | 297 |
| 296 // TODO(johnniwinther): Support return type. Note `String` might be prefixed | 298 // TODO(johnniwinther): Support return type. Note `String` might be prefixed |
| 297 // or not imported within the current library. | 299 // or not imported within the current library. |
| 298 FunctionExpression toStringNode = builder.functionExpression( | 300 FunctionExpression toStringNode = builder.functionExpression( |
| 299 Modifiers.EMPTY, | 301 Modifiers.EMPTY, |
| 300 'toString', | 302 'toString', |
| 303 null, // typeVariables |
| 301 builder.argumentList([]), | 304 builder.argumentList([]), |
| 302 builder.returnStatement(builder.indexGet( | 305 builder.returnStatement(builder.indexGet( |
| 303 builder.mapLiteral(mapEntries, isConst: true), | 306 builder.mapLiteral(mapEntries, isConst: true), |
| 304 builder.reference(builder.identifier('index'))))); | 307 builder.reference(builder.identifier('index'))))); |
| 305 | 308 |
| 306 EnumMethodElementX toString = new EnumMethodElementX( | 309 EnumMethodElementX toString = new EnumMethodElementX( |
| 307 'toString', enumClass, Modifiers.EMPTY, toStringNode); | 310 'toString', enumClass, Modifiers.EMPTY, toStringNode); |
| 308 FunctionSignatureX toStringSignature = | 311 FunctionSignatureX toStringSignature = |
| 309 new FunctionSignatureX(type: new FunctionType(toString, stringType)); | 312 new FunctionSignatureX(type: new FunctionType(toString, stringType)); |
| 310 toString.functionSignature = toStringSignature; | 313 toString.functionSignature = toStringSignature; |
| 311 enumClass.addMember(toString, reporter); | 314 enumClass.addMember(toString, reporter); |
| 312 | 315 |
| 313 enumClass.enumValues = enumValues; | 316 enumClass.enumValues = enumValues; |
| 314 } | 317 } |
| 315 } | 318 } |
| OLD | NEW |