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