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

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: Addressed comments. 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 Element jsArrayRemoveLast; 193 Element jsArrayRemoveLast;
194 Element jsArrayAdd; 194 Element jsArrayAdd;
195 Element jsStringSplit; 195 Element jsStringSplit;
196 Element jsStringToString; 196 Element jsStringToString;
197 Element jsStringOperatorAdd; 197 Element jsStringOperatorAdd;
198 Element objectEquals; 198 Element objectEquals;
199 199
200 ClassElement typeLiteralClass; 200 ClassElement typeLiteralClass;
201 ClassElement mapLiteralClass; 201 ClassElement mapLiteralClass;
202 ClassElement constMapLiteralClass; 202 ClassElement constMapLiteralClass;
203 ClassElement typeVariableClass;
203 204
204 Element getInterceptorMethod; 205 Element getInterceptorMethod;
205 Element interceptedNames; 206 Element interceptedNames;
206 207
207 /** 208 /**
208 * This element is a top-level variable (in generated output) that the 209 * This element is a top-level variable (in generated output) that the
209 * compiler initializes to a datastructure used to map from a Type to the 210 * compiler initializes to a datastructure used to map from a Type to the
210 * interceptor. See declaration of `mapTypeToInterceptor` in 211 * interceptor. See declaration of `mapTypeToInterceptor` in
211 * `interceptors.dart`. 212 * `interceptors.dart`.
212 */ 213 */
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const SourceString('propertyTypeCast')), 400 const SourceString('propertyTypeCast')),
400 const PropertyCheckedModeHelper( 401 const PropertyCheckedModeHelper(
401 const SourceString('propertyTypeCheck')) ]; 402 const SourceString('propertyTypeCheck')) ];
402 403
403 // Checked mode helpers indexed by name. 404 // Checked mode helpers indexed by name.
404 Map<String, CheckedModeHelper> checkedModeHelperByName = 405 Map<String, CheckedModeHelper> checkedModeHelperByName =
405 new Map<String, CheckedModeHelper>.fromIterable( 406 new Map<String, CheckedModeHelper>.fromIterable(
406 checkedModeHelpers, 407 checkedModeHelpers,
407 key: (helper) => helper.name.slowToString()); 408 key: (helper) => helper.name.slowToString());
408 409
410 TypeVariableHandler typeVariableHandler;
411
409 /// Number of methods compiled before considering reflection. 412 /// Number of methods compiled before considering reflection.
410 int preMirrorsMethodCount = 0; 413 int preMirrorsMethodCount = 0;
411 414
412 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 415 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
413 : namer = determineNamer(compiler), 416 : namer = determineNamer(compiler),
414 oneShotInterceptors = new Map<String, Selector>(), 417 oneShotInterceptors = new Map<String, Selector>(),
415 interceptedElements = new Map<SourceString, Set<Element>>(), 418 interceptedElements = new Map<SourceString, Set<Element>>(),
416 rti = new RuntimeTypes(compiler), 419 rti = new RuntimeTypes(compiler),
417 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 420 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
418 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { 421 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) {
419 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); 422 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap);
420 builder = new SsaBuilderTask(this); 423 builder = new SsaBuilderTask(this);
421 optimizer = new SsaOptimizerTask(this); 424 optimizer = new SsaOptimizerTask(this);
422 generator = new SsaCodeGeneratorTask(this); 425 generator = new SsaCodeGeneratorTask(this);
426 typeVariableHandler = new TypeVariableHandler(this);
423 } 427 }
424 428
425 static Namer determineNamer(Compiler compiler) { 429 static Namer determineNamer(Compiler compiler) {
426 return compiler.enableMinification ? 430 return compiler.enableMinification ?
427 new MinifyNamer(compiler) : 431 new MinifyNamer(compiler) :
428 new Namer(compiler); 432 new Namer(compiler);
429 } 433 }
430 434
431 bool usedByBackend(Element element) { 435 bool usedByBackend(Element element) {
432 if (element.isParameter() 436 if (element.isParameter()
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 indexablePrimitiveType = new HBoundedType( 662 indexablePrimitiveType = new HBoundedType(
659 new TypeMask.nonNullSubtype(jsIndexableClass)); 663 new TypeMask.nonNullSubtype(jsIndexableClass));
660 readableArrayType = new HBoundedType( 664 readableArrayType = new HBoundedType(
661 new TypeMask.nonNullSubclass(jsArrayClass)); 665 new TypeMask.nonNullSubclass(jsArrayClass));
662 mutableArrayType = new HBoundedType( 666 mutableArrayType = new HBoundedType(
663 new TypeMask.nonNullSubclass(jsMutableArrayClass)); 667 new TypeMask.nonNullSubclass(jsMutableArrayClass));
664 fixedArrayType = new HBoundedType( 668 fixedArrayType = new HBoundedType(
665 new TypeMask.nonNullExact(jsFixedArrayClass)); 669 new TypeMask.nonNullExact(jsFixedArrayClass));
666 extendableArrayType = new HBoundedType( 670 extendableArrayType = new HBoundedType(
667 new TypeMask.nonNullExact(jsExtendableArrayClass)); 671 new TypeMask.nonNullExact(jsExtendableArrayClass));
672
673 typeVariableClass =
674 compiler.findHelper(const SourceString('TypeVariable'));
668 } 675 }
669 676
670 void validateInterceptorImplementsAllObjectMethods( 677 void validateInterceptorImplementsAllObjectMethods(
671 ClassElement interceptorClass) { 678 ClassElement interceptorClass) {
672 if (interceptorClass == null) return; 679 if (interceptorClass == null) return;
673 interceptorClass.ensureResolved(compiler); 680 interceptorClass.ensureResolved(compiler);
674 compiler.objectClass.forEachMember((_, Element member) { 681 compiler.objectClass.forEachMember((_, Element member) {
675 if (member.isGenerativeConstructor()) return; 682 if (member.isGenerativeConstructor()) return;
676 Element interceptorMember = interceptorClass.lookupMember(member.name); 683 Element interceptorMember = interceptorClass.lookupMember(member.name);
677 // Interceptors must override all Object methods due to calling convention 684 // Interceptors must override all Object methods due to calling convention
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 if (mustRetainMetadata) { 792 if (mustRetainMetadata) {
786 registerCompileTimeConstant(constant, elements); 793 registerCompileTimeConstant(constant, elements);
787 } else { 794 } else {
788 metadataConstants.add(new Dependency(constant, elements)); 795 metadataConstants.add(new Dependency(constant, elements));
789 } 796 }
790 } 797 }
791 798
792 void registerInstantiatedClass(ClassElement cls, 799 void registerInstantiatedClass(ClassElement cls,
793 Enqueuer enqueuer, 800 Enqueuer enqueuer,
794 TreeElements elements) { 801 TreeElements elements) {
802 if (!cls.typeVariables.isEmpty) {
803 typeVariableHandler.registerClassWithTypeVariables(cls);
804 }
805
795 if (!seenAnyClass) { 806 if (!seenAnyClass) {
796 seenAnyClass = true; 807 seenAnyClass = true;
797 if (enqueuer.isResolutionQueue) { 808 if (enqueuer.isResolutionQueue) {
798 // TODO(9577): Make it so that these are not needed when there are no 809 // TODO(9577): Make it so that these are not needed when there are no
799 // native classes. 810 // native classes.
800 enqueue(enqueuer, getNativeInterceptorMethod, elements); 811 enqueue(enqueuer, getNativeInterceptorMethod, elements);
801 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements); 812 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements);
802 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); 813 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies);
803 } 814 }
804 } 815 }
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 if (mustRetainMetadata) { 1858 if (mustRetainMetadata) {
1848 compiler.log('Retaining metadata.'); 1859 compiler.log('Retaining metadata.');
1849 1860
1850 compiler.libraries.values.forEach(retainMetadataOf); 1861 compiler.libraries.values.forEach(retainMetadataOf);
1851 for (Dependency dependency in metadataConstants) { 1862 for (Dependency dependency in metadataConstants) {
1852 registerCompileTimeConstant( 1863 registerCompileTimeConstant(
1853 dependency.constant, dependency.user); 1864 dependency.constant, dependency.user);
1854 } 1865 }
1855 metadataConstants.clear(); 1866 metadataConstants.clear();
1856 } 1867 }
1868
1869 if (isTreeShakingDisabled) {
1870 if (enqueuer.isResolutionQueue) {
1871 typeVariableHandler.onResolutionQueueEmpty(enqueuer);
1872 } else {
1873 typeVariableHandler.onCodegenQueueEmpty();
1874 }
1875 }
1857 } 1876 }
1858 } 1877 }
1859 1878
1860 /// Records that [constant] is used by [user.element]. 1879 /// Records that [constant] is used by [user.element].
1861 class Dependency { 1880 class Dependency {
1862 final Constant constant; 1881 final Constant constant;
1863 final TreeElements user; 1882 final TreeElements user;
1864 1883
1865 const Dependency(this.constant, this.user); 1884 const Dependency(this.constant, this.user);
1866 } 1885 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 copy(constant.values); 1925 copy(constant.values);
1907 copy(constant.protoValue); 1926 copy(constant.protoValue);
1908 copy(constant); 1927 copy(constant);
1909 } 1928 }
1910 1929
1911 void visitConstructed(ConstructedConstant constant) { 1930 void visitConstructed(ConstructedConstant constant) {
1912 copy(constant.fields); 1931 copy(constant.fields);
1913 copy(constant); 1932 copy(constant);
1914 } 1933 }
1915 } 1934 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698