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

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

Issue 26472002: Add TypeVariable object on runtime to support reflection on type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const SourceString('propertyTypeCast')), 399 const SourceString('propertyTypeCast')),
400 const PropertyCheckedModeHelper( 400 const PropertyCheckedModeHelper(
401 const SourceString('propertyTypeCheck')) ]; 401 const SourceString('propertyTypeCheck')) ];
402 402
403 // Checked mode helpers indexed by name. 403 // Checked mode helpers indexed by name.
404 Map<String, CheckedModeHelper> checkedModeHelperByName = 404 Map<String, CheckedModeHelper> checkedModeHelperByName =
405 new Map<String, CheckedModeHelper>.fromIterable( 405 new Map<String, CheckedModeHelper>.fromIterable(
406 checkedModeHelpers, 406 checkedModeHelpers,
407 key: (helper) => helper.name.slowToString()); 407 key: (helper) => helper.name.slowToString());
408 408
409 TypeVariableConstantHandler typeVarHandler;
ahe 2013/10/14 13:07:07 Rename to typeVariableHandler (please don't abbrev
zarah 2013/10/15 14:20:02 Done.
410
409 /// Number of methods compiled before considering reflection. 411 /// Number of methods compiled before considering reflection.
410 int preMirrorsMethodCount = 0; 412 int preMirrorsMethodCount = 0;
411 413
412 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 414 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
413 : namer = determineNamer(compiler), 415 : namer = determineNamer(compiler),
414 oneShotInterceptors = new Map<String, Selector>(), 416 oneShotInterceptors = new Map<String, Selector>(),
415 interceptedElements = new Map<SourceString, Set<Element>>(), 417 interceptedElements = new Map<SourceString, Set<Element>>(),
416 rti = new RuntimeTypes(compiler), 418 rti = new RuntimeTypes(compiler),
417 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 419 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
418 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { 420 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) {
419 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); 421 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap);
420 builder = new SsaBuilderTask(this); 422 builder = new SsaBuilderTask(this);
421 optimizer = new SsaOptimizerTask(this); 423 optimizer = new SsaOptimizerTask(this);
422 generator = new SsaCodeGeneratorTask(this); 424 generator = new SsaCodeGeneratorTask(this);
425 typeVarHandler = new TypeVariableConstantHandler(this);
423 } 426 }
424 427
425 static Namer determineNamer(Compiler compiler) { 428 static Namer determineNamer(Compiler compiler) {
426 return compiler.enableMinification ? 429 return compiler.enableMinification ?
427 new MinifyNamer(compiler) : 430 new MinifyNamer(compiler) :
428 new Namer(compiler); 431 new Namer(compiler);
429 } 432 }
430 433
431 bool usedByBackend(Element element) { 434 bool usedByBackend(Element element) {
432 if (element.isParameter() 435 if (element.isParameter()
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 indexablePrimitiveType = new HBoundedType( 659 indexablePrimitiveType = new HBoundedType(
657 new TypeMask.nonNullSubtype(jsIndexableClass)); 660 new TypeMask.nonNullSubtype(jsIndexableClass));
658 readableArrayType = new HBoundedType( 661 readableArrayType = new HBoundedType(
659 new TypeMask.nonNullSubclass(jsArrayClass)); 662 new TypeMask.nonNullSubclass(jsArrayClass));
660 mutableArrayType = new HBoundedType( 663 mutableArrayType = new HBoundedType(
661 new TypeMask.nonNullSubclass(jsMutableArrayClass)); 664 new TypeMask.nonNullSubclass(jsMutableArrayClass));
662 fixedArrayType = new HBoundedType( 665 fixedArrayType = new HBoundedType(
663 new TypeMask.nonNullExact(jsFixedArrayClass)); 666 new TypeMask.nonNullExact(jsFixedArrayClass));
664 extendableArrayType = new HBoundedType( 667 extendableArrayType = new HBoundedType(
665 new TypeMask.nonNullExact(jsExtendableArrayClass)); 668 new TypeMask.nonNullExact(jsExtendableArrayClass));
669
670 typeVarHandler.initializeHelperClass();
ahe 2013/10/14 13:07:07 I think I would prefer if the helper class was ini
zarah 2013/10/15 14:20:02 Done.
666 } 671 }
667 672
668 void validateInterceptorImplementsAllObjectMethods( 673 void validateInterceptorImplementsAllObjectMethods(
669 ClassElement interceptorClass) { 674 ClassElement interceptorClass) {
670 if (interceptorClass == null) return; 675 if (interceptorClass == null) return;
671 interceptorClass.ensureResolved(compiler); 676 interceptorClass.ensureResolved(compiler);
672 compiler.objectClass.forEachMember((_, Element member) { 677 compiler.objectClass.forEachMember((_, Element member) {
673 if (member.isGenerativeConstructor()) return; 678 if (member.isGenerativeConstructor()) return;
674 Element interceptorMember = interceptorClass.lookupMember(member.name); 679 Element interceptorMember = interceptorClass.lookupMember(member.name);
675 // Interceptors must override all Object methods due to calling convention 680 // Interceptors must override all Object methods due to calling convention
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 if (mustRetainMetadata) { 788 if (mustRetainMetadata) {
784 registerCompileTimeConstant(constant, elements); 789 registerCompileTimeConstant(constant, elements);
785 } else { 790 } else {
786 metadataConstants.add(new Dependency(constant, elements)); 791 metadataConstants.add(new Dependency(constant, elements));
787 } 792 }
788 } 793 }
789 794
790 void registerInstantiatedClass(ClassElement cls, 795 void registerInstantiatedClass(ClassElement cls,
791 Enqueuer enqueuer, 796 Enqueuer enqueuer,
792 TreeElements elements) { 797 TreeElements elements) {
798 if (!cls.typeVariables.isEmpty) {
799 typeVarHandler.registerClassWithTypeVars(cls);
800 }
801
793 if (!seenAnyClass) { 802 if (!seenAnyClass) {
794 seenAnyClass = true; 803 seenAnyClass = true;
795 if (enqueuer.isResolutionQueue) { 804 if (enqueuer.isResolutionQueue) {
796 // TODO(9577): Make it so that these are not needed when there are no 805 // TODO(9577): Make it so that these are not needed when there are no
797 // native classes. 806 // native classes.
798 enqueue(enqueuer, getNativeInterceptorMethod, elements); 807 enqueue(enqueuer, getNativeInterceptorMethod, elements);
799 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements); 808 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements);
800 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); 809 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies);
801 } 810 }
802 } 811 }
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 if (mustRetainMetadata) { 1808 if (mustRetainMetadata) {
1800 compiler.log('Retaining metadata.'); 1809 compiler.log('Retaining metadata.');
1801 1810
1802 compiler.libraries.values.forEach(retainMetadataOf); 1811 compiler.libraries.values.forEach(retainMetadataOf);
1803 for (Dependency dependency in metadataConstants) { 1812 for (Dependency dependency in metadataConstants) {
1804 registerCompileTimeConstant( 1813 registerCompileTimeConstant(
1805 dependency.constant, dependency.user); 1814 dependency.constant, dependency.user);
1806 } 1815 }
1807 metadataConstants.clear(); 1816 metadataConstants.clear();
1808 } 1817 }
1818
1819 if (isTreeShakingDisabled) {
1820 if (enqueuer.isResolutionQueue) {
1821 typeVarHandler.onResolutionQueueEmpty(enqueuer);
1822 } else {
1823 typeVarHandler.onCodegenQueueEmpty();
1824 }
1825 }
1809 } 1826 }
1810 } 1827 }
1811 1828
1812 /// Records that [constant] is used by [user.element]. 1829 /// Records that [constant] is used by [user.element].
1813 class Dependency { 1830 class Dependency {
1814 final Constant constant; 1831 final Constant constant;
1815 final TreeElements user; 1832 final TreeElements user;
1816 1833
1817 const Dependency(this.constant, this.user); 1834 const Dependency(this.constant, this.user);
1818 } 1835 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 copy(constant.values); 1875 copy(constant.values);
1859 copy(constant.protoValue); 1876 copy(constant.protoValue);
1860 copy(constant); 1877 copy(constant);
1861 } 1878 }
1862 1879
1863 void visitConstructed(ConstructedConstant constant) { 1880 void visitConstructed(ConstructedConstant constant) {
1864 copy(constant.fields); 1881 copy(constant.fields);
1865 copy(constant); 1882 copy(constant);
1866 } 1883 }
1867 } 1884 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698