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

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

Issue 15026006: Support for extending native classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months 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 part of js_backend; 5 part of js_backend;
6 6
7 class JavaScriptItemCompilationContext extends ItemCompilationContext { 7 class JavaScriptItemCompilationContext extends ItemCompilationContext {
8 final Set<HInstruction> boundsChecked; 8 final Set<HInstruction> boundsChecked;
9 9
10 JavaScriptItemCompilationContext() 10 JavaScriptItemCompilationContext()
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 Element jsStringConcat; 193 Element jsStringConcat;
194 Element jsStringToString; 194 Element jsStringToString;
195 Element objectEquals; 195 Element objectEquals;
196 196
197 ClassElement typeLiteralClass; 197 ClassElement typeLiteralClass;
198 ClassElement mapLiteralClass; 198 ClassElement mapLiteralClass;
199 ClassElement constMapLiteralClass; 199 ClassElement constMapLiteralClass;
200 200
201 Element getInterceptorMethod; 201 Element getInterceptorMethod;
202 Element interceptedNames; 202 Element interceptedNames;
203 Element mapTypeToInterceptor;
ahe 2013/08/12 20:47:35 Please document this field.
sra1 2013/08/12 23:06:14 Done.
203 204
204 HType stringType; 205 HType stringType;
205 HType indexablePrimitiveType; 206 HType indexablePrimitiveType;
206 HType readableArrayType; 207 HType readableArrayType;
207 HType mutableArrayType; 208 HType mutableArrayType;
208 HType fixedArrayType; 209 HType fixedArrayType;
209 HType extendableArrayType; 210 HType extendableArrayType;
210 211
211 // TODO(9577): Make it so that these are not needed when there are no native 212 // TODO(9577): Make it so that these are not needed when there are no native
212 // classes. 213 // classes.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 350 }
350 351
351 static Namer determineNamer(Compiler compiler) { 352 static Namer determineNamer(Compiler compiler) {
352 return compiler.enableMinification ? 353 return compiler.enableMinification ?
353 new MinifyNamer(compiler) : 354 new MinifyNamer(compiler) :
354 new Namer(compiler); 355 new Namer(compiler);
355 } 356 }
356 357
357 bool isInterceptorClass(ClassElement element) { 358 bool isInterceptorClass(ClassElement element) {
358 if (element == null) return false; 359 if (element == null) return false;
359 if (element.isNative()) return true; 360 if (Elements.isNativeOrExtendsNative(element)) return true;
360 if (interceptedClasses.contains(element)) return true; 361 if (interceptedClasses.contains(element)) return true;
361 if (classesMixedIntoNativeClasses.contains(element)) return true; 362 if (classesMixedIntoNativeClasses.contains(element)) return true;
362 return false; 363 return false;
363 } 364 }
364 365
365 String registerOneShotInterceptor(Selector selector) { 366 String registerOneShotInterceptor(Selector selector) {
366 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); 367 Set<ClassElement> classes = getInterceptedClassesOn(selector.name);
367 String name = namer.getOneShotInterceptorName(selector, classes); 368 String name = namer.getOneShotInterceptorName(selector, classes);
368 if (!oneShotInterceptors.containsKey(name)) { 369 if (!oneShotInterceptors.containsKey(name)) {
369 registerSpecializedGetInterceptor(classes); 370 registerSpecializedGetInterceptor(classes);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 */ 406 */
406 Set<ClassElement> getInterceptedClassesOn(SourceString name) { 407 Set<ClassElement> getInterceptedClassesOn(SourceString name) {
407 Set<Element> intercepted = interceptedElements[name]; 408 Set<Element> intercepted = interceptedElements[name];
408 if (intercepted == null) return null; 409 if (intercepted == null) return null;
409 return interceptedClassesCache.putIfAbsent(name, () { 410 return interceptedClassesCache.putIfAbsent(name, () {
410 // Populate the cache by running through all the elements and 411 // Populate the cache by running through all the elements and
411 // determine if the given selector applies to them. 412 // determine if the given selector applies to them.
412 Set<ClassElement> result = new Set<ClassElement>(); 413 Set<ClassElement> result = new Set<ClassElement>();
413 for (Element element in intercepted) { 414 for (Element element in intercepted) {
414 ClassElement classElement = element.getEnclosingClass(); 415 ClassElement classElement = element.getEnclosingClass();
415 if (classElement.isNative() 416 if (Elements.isNativeOrExtendsNative(classElement)
416 || interceptedClasses.contains(classElement)) { 417 || interceptedClasses.contains(classElement)) {
417 result.add(classElement); 418 result.add(classElement);
418 } 419 }
419 if (classesMixedIntoNativeClasses.contains(classElement)) { 420 if (classesMixedIntoNativeClasses.contains(classElement)) {
420 Set<ClassElement> nativeSubclasses = 421 Set<ClassElement> nativeSubclasses =
421 nativeSubclassesOfMixin(classElement); 422 nativeSubclassesOfMixin(classElement);
422 if (nativeSubclasses != null) result.addAll(nativeSubclasses); 423 if (nativeSubclasses != null) result.addAll(nativeSubclasses);
423 } 424 }
424 } 425 }
425 return result; 426 return result;
(...skipping 21 matching lines...) Expand all
447 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { 448 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) {
448 return specialOperatorEqClasses.contains( 449 return specialOperatorEqClasses.contains(
449 operatorEqfunction.getEnclosingClass()); 450 operatorEqfunction.getEnclosingClass());
450 } 451 }
451 452
452 void initializeHelperClasses() { 453 void initializeHelperClasses() {
453 getInterceptorMethod = 454 getInterceptorMethod =
454 compiler.findInterceptor(const SourceString('getInterceptor')); 455 compiler.findInterceptor(const SourceString('getInterceptor'));
455 interceptedNames = 456 interceptedNames =
456 compiler.findInterceptor(const SourceString('interceptedNames')); 457 compiler.findInterceptor(const SourceString('interceptedNames'));
458 mapTypeToInterceptor =
459 compiler.findInterceptor(const SourceString('mapTypeToInterceptor'));
457 dispatchPropertyName = 460 dispatchPropertyName =
458 compiler.findInterceptor(const SourceString('dispatchPropertyName')); 461 compiler.findInterceptor(const SourceString('dispatchPropertyName'));
459 getDispatchPropertyMethod = 462 getDispatchPropertyMethod =
460 compiler.findInterceptor(const SourceString('getDispatchProperty')); 463 compiler.findInterceptor(const SourceString('getDispatchProperty'));
461 setDispatchPropertyMethod = 464 setDispatchPropertyMethod =
462 compiler.findInterceptor(const SourceString('setDispatchProperty')); 465 compiler.findInterceptor(const SourceString('setDispatchProperty'));
463 getNativeInterceptorMethod = 466 getNativeInterceptorMethod =
464 compiler.findInterceptor(const SourceString('getNativeInterceptor')); 467 compiler.findInterceptor(const SourceString('getNativeInterceptor'));
465 initializeDispatchPropertyMethod = 468 initializeDispatchPropertyMethod =
466 compiler.findInterceptor( 469 compiler.findInterceptor(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if (enqueuer.isResolutionQueue) { 590 if (enqueuer.isResolutionQueue) {
588 cls.ensureResolved(compiler); 591 cls.ensureResolved(compiler);
589 cls.forEachMember((ClassElement classElement, Element member) { 592 cls.forEachMember((ClassElement classElement, Element member) {
590 if (member.isSynthesized) return; 593 if (member.isSynthesized) return;
591 // All methods on [Object] are shadowed by [Interceptor]. 594 // All methods on [Object] are shadowed by [Interceptor].
592 if (classElement == compiler.objectClass) return; 595 if (classElement == compiler.objectClass) return;
593 Set<Element> set = interceptedElements.putIfAbsent( 596 Set<Element> set = interceptedElements.putIfAbsent(
594 member.name, () => new Set<Element>()); 597 member.name, () => new Set<Element>());
595 set.add(member); 598 set.add(member);
596 if (classElement == jsInterceptorClass) return; 599 if (classElement == jsInterceptorClass) return;
597 if (!classElement.isNative()) { 600 if (classElement.isMixinApplication) {
598 MixinApplicationElement mixinApplication = classElement; 601 MixinApplicationElement mixinApplication = classElement;
599 assert(member.getEnclosingClass() == mixinApplication.mixin); 602 assert(member.getEnclosingClass() == mixinApplication.mixin);
600 classesMixedIntoNativeClasses.add(mixinApplication.mixin); 603 classesMixedIntoNativeClasses.add(mixinApplication.mixin);
601 } 604 }
602 }, 605 },
603 includeSuperAndInjectedMembers: true); 606 includeSuperAndInjectedMembers: true);
604 } 607 }
605 } 608 }
606 609
607 void addInterceptors(ClassElement cls, 610 void addInterceptors(ClassElement cls,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } else if (cls == compiler.nullClass || cls == jsNullClass) { 699 } else if (cls == compiler.nullClass || cls == jsNullClass) {
697 addInterceptors(jsNullClass, enqueuer, elements); 700 addInterceptors(jsNullClass, enqueuer, elements);
698 } else if (cls == compiler.numClass || cls == jsNumberClass) { 701 } else if (cls == compiler.numClass || cls == jsNumberClass) {
699 addInterceptors(jsIntClass, enqueuer, elements); 702 addInterceptors(jsIntClass, enqueuer, elements);
700 addInterceptors(jsDoubleClass, enqueuer, elements); 703 addInterceptors(jsDoubleClass, enqueuer, elements);
701 addInterceptors(jsNumberClass, enqueuer, elements); 704 addInterceptors(jsNumberClass, enqueuer, elements);
702 } else if (cls == jsPlainJavaScriptObjectClass) { 705 } else if (cls == jsPlainJavaScriptObjectClass) {
703 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements); 706 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements);
704 } else if (cls == jsUnknownJavaScriptObjectClass) { 707 } else if (cls == jsUnknownJavaScriptObjectClass) {
705 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements); 708 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements);
706 } else if (cls.isNative()) { 709 //} else if (cls.isNative()) {
ahe 2013/08/12 20:47:35 Remove comment.
sra1 2013/08/12 23:06:14 Done.
710 } else if (Elements.isNativeOrExtendsNative(cls)) {
707 addInterceptorsForNativeClassMembers(cls, enqueuer); 711 addInterceptorsForNativeClassMembers(cls, enqueuer);
708 } 712 }
709 } 713 }
710 714
711 void registerUseInterceptor(Enqueuer enqueuer) { 715 void registerUseInterceptor(Enqueuer enqueuer) {
712 assert(!enqueuer.isResolutionQueue); 716 assert(!enqueuer.isResolutionQueue);
713 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; 717 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return;
714 enqueuer.registerStaticUse(getNativeInterceptorMethod); 718 enqueuer.registerStaticUse(getNativeInterceptorMethod);
715 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod); 719 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod);
716 enqueuer.registerStaticUse(initializeDispatchPropertyMethod); 720 enqueuer.registerStaticUse(initializeDispatchPropertyMethod);
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 } 1521 }
1518 } 1522 }
1519 1523
1520 /// Records that [type] is used by [user.element]. 1524 /// Records that [type] is used by [user.element].
1521 class Dependency { 1525 class Dependency {
1522 final DartType type; 1526 final DartType type;
1523 final TreeElements user; 1527 final TreeElements user;
1524 1528
1525 const Dependency(this.type, this.user); 1529 const Dependency(this.type, this.user);
1526 } 1530 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698