| 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); |
| 189 if (name == '[]') { | 190 if (name == '[]') { |
| 190 return new Selector.index(); | 191 return new Selector.index(); |
| 191 } else if (name == '[]=') { | 192 } else if (name == '[]=') { |
| 192 return new Selector.indexSet(); | 193 return new Selector.indexSet(); |
| 193 } | 194 } else if (Elements.operatorNameToIdentifier(name) != name) { |
| 194 FunctionSignature signature = | 195 return new Selector(SelectorKind.OPERATOR, name, null, arity); |
| 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); | |
| 207 } else { | 196 } else { |
| 208 return new Selector.call( | 197 return new Selector.call(name, element.getLibrary(), arity); |
| 209 name, element.getLibrary(), arity, namedArguments); | |
| 210 } | 198 } |
| 211 } else if (element.isSetter()) { | 199 } else if (element.isSetter()) { |
| 212 return new Selector.setter(name, element.getLibrary()); | 200 return new Selector.setter(name, element.getLibrary()); |
| 213 } else if (element.isGetter()) { | 201 } else if (element.isGetter()) { |
| 214 return new Selector.getter(name, element.getLibrary()); | 202 return new Selector.getter(name, element.getLibrary()); |
| 215 } else if (element.isField()) { | 203 } else if (element.isField()) { |
| 216 return new Selector.getter(name, element.getLibrary()); | 204 return new Selector.getter(name, element.getLibrary()); |
| 217 } else { | |
| 218 throw new SpannableAssertionFailure( | |
| 219 element, "Can't get selector from $element"); | |
| 220 } | 205 } |
| 221 } | 206 } |
| 222 | 207 |
| 223 factory Selector.getter(String name, LibraryElement library) | 208 factory Selector.getter(String name, LibraryElement library) |
| 224 => new Selector(SelectorKind.GETTER, name, library, 0); | 209 => new Selector(SelectorKind.GETTER, name, library, 0); |
| 225 | 210 |
| 226 factory Selector.getterFrom(Selector selector) | 211 factory Selector.getterFrom(Selector selector) |
| 227 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); | 212 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); |
| 228 | 213 |
| 229 factory Selector.setter(String name, LibraryElement library) | 214 factory Selector.setter(String name, LibraryElement library) |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 String type = ''; | 583 String type = ''; |
| 599 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; | 584 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; |
| 600 if (mask != null) type = ', mask=$mask'; | 585 if (mask != null) type = ', mask=$mask'; |
| 601 return 'Selector($kind, $name, ' | 586 return 'Selector($kind, $name, ' |
| 602 'arity=$argumentCount$named$type)'; | 587 'arity=$argumentCount$named$type)'; |
| 603 } | 588 } |
| 604 | 589 |
| 605 Selector extendIfReachesAll(Compiler compiler) { | 590 Selector extendIfReachesAll(Compiler compiler) { |
| 606 return new TypedSelector(compiler.typesTask.dynamicType, this); | 591 return new TypedSelector(compiler.typesTask.dynamicType, this); |
| 607 } | 592 } |
| 608 | |
| 609 Selector toCallSelector() => new Selector.callClosureFrom(this); | |
| 610 } | 593 } |
| 611 | 594 |
| 612 class TypedSelector extends Selector { | 595 class TypedSelector extends Selector { |
| 613 final Selector asUntyped; | 596 final Selector asUntyped; |
| 614 final TypeMask mask; | 597 final TypeMask mask; |
| 615 | 598 |
| 616 TypedSelector.internal(this.mask, Selector selector, int hashCode) | 599 TypedSelector.internal(this.mask, Selector selector, int hashCode) |
| 617 : asUntyped = selector, | 600 : asUntyped = selector, |
| 618 super.internal(selector.kind, | 601 super.internal(selector.kind, |
| 619 selector.name, | 602 selector.name, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 654 } |
| 672 | 655 |
| 673 Selector extendIfReachesAll(Compiler compiler) { | 656 Selector extendIfReachesAll(Compiler compiler) { |
| 674 bool canReachAll = compiler.enabledInvokeOn | 657 bool canReachAll = compiler.enabledInvokeOn |
| 675 && mask.needsNoSuchMethodHandling(this, compiler); | 658 && mask.needsNoSuchMethodHandling(this, compiler); |
| 676 return canReachAll | 659 return canReachAll |
| 677 ? new TypedSelector(compiler.typesTask.dynamicType, this) | 660 ? new TypedSelector(compiler.typesTask.dynamicType, this) |
| 678 : this; | 661 : this; |
| 679 } | 662 } |
| 680 } | 663 } |
| OLD | NEW |