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

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 /**
ahe 2013/08/13 18:31:47 Add newline before comment.
sra1 2013/08/14 04:36:47 Done.
204 * This element is a top-level variable that the compiler initializes to a
ahe 2013/08/13 18:31:47 Consider: ... top-level variable (in generated ou
sra1 2013/08/14 04:36:47 Done.
205 * datastructure used to map from a Type to the interceptor. See declaration
206 * of `mapTypeToInterceptor` in `interceptors.dart`.
207 */
208 Element mapTypeToInterceptor;
203 209
204 HType stringType; 210 HType stringType;
205 HType indexablePrimitiveType; 211 HType indexablePrimitiveType;
206 HType readableArrayType; 212 HType readableArrayType;
207 HType mutableArrayType; 213 HType mutableArrayType;
208 HType fixedArrayType; 214 HType fixedArrayType;
209 HType extendableArrayType; 215 HType extendableArrayType;
210 216
211 // TODO(9577): Make it so that these are not needed when there are no native 217 // TODO(9577): Make it so that these are not needed when there are no native
212 // classes. 218 // classes.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 355 }
350 356
351 static Namer determineNamer(Compiler compiler) { 357 static Namer determineNamer(Compiler compiler) {
352 return compiler.enableMinification ? 358 return compiler.enableMinification ?
353 new MinifyNamer(compiler) : 359 new MinifyNamer(compiler) :
354 new Namer(compiler); 360 new Namer(compiler);
355 } 361 }
356 362
357 bool isInterceptorClass(ClassElement element) { 363 bool isInterceptorClass(ClassElement element) {
358 if (element == null) return false; 364 if (element == null) return false;
359 if (element.isNative()) return true; 365 if (Elements.isNativeOrExtendsNative(element)) return true;
360 if (interceptedClasses.contains(element)) return true; 366 if (interceptedClasses.contains(element)) return true;
361 if (classesMixedIntoNativeClasses.contains(element)) return true; 367 if (classesMixedIntoNativeClasses.contains(element)) return true;
362 return false; 368 return false;
363 } 369 }
364 370
365 String registerOneShotInterceptor(Selector selector) { 371 String registerOneShotInterceptor(Selector selector) {
366 Set<ClassElement> classes = getInterceptedClassesOn(selector.name); 372 Set<ClassElement> classes = getInterceptedClassesOn(selector.name);
367 String name = namer.getOneShotInterceptorName(selector, classes); 373 String name = namer.getOneShotInterceptorName(selector, classes);
368 if (!oneShotInterceptors.containsKey(name)) { 374 if (!oneShotInterceptors.containsKey(name)) {
369 registerSpecializedGetInterceptor(classes); 375 registerSpecializedGetInterceptor(classes);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 */ 411 */
406 Set<ClassElement> getInterceptedClassesOn(SourceString name) { 412 Set<ClassElement> getInterceptedClassesOn(SourceString name) {
407 Set<Element> intercepted = interceptedElements[name]; 413 Set<Element> intercepted = interceptedElements[name];
408 if (intercepted == null) return null; 414 if (intercepted == null) return null;
409 return interceptedClassesCache.putIfAbsent(name, () { 415 return interceptedClassesCache.putIfAbsent(name, () {
410 // Populate the cache by running through all the elements and 416 // Populate the cache by running through all the elements and
411 // determine if the given selector applies to them. 417 // determine if the given selector applies to them.
412 Set<ClassElement> result = new Set<ClassElement>(); 418 Set<ClassElement> result = new Set<ClassElement>();
413 for (Element element in intercepted) { 419 for (Element element in intercepted) {
414 ClassElement classElement = element.getEnclosingClass(); 420 ClassElement classElement = element.getEnclosingClass();
415 if (classElement.isNative() 421 if (Elements.isNativeOrExtendsNative(classElement)
416 || interceptedClasses.contains(classElement)) { 422 || interceptedClasses.contains(classElement)) {
417 result.add(classElement); 423 result.add(classElement);
418 } 424 }
419 if (classesMixedIntoNativeClasses.contains(classElement)) { 425 if (classesMixedIntoNativeClasses.contains(classElement)) {
420 Set<ClassElement> nativeSubclasses = 426 Set<ClassElement> nativeSubclasses =
421 nativeSubclassesOfMixin(classElement); 427 nativeSubclassesOfMixin(classElement);
422 if (nativeSubclasses != null) result.addAll(nativeSubclasses); 428 if (nativeSubclasses != null) result.addAll(nativeSubclasses);
423 } 429 }
424 } 430 }
425 return result; 431 return result;
(...skipping 21 matching lines...) Expand all
447 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { 453 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) {
448 return specialOperatorEqClasses.contains( 454 return specialOperatorEqClasses.contains(
449 operatorEqfunction.getEnclosingClass()); 455 operatorEqfunction.getEnclosingClass());
450 } 456 }
451 457
452 void initializeHelperClasses() { 458 void initializeHelperClasses() {
453 getInterceptorMethod = 459 getInterceptorMethod =
454 compiler.findInterceptor(const SourceString('getInterceptor')); 460 compiler.findInterceptor(const SourceString('getInterceptor'));
455 interceptedNames = 461 interceptedNames =
456 compiler.findInterceptor(const SourceString('interceptedNames')); 462 compiler.findInterceptor(const SourceString('interceptedNames'));
463 mapTypeToInterceptor =
464 compiler.findInterceptor(const SourceString('mapTypeToInterceptor'));
457 dispatchPropertyName = 465 dispatchPropertyName =
458 compiler.findInterceptor(const SourceString('dispatchPropertyName')); 466 compiler.findInterceptor(const SourceString('dispatchPropertyName'));
459 getDispatchPropertyMethod = 467 getDispatchPropertyMethod =
460 compiler.findInterceptor(const SourceString('getDispatchProperty')); 468 compiler.findInterceptor(const SourceString('getDispatchProperty'));
461 setDispatchPropertyMethod = 469 setDispatchPropertyMethod =
462 compiler.findInterceptor(const SourceString('setDispatchProperty')); 470 compiler.findInterceptor(const SourceString('setDispatchProperty'));
463 getNativeInterceptorMethod = 471 getNativeInterceptorMethod =
464 compiler.findInterceptor(const SourceString('getNativeInterceptor')); 472 compiler.findInterceptor(const SourceString('getNativeInterceptor'));
465 initializeDispatchPropertyMethod = 473 initializeDispatchPropertyMethod =
466 compiler.findInterceptor( 474 compiler.findInterceptor(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 if (enqueuer.isResolutionQueue) { 595 if (enqueuer.isResolutionQueue) {
588 cls.ensureResolved(compiler); 596 cls.ensureResolved(compiler);
589 cls.forEachMember((ClassElement classElement, Element member) { 597 cls.forEachMember((ClassElement classElement, Element member) {
590 if (member.isSynthesized) return; 598 if (member.isSynthesized) return;
591 // All methods on [Object] are shadowed by [Interceptor]. 599 // All methods on [Object] are shadowed by [Interceptor].
592 if (classElement == compiler.objectClass) return; 600 if (classElement == compiler.objectClass) return;
593 Set<Element> set = interceptedElements.putIfAbsent( 601 Set<Element> set = interceptedElements.putIfAbsent(
594 member.name, () => new Set<Element>()); 602 member.name, () => new Set<Element>());
595 set.add(member); 603 set.add(member);
596 if (classElement == jsInterceptorClass) return; 604 if (classElement == jsInterceptorClass) return;
597 if (!classElement.isNative()) { 605 if (classElement.isMixinApplication) {
598 MixinApplicationElement mixinApplication = classElement; 606 MixinApplicationElement mixinApplication = classElement;
599 assert(member.getEnclosingClass() == mixinApplication.mixin); 607 assert(member.getEnclosingClass() == mixinApplication.mixin);
600 classesMixedIntoNativeClasses.add(mixinApplication.mixin); 608 classesMixedIntoNativeClasses.add(mixinApplication.mixin);
601 } 609 }
602 }, 610 },
603 includeSuperAndInjectedMembers: true); 611 includeSuperAndInjectedMembers: true);
604 } 612 }
605 } 613 }
606 614
607 void addInterceptors(ClassElement cls, 615 void addInterceptors(ClassElement cls,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } else if (cls == compiler.nullClass || cls == jsNullClass) { 704 } else if (cls == compiler.nullClass || cls == jsNullClass) {
697 addInterceptors(jsNullClass, enqueuer, elements); 705 addInterceptors(jsNullClass, enqueuer, elements);
698 } else if (cls == compiler.numClass || cls == jsNumberClass) { 706 } else if (cls == compiler.numClass || cls == jsNumberClass) {
699 addInterceptors(jsIntClass, enqueuer, elements); 707 addInterceptors(jsIntClass, enqueuer, elements);
700 addInterceptors(jsDoubleClass, enqueuer, elements); 708 addInterceptors(jsDoubleClass, enqueuer, elements);
701 addInterceptors(jsNumberClass, enqueuer, elements); 709 addInterceptors(jsNumberClass, enqueuer, elements);
702 } else if (cls == jsPlainJavaScriptObjectClass) { 710 } else if (cls == jsPlainJavaScriptObjectClass) {
703 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements); 711 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, elements);
704 } else if (cls == jsUnknownJavaScriptObjectClass) { 712 } else if (cls == jsUnknownJavaScriptObjectClass) {
705 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements); 713 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, elements);
706 } else if (cls.isNative()) { 714 } else if (Elements.isNativeOrExtendsNative(cls)) {
707 addInterceptorsForNativeClassMembers(cls, enqueuer); 715 addInterceptorsForNativeClassMembers(cls, enqueuer);
708 } 716 }
709 } 717 }
710 718
711 void registerUseInterceptor(Enqueuer enqueuer) { 719 void registerUseInterceptor(Enqueuer enqueuer) {
712 assert(!enqueuer.isResolutionQueue); 720 assert(!enqueuer.isResolutionQueue);
713 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; 721 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return;
714 enqueuer.registerStaticUse(getNativeInterceptorMethod); 722 enqueuer.registerStaticUse(getNativeInterceptorMethod);
715 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod); 723 enqueuer.registerStaticUse(defineNativeMethodsFinishMethod);
716 enqueuer.registerStaticUse(initializeDispatchPropertyMethod); 724 enqueuer.registerStaticUse(initializeDispatchPropertyMethod);
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 } 1525 }
1518 } 1526 }
1519 1527
1520 /// Records that [type] is used by [user.element]. 1528 /// Records that [type] is used by [user.element].
1521 class Dependency { 1529 class Dependency {
1522 final DartType type; 1530 final DartType type;
1523 final TreeElements user; 1531 final TreeElements user;
1524 1532
1525 const Dependency(this.type, this.user); 1533 const Dependency(this.type, this.user);
1526 } 1534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698