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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 /** | 7 /** |
8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
9 * from the given element. | 9 * from the given element. |
10 */ | 10 */ |
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 Function computeClassFilter() { | 1717 Function computeClassFilter() { |
1718 Set<ClassElement> unneededClasses = new Set<ClassElement>(); | 1718 Set<ClassElement> unneededClasses = new Set<ClassElement>(); |
1719 // The [Bool] class is not marked as abstract, but has a factory | 1719 // The [Bool] class is not marked as abstract, but has a factory |
1720 // constructor that always throws. We never need to emit it. | 1720 // constructor that always throws. We never need to emit it. |
1721 unneededClasses.add(compiler.boolClass); | 1721 unneededClasses.add(compiler.boolClass); |
1722 | 1722 |
1723 // Go over specialized interceptors and then constants to know which | 1723 // Go over specialized interceptors and then constants to know which |
1724 // interceptors are needed. | 1724 // interceptors are needed. |
1725 Set<ClassElement> needed = new Set<ClassElement>(); | 1725 Set<ClassElement> needed = new Set<ClassElement>(); |
1726 backend.specializedGetInterceptors.forEach( | 1726 backend.specializedGetInterceptors.forEach( |
1727 (_, Collection<ClassElement> elements) { | 1727 (_, Iterable<ClassElement> elements) { |
1728 needed.addAll(elements); | 1728 needed.addAll(elements); |
1729 } | 1729 } |
1730 ); | 1730 ); |
1731 | 1731 |
1732 // Add interceptors referenced by constants. | 1732 // Add interceptors referenced by constants. |
1733 ConstantHandler handler = compiler.constantHandler; | 1733 ConstantHandler handler = compiler.constantHandler; |
1734 List<Constant> constants = handler.getConstantsForEmission(); | 1734 List<Constant> constants = handler.getConstantsForEmission(); |
1735 for (Constant constant in constants) { | 1735 for (Constant constant in constants) { |
1736 if (constant is InterceptorConstant) { | 1736 if (constant is InterceptorConstant) { |
1737 needed.add(constant.dispatchedType.element); | 1737 needed.add(constant.dispatchedType.element); |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 } else { | 2408 } else { |
2409 ${mainCall}; | 2409 ${mainCall}; |
2410 } | 2410 } |
2411 } | 2411 } |
2412 """); | 2412 """); |
2413 addComment('END invoke [main].', buffer); | 2413 addComment('END invoke [main].', buffer); |
2414 } | 2414 } |
2415 | 2415 |
2416 void emitGetInterceptorMethod(CodeBuffer buffer, | 2416 void emitGetInterceptorMethod(CodeBuffer buffer, |
2417 String key, | 2417 String key, |
2418 Collection<ClassElement> classes) { | 2418 Iterable<ClassElement> classes) { |
2419 jsAst.Statement buildReturnInterceptor(ClassElement cls) { | 2419 jsAst.Statement buildReturnInterceptor(ClassElement cls) { |
2420 return js.return_(js(namer.isolateAccess(cls))['prototype']); | 2420 return js.return_(js(namer.isolateAccess(cls))['prototype']); |
2421 } | 2421 } |
2422 | 2422 |
2423 /** | 2423 /** |
2424 * Build a JavaScrit AST node for doing a type check on | 2424 * Build a JavaScrit AST node for doing a type check on |
2425 * [cls]. [cls] must be an interceptor class. | 2425 * [cls]. [cls] must be an interceptor class. |
2426 */ | 2426 */ |
2427 jsAst.Statement buildInterceptorCheck(ClassElement cls) { | 2427 jsAst.Statement buildInterceptorCheck(ClassElement cls) { |
2428 jsAst.Expression condition; | 2428 jsAst.Expression condition; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2575 compiler)); | 2575 compiler)); |
2576 buffer.write(N); | 2576 buffer.write(N); |
2577 } | 2577 } |
2578 | 2578 |
2579 /** | 2579 /** |
2580 * Emit all versions of the [:getInterceptor:] method. | 2580 * Emit all versions of the [:getInterceptor:] method. |
2581 */ | 2581 */ |
2582 void emitGetInterceptorMethods(CodeBuffer buffer) { | 2582 void emitGetInterceptorMethods(CodeBuffer buffer) { |
2583 var specializedGetInterceptors = backend.specializedGetInterceptors; | 2583 var specializedGetInterceptors = backend.specializedGetInterceptors; |
2584 for (String name in specializedGetInterceptors.keys.toList()..sort()) { | 2584 for (String name in specializedGetInterceptors.keys.toList()..sort()) { |
2585 Collection<ClassElement> classes = specializedGetInterceptors[name]; | 2585 Iterable<ClassElement> classes = specializedGetInterceptors[name]; |
2586 emitGetInterceptorMethod(buffer, name, classes); | 2586 emitGetInterceptorMethod(buffer, name, classes); |
2587 } | 2587 } |
2588 } | 2588 } |
2589 | 2589 |
2590 /** | 2590 /** |
2591 * Compute all the classes that must be emitted. | 2591 * Compute all the classes that must be emitted. |
2592 */ | 2592 */ |
2593 void computeNeededClasses() { | 2593 void computeNeededClasses() { |
2594 instantiatedClasses = | 2594 instantiatedClasses = |
2595 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter()) | 2595 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter()) |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3045 """; | 3045 """; |
3046 const String HOOKS_API_USAGE = """ | 3046 const String HOOKS_API_USAGE = """ |
3047 // The code supports the following hooks: | 3047 // The code supports the following hooks: |
3048 // dartPrint(message) - if this function is defined it is called | 3048 // dartPrint(message) - if this function is defined it is called |
3049 // instead of the Dart [print] method. | 3049 // instead of the Dart [print] method. |
3050 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3050 // dartMainRunner(main) - if this function is defined, the Dart [main] |
3051 // method will not be invoked directly. | 3051 // method will not be invoked directly. |
3052 // Instead, a closure that will invoke [main] is | 3052 // Instead, a closure that will invoke [main] is |
3053 // passed to [dartMainRunner]. | 3053 // passed to [dartMainRunner]. |
3054 """; | 3054 """; |
OLD | NEW |