| 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 class NativeEmitter { | 7 class NativeEmitter { |
| 8 | 8 |
| 9 CodeEmitterTask emitter; | 9 CodeEmitterTask emitter; |
| 10 CodeBuffer nativeBuffer; | 10 CodeBuffer nativeBuffer; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 for (final ClassElement subclass in getDirectSubclasses(cls)) { | 392 for (final ClassElement subclass in getDirectSubclasses(cls)) { |
| 393 ClassElement tag = subclass; | 393 ClassElement tag = subclass; |
| 394 js.Expression existing = tagDefns[tag]; | 394 js.Expression existing = tagDefns[tag]; |
| 395 if (existing == null) { | 395 if (existing == null) { |
| 396 // [subclass] is still within the subtree between dispatch classes. | 396 // [subclass] is still within the subtree between dispatch classes. |
| 397 subtags.add(toNativeTag(tag)); | 397 subtags.add(toNativeTag(tag)); |
| 398 walk(subclass); | 398 walk(subclass); |
| 399 } else { | 399 } else { |
| 400 // [subclass] is one of the preorderDispatchClasses, so CSE this | 400 // [subclass] is one of the preorderDispatchClasses, so CSE this |
| 401 // reference with the previous reference. | 401 // reference with the previous reference. |
| 402 if (existing is js.VariableUse && | 402 js.VariableUse use = existing.asVariableUse(); |
| 403 varDefns.containsKey(existing.name)) { | 403 if (use != null && varDefns.containsKey(use.name)) { |
| 404 // We end up here if the subclasses have a DAG structure. We | 404 // We end up here if the subclasses have a DAG structure. We |
| 405 // don't have DAGs yet, but if the dispatch is used for mixins | 405 // don't have DAGs yet, but if the dispatch is used for mixins |
| 406 // that will be a possibility. | 406 // that will be a possibility. |
| 407 // Re-use the previously created temporary variable. | 407 // Re-use the previously created temporary variable. |
| 408 expressions.add(new js.VariableUse(existing.name)); | 408 expressions.add(new js.VariableUse(use.name)); |
| 409 } else { | 409 } else { |
| 410 String varName = 'v${varNames.length}_${tag.name.slowToString()}'; | 410 String varName = 'v${varNames.length}_${tag.name.slowToString()}'; |
| 411 varNames.add(varName); | 411 varNames.add(varName); |
| 412 varDefns[varName] = existing; | 412 varDefns[varName] = existing; |
| 413 tagDefns[tag] = new js.VariableUse(varName); | 413 tagDefns[tag] = new js.VariableUse(varName); |
| 414 expressions.add(new js.VariableUse(varName)); | 414 expressions.add(new js.VariableUse(varName)); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 } | 418 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (!first) targetBuffer.add(",\n"); | 566 if (!first) targetBuffer.add(",\n"); |
| 567 targetBuffer.add(" $name: $function"); | 567 targetBuffer.add(" $name: $function"); |
| 568 first = false; | 568 first = false; |
| 569 }); | 569 }); |
| 570 targetBuffer.add("\n});\n\n"); | 570 targetBuffer.add("\n});\n\n"); |
| 571 } | 571 } |
| 572 targetBuffer.add(nativeBuffer); | 572 targetBuffer.add(nativeBuffer); |
| 573 targetBuffer.add('\n'); | 573 targetBuffer.add('\n'); |
| 574 } | 574 } |
| 575 } | 575 } |
| OLD | NEW |