| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 : <String>[]; | 185 : <String>[]; |
| 186 Selector result = new Selector.internal( | 186 Selector result = new Selector.internal( |
| 187 kind, name, library, argumentCount, | 187 kind, name, library, argumentCount, |
| 188 namedArguments, orderedNamedArguments, | 188 namedArguments, orderedNamedArguments, |
| 189 hashCode); | 189 hashCode); |
| 190 list.add(result); | 190 list.add(result); |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 | 193 |
| 194 factory Selector.fromElement(Element element, Compiler compiler) { | 194 factory Selector.fromElement(Element element, Compiler compiler) { |
| 195 // TODO(ahe): This method doesn't work as one might expect if there are |
| 196 // optional arguments. |
| 195 String name = element.name; | 197 String name = element.name; |
| 196 if (element.isFunction()) { | 198 if (element.isFunction()) { |
| 197 int arity = element.asFunctionElement().requiredParameterCount(compiler); | |
| 198 if (name == '[]') { | 199 if (name == '[]') { |
| 199 return new Selector.index(); | 200 return new Selector.index(); |
| 200 } else if (name == '[]=') { | 201 } else if (name == '[]=') { |
| 201 return new Selector.indexSet(); | 202 return new Selector.indexSet(); |
| 202 } else if (Elements.operatorNameToIdentifier(name) != name) { | 203 } |
| 203 return new Selector(SelectorKind.OPERATOR, name, null, arity); | 204 FunctionSignature signature = |
| 205 element.asFunctionElement().computeSignature(compiler); |
| 206 int arity = signature.parameterCount; |
| 207 List<String> namedArguments = null; |
| 208 if (signature.optionalParametersAreNamed) { |
| 209 namedArguments = |
| 210 signature.orderedOptionalParameters.map((e) => e.name).toList(); |
| 211 } |
| 212 if (Elements.operatorNameToIdentifier(name) != name) { |
| 213 // Operators cannot have named arguments, however, that doesn't prevent |
| 214 // a user from declaring such an operator. |
| 215 return new Selector( |
| 216 SelectorKind.OPERATOR, name, null, arity, namedArguments); |
| 204 } else { | 217 } else { |
| 205 return new Selector.call(name, element.getLibrary(), arity); | 218 return new Selector.call( |
| 219 name, element.getLibrary(), arity, namedArguments); |
| 206 } | 220 } |
| 207 } else if (element.isSetter()) { | 221 } else if (element.isSetter()) { |
| 208 return new Selector.setter(name, element.getLibrary()); | 222 return new Selector.setter(name, element.getLibrary()); |
| 209 } else if (element.isGetter()) { | 223 } else if (element.isGetter()) { |
| 210 return new Selector.getter(name, element.getLibrary()); | 224 return new Selector.getter(name, element.getLibrary()); |
| 211 } else if (element.isField()) { | 225 } else if (element.isField()) { |
| 212 return new Selector.getter(name, element.getLibrary()); | 226 return new Selector.getter(name, element.getLibrary()); |
| 227 } else { |
| 228 throw new SpannableAssertionFailure( |
| 229 element, "Can't get selector from $element"); |
| 213 } | 230 } |
| 214 } | 231 } |
| 215 | 232 |
| 216 factory Selector.getter(String name, LibraryElement library) | 233 factory Selector.getter(String name, LibraryElement library) |
| 217 => new Selector(SelectorKind.GETTER, name, library, 0); | 234 => new Selector(SelectorKind.GETTER, name, library, 0); |
| 218 | 235 |
| 219 factory Selector.getterFrom(Selector selector) | 236 factory Selector.getterFrom(Selector selector) |
| 220 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); | 237 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); |
| 221 | 238 |
| 222 factory Selector.setter(String name, LibraryElement library) | 239 factory Selector.setter(String name, LibraryElement library) |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 String type = ''; | 609 String type = ''; |
| 593 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; | 610 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; |
| 594 if (mask != null) type = ', mask=$mask'; | 611 if (mask != null) type = ', mask=$mask'; |
| 595 return 'Selector($kind, $name, ' | 612 return 'Selector($kind, $name, ' |
| 596 'arity=$argumentCount$named$type)'; | 613 'arity=$argumentCount$named$type)'; |
| 597 } | 614 } |
| 598 | 615 |
| 599 Selector extendIfReachesAll(Compiler compiler) { | 616 Selector extendIfReachesAll(Compiler compiler) { |
| 600 return new TypedSelector(compiler.typesTask.dynamicType, this); | 617 return new TypedSelector(compiler.typesTask.dynamicType, this); |
| 601 } | 618 } |
| 619 |
| 620 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 602 } | 621 } |
| 603 | 622 |
| 604 class TypedSelector extends Selector { | 623 class TypedSelector extends Selector { |
| 605 final Selector asUntyped; | 624 final Selector asUntyped; |
| 606 final TypeMask mask; | 625 final TypeMask mask; |
| 607 | 626 |
| 608 TypedSelector.internal(this.mask, Selector selector, int hashCode) | 627 TypedSelector.internal(this.mask, Selector selector, int hashCode) |
| 609 : asUntyped = selector, | 628 : asUntyped = selector, |
| 610 super.internal(selector.kind, | 629 super.internal(selector.kind, |
| 611 selector.name, | 630 selector.name, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 682 } |
| 664 | 683 |
| 665 Selector extendIfReachesAll(Compiler compiler) { | 684 Selector extendIfReachesAll(Compiler compiler) { |
| 666 bool canReachAll = compiler.enabledInvokeOn | 685 bool canReachAll = compiler.enabledInvokeOn |
| 667 && mask.needsNoSuchMethodHandling(this, compiler); | 686 && mask.needsNoSuchMethodHandling(this, compiler); |
| 668 return canReachAll | 687 return canReachAll |
| 669 ? new TypedSelector(compiler.typesTask.dynamicType, this) | 688 ? new TypedSelector(compiler.typesTask.dynamicType, this) |
| 670 : this; | 689 : this; |
| 671 } | 690 } |
| 672 } | 691 } |
| OLD | NEW |