OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 universe; | 5 library universe; |
6 | 6 |
7 import '../elements/elements.dart'; | 7 import '../elements/elements.dart'; |
8 import '../dart2jslib.dart'; | 8 import '../dart2jslib.dart'; |
9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
10 import '../types/types.dart'; | 10 import '../types/types.dart'; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 kind, name, library, argumentCount, | 179 kind, name, library, argumentCount, |
180 namedArguments, orderedNamedArguments, | 180 namedArguments, orderedNamedArguments, |
181 hashCode); | 181 hashCode); |
182 list.add(result); | 182 list.add(result); |
183 return result; | 183 return result; |
184 } | 184 } |
185 | 185 |
186 factory Selector.fromElement(Element element, Compiler compiler) { | 186 factory Selector.fromElement(Element element, Compiler compiler) { |
187 String name = element.name; | 187 String name = element.name; |
188 if (element.isFunction()) { | 188 if (element.isFunction()) { |
189 int arity = element.asFunctionElement().requiredParameterCount(compiler); | |
190 if (name == '[]') { | 189 if (name == '[]') { |
191 return new Selector.index(); | 190 return new Selector.index(); |
192 } else if (name == '[]=') { | 191 } else if (name == '[]=') { |
193 return new Selector.indexSet(); | 192 return new Selector.indexSet(); |
194 } else if (Elements.operatorNameToIdentifier(name) != name) { | 193 } |
195 return new Selector(SelectorKind.OPERATOR, name, null, arity); | 194 FunctionSignature signature = |
| 195 element.asFunctionElement().computeSignature(compiler); |
| 196 int arity = signature.parameterCount; |
| 197 List<String> namedArguments = null; |
| 198 if (signature.optionalParametersAreNamed) { |
| 199 namedArguments = |
| 200 signature.orderedOptionalParameters.map((e) => e.name).toList(); |
| 201 } |
| 202 if (Elements.operatorNameToIdentifier(name) != name) { |
| 203 // Operators cannot have named arguments, however, that doesn't prevent |
| 204 // a user from declaring such an operator. |
| 205 return new Selector( |
| 206 SelectorKind.OPERATOR, name, null, arity, namedArguments); |
196 } else { | 207 } else { |
197 return new Selector.call(name, element.getLibrary(), arity); | 208 return new Selector.call( |
| 209 name, element.getLibrary(), arity, namedArguments); |
198 } | 210 } |
199 } else if (element.isSetter()) { | 211 } else if (element.isSetter()) { |
200 return new Selector.setter(name, element.getLibrary()); | 212 return new Selector.setter(name, element.getLibrary()); |
201 } else if (element.isGetter()) { | 213 } else if (element.isGetter()) { |
202 return new Selector.getter(name, element.getLibrary()); | 214 return new Selector.getter(name, element.getLibrary()); |
203 } else if (element.isField()) { | 215 } else if (element.isField()) { |
204 return new Selector.getter(name, element.getLibrary()); | 216 return new Selector.getter(name, element.getLibrary()); |
| 217 } else { |
| 218 throw new SpannableAssertionFailure( |
| 219 element, "Can't get selector from $element"); |
205 } | 220 } |
206 } | 221 } |
207 | 222 |
208 factory Selector.getter(String name, LibraryElement library) | 223 factory Selector.getter(String name, LibraryElement library) |
209 => new Selector(SelectorKind.GETTER, name, library, 0); | 224 => new Selector(SelectorKind.GETTER, name, library, 0); |
210 | 225 |
211 factory Selector.getterFrom(Selector selector) | 226 factory Selector.getterFrom(Selector selector) |
212 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); | 227 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); |
213 | 228 |
214 factory Selector.setter(String name, LibraryElement library) | 229 factory Selector.setter(String name, LibraryElement library) |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 String type = ''; | 598 String type = ''; |
584 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; | 599 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; |
585 if (mask != null) type = ', mask=$mask'; | 600 if (mask != null) type = ', mask=$mask'; |
586 return 'Selector($kind, $name, ' | 601 return 'Selector($kind, $name, ' |
587 'arity=$argumentCount$named$type)'; | 602 'arity=$argumentCount$named$type)'; |
588 } | 603 } |
589 | 604 |
590 Selector extendIfReachesAll(Compiler compiler) { | 605 Selector extendIfReachesAll(Compiler compiler) { |
591 return new TypedSelector(compiler.typesTask.dynamicType, this); | 606 return new TypedSelector(compiler.typesTask.dynamicType, this); |
592 } | 607 } |
| 608 |
| 609 Selector toCallSelector() => new Selector.callClosureFrom(this); |
593 } | 610 } |
594 | 611 |
595 class TypedSelector extends Selector { | 612 class TypedSelector extends Selector { |
596 final Selector asUntyped; | 613 final Selector asUntyped; |
597 final TypeMask mask; | 614 final TypeMask mask; |
598 | 615 |
599 TypedSelector.internal(this.mask, Selector selector, int hashCode) | 616 TypedSelector.internal(this.mask, Selector selector, int hashCode) |
600 : asUntyped = selector, | 617 : asUntyped = selector, |
601 super.internal(selector.kind, | 618 super.internal(selector.kind, |
602 selector.name, | 619 selector.name, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 } | 671 } |
655 | 672 |
656 Selector extendIfReachesAll(Compiler compiler) { | 673 Selector extendIfReachesAll(Compiler compiler) { |
657 bool canReachAll = compiler.enabledInvokeOn | 674 bool canReachAll = compiler.enabledInvokeOn |
658 && mask.needsNoSuchMethodHandling(this, compiler); | 675 && mask.needsNoSuchMethodHandling(this, compiler); |
659 return canReachAll | 676 return canReachAll |
660 ? new TypedSelector(compiler.typesTask.dynamicType, this) | 677 ? new TypedSelector(compiler.typesTask.dynamicType, this) |
661 : this; | 678 : this; |
662 } | 679 } |
663 } | 680 } |
OLD | NEW |