Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/universe/universe.dart

Issue 27524003: Generate tear-off closures dynamically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed unit tests. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 : <String>[]; 177 : <String>[];
178 Selector result = new Selector.internal( 178 Selector result = new Selector.internal(
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 // TODO(ahe): This method doesn't work as one might expect if there are
188 // optional arguments.
Johnni Winther 2013/12/05 11:49:56 How?
ahe 2013/12/06 15:57:54 I think I fixed that below :-)
187 String name = element.name; 189 String name = element.name;
188 if (element.isFunction()) { 190 if (element.isFunction()) {
189 int arity = element.asFunctionElement().requiredParameterCount(compiler);
190 if (name == '[]') { 191 if (name == '[]') {
191 return new Selector.index(); 192 return new Selector.index();
192 } else if (name == '[]=') { 193 } else if (name == '[]=') {
193 return new Selector.indexSet(); 194 return new Selector.indexSet();
194 } else if (Elements.operatorNameToIdentifier(name) != name) { 195 }
195 return new Selector(SelectorKind.OPERATOR, name, null, arity); 196 FunctionSignature signature =
197 element.asFunctionElement().computeSignature(compiler);
198 int arity = signature.parameterCount;
199 List<String> namedArguments = null;
200 if (signature.optionalParametersAreNamed) {
201 namedArguments =
202 signature.orderedOptionalParameters.map((e) => e.name).toList();
203 }
204 if (Elements.operatorNameToIdentifier(name) != name) {
205 // Operators cannot have named arguments, however, that doesn't prevent
206 // a user from declaring such an operator.
207 return new Selector(
208 SelectorKind.OPERATOR, name, null, arity, namedArguments);
196 } else { 209 } else {
197 return new Selector.call(name, element.getLibrary(), arity); 210 return new Selector.call(
211 name, element.getLibrary(), arity, namedArguments);
198 } 212 }
199 } else if (element.isSetter()) { 213 } else if (element.isSetter()) {
200 return new Selector.setter(name, element.getLibrary()); 214 return new Selector.setter(name, element.getLibrary());
201 } else if (element.isGetter()) { 215 } else if (element.isGetter()) {
202 return new Selector.getter(name, element.getLibrary()); 216 return new Selector.getter(name, element.getLibrary());
203 } else if (element.isField()) { 217 } else if (element.isField()) {
204 return new Selector.getter(name, element.getLibrary()); 218 return new Selector.getter(name, element.getLibrary());
219 } else {
220 throw new SpannableAssertionFailure(
221 element, "Can't get selector from $element");
205 } 222 }
206 } 223 }
207 224
208 factory Selector.getter(String name, LibraryElement library) 225 factory Selector.getter(String name, LibraryElement library)
209 => new Selector(SelectorKind.GETTER, name, library, 0); 226 => new Selector(SelectorKind.GETTER, name, library, 0);
210 227
211 factory Selector.getterFrom(Selector selector) 228 factory Selector.getterFrom(Selector selector)
212 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0); 229 => new Selector(SelectorKind.GETTER, selector.name, selector.library, 0);
213 230
214 factory Selector.setter(String name, LibraryElement library) 231 factory Selector.setter(String name, LibraryElement library)
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 String type = ''; 600 String type = '';
584 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}'; 601 if (namedArgumentCount > 0) named = ', named=${namedArgumentsToString()}';
585 if (mask != null) type = ', mask=$mask'; 602 if (mask != null) type = ', mask=$mask';
586 return 'Selector($kind, $name, ' 603 return 'Selector($kind, $name, '
587 'arity=$argumentCount$named$type)'; 604 'arity=$argumentCount$named$type)';
588 } 605 }
589 606
590 Selector extendIfReachesAll(Compiler compiler) { 607 Selector extendIfReachesAll(Compiler compiler) {
591 return new TypedSelector(compiler.typesTask.dynamicType, this); 608 return new TypedSelector(compiler.typesTask.dynamicType, this);
592 } 609 }
610
611 Selector toCallSelector() => new Selector.callClosureFrom(this);
593 } 612 }
594 613
595 class TypedSelector extends Selector { 614 class TypedSelector extends Selector {
596 final Selector asUntyped; 615 final Selector asUntyped;
597 final TypeMask mask; 616 final TypeMask mask;
598 617
599 TypedSelector.internal(this.mask, Selector selector, int hashCode) 618 TypedSelector.internal(this.mask, Selector selector, int hashCode)
600 : asUntyped = selector, 619 : asUntyped = selector,
601 super.internal(selector.kind, 620 super.internal(selector.kind,
602 selector.name, 621 selector.name,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 673 }
655 674
656 Selector extendIfReachesAll(Compiler compiler) { 675 Selector extendIfReachesAll(Compiler compiler) {
657 bool canReachAll = compiler.enabledInvokeOn 676 bool canReachAll = compiler.enabledInvokeOn
658 && mask.needsNoSuchMethodHandling(this, compiler); 677 && mask.needsNoSuchMethodHandling(this, compiler);
659 return canReachAll 678 return canReachAll
660 ? new TypedSelector(compiler.typesTask.dynamicType, this) 679 ? new TypedSelector(compiler.typesTask.dynamicType, this)
661 : this; 680 : this;
662 } 681 }
663 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698