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:collection' show Queue; | 7 import 'dart:collection' show Queue; |
8 import 'dart:uri'; | 8 import 'dart:uri'; |
9 import 'dart2jslib.dart' hide SourceString; | 9 import 'dart2jslib.dart' hide SourceString; |
10 import 'dart_types.dart'; | 10 import 'dart_types.dart'; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 flushing = false; | 211 flushing = false; |
212 } | 212 } |
213 | 213 |
214 processClass(ClassElement classElement, cause) { | 214 processClass(ClassElement classElement, cause) { |
215 assert(!registeredClasses.contains(classElement)); | 215 assert(!registeredClasses.contains(classElement)); |
216 | 216 |
217 bool firstTime = registeredClasses.isEmpty; | 217 bool firstTime = registeredClasses.isEmpty; |
218 pendingClasses.remove(classElement); | 218 pendingClasses.remove(classElement); |
219 registeredClasses.add(classElement); | 219 registeredClasses.add(classElement); |
220 | 220 |
221 world.registerInstantiatedClass(classElement); | 221 world.registerInstantiatedClass(classElement, compiler.globalDependencies); |
222 | 222 |
223 // Also parse the node to know all its methods because otherwise it will | 223 // Also parse the node to know all its methods because otherwise it will |
224 // only be parsed if there is a call to one of its constructors. | 224 // only be parsed if there is a call to one of its constructors. |
225 classElement.parseNode(compiler); | 225 classElement.parseNode(compiler); |
226 | 226 |
227 if (firstTime) { | 227 if (firstTime) { |
228 queue.add(onFirstNativeClass); | 228 queue.add(onFirstNativeClass); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 315 |
316 NativeBehavior getNativeBehaviorOf(Send node) => nativeBehaviors[node]; | 316 NativeBehavior getNativeBehaviorOf(Send node) => nativeBehaviors[node]; |
317 | 317 |
318 processNativeBehavior(NativeBehavior behavior, cause) { | 318 processNativeBehavior(NativeBehavior behavior, cause) { |
319 bool allUsedBefore = unusedClasses.isEmpty; | 319 bool allUsedBefore = unusedClasses.isEmpty; |
320 for (var type in behavior.typesInstantiated) { | 320 for (var type in behavior.typesInstantiated) { |
321 if (matchedTypeConstraints.contains(type)) continue; | 321 if (matchedTypeConstraints.contains(type)) continue; |
322 matchedTypeConstraints.add(type); | 322 matchedTypeConstraints.add(type); |
323 if (type is SpecialType) { | 323 if (type is SpecialType) { |
324 if (type == SpecialType.JsArray) { | 324 if (type == SpecialType.JsArray) { |
325 world.registerInstantiatedClass(compiler.listClass); | 325 world.registerInstantiatedClass(compiler.listClass, |
| 326 compiler.globalDependencies); |
326 } else if (type == SpecialType.JsObject) { | 327 } else if (type == SpecialType.JsObject) { |
327 world.registerInstantiatedClass(compiler.objectClass); | 328 world.registerInstantiatedClass(compiler.objectClass, |
| 329 compiler.globalDependencies); |
328 } | 330 } |
329 continue; | 331 continue; |
330 } | 332 } |
331 if (type is InterfaceType) { | 333 if (type is InterfaceType) { |
332 if (type.element == compiler.intClass) { | 334 if (type.element == compiler.intClass) { |
333 world.registerInstantiatedClass(compiler.intClass); | 335 world.registerInstantiatedClass( |
| 336 compiler.intClass, compiler.globalDependencies); |
334 } else if (type.element == compiler.doubleClass) { | 337 } else if (type.element == compiler.doubleClass) { |
335 world.registerInstantiatedClass(compiler.doubleClass); | 338 world.registerInstantiatedClass( |
| 339 compiler.doubleClass, compiler.globalDependencies); |
336 } else if (type.element == compiler.numClass) { | 340 } else if (type.element == compiler.numClass) { |
337 world.registerInstantiatedClass(compiler.doubleClass); | 341 world.registerInstantiatedClass( |
338 world.registerInstantiatedClass(compiler.intClass); | 342 compiler.doubleClass, compiler.globalDependencies); |
| 343 world.registerInstantiatedClass( |
| 344 compiler.intClass, compiler.globalDependencies); |
339 } else if (type.element == compiler.stringClass) { | 345 } else if (type.element == compiler.stringClass) { |
340 world.registerInstantiatedClass(compiler.stringClass); | 346 world.registerInstantiatedClass( |
| 347 compiler.stringClass, compiler.globalDependencies); |
341 } else if (type.element == compiler.nullClass) { | 348 } else if (type.element == compiler.nullClass) { |
342 world.registerInstantiatedClass(compiler.nullClass); | 349 world.registerInstantiatedClass( |
| 350 compiler.nullClass, compiler.globalDependencies); |
343 } else if (type.element == compiler.boolClass) { | 351 } else if (type.element == compiler.boolClass) { |
344 world.registerInstantiatedClass(compiler.boolClass); | 352 world.registerInstantiatedClass( |
| 353 compiler.boolClass, compiler.globalDependencies); |
345 } | 354 } |
346 } | 355 } |
347 assert(type is DartType); | 356 assert(type is DartType); |
348 enqueueUnusedClassesMatching( | 357 enqueueUnusedClassesMatching( |
349 (nativeClass) => compiler.types.isSubtype(nativeClass.thisType, type), | 358 (nativeClass) => compiler.types.isSubtype(nativeClass.thisType, type), |
350 cause, | 359 cause, |
351 'subtypeof($type)'); | 360 'subtypeof($type)'); |
352 } | 361 } |
353 | 362 |
354 // Give an info so that library developers can compile with -v to find why | 363 // Give an info so that library developers can compile with -v to find why |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 } else { | 904 } else { |
896 if (parameters.parameterCount != 0) { | 905 if (parameters.parameterCount != 0) { |
897 compiler.cancel( | 906 compiler.cancel( |
898 'native "..." syntax is restricted to functions with zero parameters', | 907 'native "..." syntax is restricted to functions with zero parameters', |
899 node: nativeBody); | 908 node: nativeBody); |
900 } | 909 } |
901 LiteralString jsCode = nativeBody.asLiteralString(); | 910 LiteralString jsCode = nativeBody.asLiteralString(); |
902 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 911 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
903 } | 912 } |
904 } | 913 } |
OLD | NEW |