 Chromium Code Reviews
 Chromium Code Reviews Issue 11348316:
  Move the handling of operator[] into the new interceptors.  (Closed) 
  Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
    
  
    Issue 11348316:
  Move the handling of operator[] into the new interceptors.  (Closed) 
  Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/| OLD | NEW | 
|---|---|
| 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 native; | 5 library native; | 
| 6 | 6 | 
| 7 import 'dart:uri'; | 7 import 'dart:uri'; | 
| 8 import 'dart2jslib.dart' hide SourceString; | 8 import 'dart2jslib.dart' hide SourceString; | 
| 9 import 'elements/elements.dart'; | 9 import 'elements/elements.dart'; | 
| 10 import 'js_backend/js_backend.dart'; | 10 import 'js_backend/js_backend.dart'; | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 final bool enableLiveTypeAnalysis; | 95 final bool enableLiveTypeAnalysis; | 
| 96 | 96 | 
| 97 ClassElement _annotationCreatesClass; | 97 ClassElement _annotationCreatesClass; | 
| 98 ClassElement _annotationReturnsClass; | 98 ClassElement _annotationReturnsClass; | 
| 99 ClassElement _annotationJsNameClass; | 99 ClassElement _annotationJsNameClass; | 
| 100 | 100 | 
| 101 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 101 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 
| 102 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); | 102 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); | 
| 103 | 103 | 
| 104 void processNativeClasses(Collection<LibraryElement> libraries) { | 104 void processNativeClasses(Collection<LibraryElement> libraries) { | 
| 105 libraries.forEach(processNativeClassesInLibrary); | 105 libraries.forEach(processNativeClassesInLibrary); | 
| 
sra1
2012/12/10 23:42:21
After adding all the native classes, you will need
 
ngeoffray
2012/12/11 09:30:15
Done.
 | |
| 106 if (!enableLiveTypeAnalysis) { | 106 if (!enableLiveTypeAnalysis) { | 
| 107 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); | 107 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); | 
| 108 flushQueue(); | 108 flushQueue(); | 
| 109 } | 109 } | 
| 110 } | 110 } | 
| 111 | 111 | 
| 112 void processNativeClassesInLibrary(LibraryElement library) { | 112 void processNativeClassesInLibrary(LibraryElement library) { | 
| 113 // Use implementation to ensure the inclusion of injected members. | 113 // Use implementation to ensure the inclusion of injected members. | 
| 114 library.implementation.forEachLocalMember((Element element) { | 114 library.implementation.forEachLocalMember((Element element) { | 
| 115 if (element.kind == ElementKind.CLASS) { | 115 if (element.kind == ElementKind.CLASS) { | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } else { | 181 } else { | 
| 182 PartialMetadataAnnotation partial = annotation; | 182 PartialMetadataAnnotation partial = annotation; | 
| 183 compiler.cancel( | 183 compiler.cancel( | 
| 184 'Too many JSName annotations: ${partial.parseNode(compiler)}'); | 184 'Too many JSName annotations: ${partial.parseNode(compiler)}'); | 
| 185 } | 185 } | 
| 186 } | 186 } | 
| 187 return name; | 187 return name; | 
| 188 } | 188 } | 
| 189 | 189 | 
| 190 enqueueClass(ClassElement classElement, cause) { | 190 enqueueClass(ClassElement classElement, cause) { | 
| 191 assert(unusedClasses.contains(classElement)); | 191 assert(unusedClasses.contains(classElement)); | 
| 
sra1
2012/12/10 23:42:21
I don't know why this is not firing for you.
 | |
| 192 unusedClasses.remove(classElement); | 192 unusedClasses.remove(classElement); | 
| 193 pendingClasses.add(classElement); | 193 pendingClasses.add(classElement); | 
| 194 queue.add(() { processClass(classElement, cause); }); | 194 queue.add(() { processClass(classElement, cause); }); | 
| 195 } | 195 } | 
| 196 | 196 | 
| 197 void flushQueue() { | 197 void flushQueue() { | 
| 198 if (flushing) return; | 198 if (flushing) return; | 
| 199 flushing = true; | 199 flushing = true; | 
| 200 while (!queue.isEmpty) { | 200 while (!queue.isEmpty) { | 
| 201 (queue.removeFirst())(); | 201 (queue.removeFirst())(); | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 } | 304 } | 
| 305 | 305 | 
| 306 processNativeBehavior(NativeBehavior behavior, cause) { | 306 processNativeBehavior(NativeBehavior behavior, cause) { | 
| 307 bool allUsedBefore = unusedClasses.isEmpty; | 307 bool allUsedBefore = unusedClasses.isEmpty; | 
| 308 for (var type in behavior.typesInstantiated) { | 308 for (var type in behavior.typesInstantiated) { | 
| 309 if (matchedTypeConstraints.contains(type)) continue; | 309 if (matchedTypeConstraints.contains(type)) continue; | 
| 310 matchedTypeConstraints.add(type); | 310 matchedTypeConstraints.add(type); | 
| 311 if (type is SpecialType) { | 311 if (type is SpecialType) { | 
| 312 if (type == SpecialType.JsArray) { | 312 if (type == SpecialType.JsArray) { | 
| 313 world.registerInstantiatedClass(compiler.listClass); | 313 world.registerInstantiatedClass(compiler.listClass); | 
| 314 enqueueClass(compiler.listClass, 'core type'); | |
| 
sra1
2012/12/10 23:42:21
Line before this should be unnecessary, since enqu
 
ngeoffray
2012/12/11 09:30:15
Done.
 | |
| 314 } else if (type == SpecialType.JsObject) { | 315 } else if (type == SpecialType.JsObject) { | 
| 315 world.registerInstantiatedClass(compiler.objectClass); | 316 world.registerInstantiatedClass(compiler.objectClass); | 
| 317 enqueueClass(compiler.objectClass, 'core type'); | |
| 316 } | 318 } | 
| 317 continue; | 319 continue; | 
| 318 } | 320 } | 
| 319 if (type is InterfaceType) { | 321 if (type is InterfaceType) { | 
| 320 if (type.element == compiler.intClass) { | 322 if (type.element == compiler.intClass) { | 
| 321 world.registerInstantiatedClass(compiler.intClass); | 323 world.registerInstantiatedClass(compiler.intClass); | 
| 322 } else if (type.element == compiler.doubleClass) { | 324 } else if (type.element == compiler.doubleClass) { | 
| 323 world.registerInstantiatedClass(compiler.doubleClass); | 325 world.registerInstantiatedClass(compiler.doubleClass); | 
| 324 } else if (type.element == compiler.numClass) { | 326 } else if (type.element == compiler.numClass) { | 
| 325 world.registerInstantiatedClass(compiler.numClass); | 327 world.registerInstantiatedClass(compiler.numClass); | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 class NativeCodegenEnqueuer extends NativeEnqueuerBase { | 394 class NativeCodegenEnqueuer extends NativeEnqueuerBase { | 
| 393 | 395 | 
| 394 final CodeEmitterTask emitter; | 396 final CodeEmitterTask emitter; | 
| 395 | 397 | 
| 396 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); | 398 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); | 
| 397 | 399 | 
| 398 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) | 400 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) | 
| 399 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); | 401 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); | 
| 400 | 402 | 
| 401 void processNativeClasses(Collection<LibraryElement> libraries) { | 403 void processNativeClasses(Collection<LibraryElement> libraries) { | 
| 402 super.processNativeClasses(libraries); | |
| 
sra1
2012/12/10 23:42:21
Removing this will mess up --disable-native-live-t
 | |
| 403 | |
| 404 // HACK HACK - add all the resolved classes. | 404 // HACK HACK - add all the resolved classes. | 
| 405 NativeEnqueuerBase enqueuer = compiler.enqueuer.resolution.nativeEnqueuer; | 405 NativeEnqueuerBase enqueuer = compiler.enqueuer.resolution.nativeEnqueuer; | 
| 406 for (final classElement in enqueuer.registeredClasses) { | 406 for (final classElement in enqueuer.registeredClasses) { | 
| 407 if (unusedClasses.contains(classElement)) { | 407 enqueueClass(classElement, 'was resolved'); | 
| 408 enqueueClass(classElement, 'was resolved'); | |
| 409 } | |
| 410 } | 408 } | 
| 411 flushQueue(); | 409 flushQueue(); | 
| 412 } | 410 } | 
| 413 | 411 | 
| 414 processClass(ClassElement classElement, cause) { | 412 processClass(ClassElement classElement, cause) { | 
| 415 super.processClass(classElement, cause); | 413 super.processClass(classElement, cause); | 
| 416 // Add the information that this class is a subtype of its supertypes. The | 414 // Add the information that this class is a subtype of its supertypes. The | 
| 417 // code emitter and the ssa builder use that information. | 415 // code emitter and the ssa builder use that information. | 
| 418 addSubtypes(classElement, emitter.nativeEmitter); | 416 addSubtypes(classElement, emitter.nativeEmitter); | 
| 419 } | 417 } | 
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 builder.add(new HForeign( | 899 builder.add(new HForeign( | 
| 902 new DartString.literal('${parameter.name.slowToString()} = #'), | 900 new DartString.literal('${parameter.name.slowToString()} = #'), | 
| 903 const LiteralDartString('void'), | 901 const LiteralDartString('void'), | 
| 904 <HInstruction>[jsClosure])); | 902 <HInstruction>[jsClosure])); | 
| 905 } | 903 } | 
| 906 }); | 904 }); | 
| 907 LiteralString jsCode = nativeBody.asLiteralString(); | 905 LiteralString jsCode = nativeBody.asLiteralString(); | 
| 908 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 906 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 
| 909 } | 907 } | 
| 910 } | 908 } | 
| OLD | NEW |