| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Test that the CPS IR code generator generates source information. | 5 // Test that the CPS IR code generator generates source information. |
| 6 | 6 |
| 7 library source_information_tests; | 7 library source_information_tests; |
| 8 | 8 |
| 9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:compiler/src/apiimpl.dart' | 11 import 'package:compiler/src/apiimpl.dart' |
| 12 show CompilerImpl; | 12 show CompilerImpl; |
| 13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
| 14 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart' as ir; | 14 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart' as ir; |
| 15 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart' as ir; | 15 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart' as ir; |
| 16 import 'package:compiler/src/js/js.dart' as js; | 16 import 'package:compiler/src/js/js.dart' as js; |
| 17 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 17 import 'package:compiler/src/elements/elements.dart'; | 18 import 'package:compiler/src/elements/elements.dart'; |
| 18 | 19 |
| 19 const String TEST_MAIN_FILE = 'test.dart'; | 20 const String TEST_MAIN_FILE = 'test.dart'; |
| 20 | 21 |
| 21 class TestEntry { | 22 class TestEntry { |
| 22 final String source; | 23 final String source; |
| 23 final List<String> expectation; | 24 final List<String> expectation; |
| 24 final String elementName; | 25 final String elementName; |
| 25 | 26 |
| 26 const TestEntry(this.source, this.expectation) | 27 const TestEntry(this.source, this.expectation) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 ir.FunctionDefinition irNodeForMain; | 72 ir.FunctionDefinition irNodeForMain; |
| 72 | 73 |
| 73 void cacheIrNodeForMain(Element function, ir.FunctionDefinition irNode) { | 74 void cacheIrNodeForMain(Element function, ir.FunctionDefinition irNode) { |
| 74 if (function == compiler.mainFunction) { | 75 if (function == compiler.mainFunction) { |
| 75 assert(irNodeForMain == null); | 76 assert(irNodeForMain == null); |
| 76 irNodeForMain = irNode; | 77 irNodeForMain = irNode; |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); | 81 Uri uri = Uri.parse('memory:$TEST_MAIN_FILE'); |
| 81 compiler.backend.functionCompiler.cpsBuilderTask.builderCallback = | 82 JavaScriptBackend backend = compiler.backend; |
| 82 cacheIrNodeForMain; | 83 var functionCompiler = backend.functionCompiler; |
| 84 functionCompiler.cpsBuilderTask.builderCallback = cacheIrNodeForMain; |
| 83 | 85 |
| 84 return compiler.run(uri).then((bool success) { | 86 return compiler.run(uri).then((bool success) { |
| 85 Expect.isTrue(success); | 87 Expect.isTrue(success); |
| 86 | 88 |
| 87 IrSourceInformationVisitor irVisitor = new IrSourceInformationVisitor(); | 89 IrSourceInformationVisitor irVisitor = new IrSourceInformationVisitor(); |
| 88 irNodeForMain.accept(irVisitor); | 90 irNodeForMain.accept(irVisitor); |
| 89 | 91 |
| 90 js.Node jsNode = getJsNodeForElement(compiler, compiler.mainFunction); | 92 js.Node jsNode = getJsNodeForElement(compiler, compiler.mainFunction); |
| 91 JsSourceInformationVisitor jsVisitor = new JsSourceInformationVisitor(); | 93 JsSourceInformationVisitor jsVisitor = new JsSourceInformationVisitor(); |
| 92 jsNode.accept(jsVisitor); | 94 jsNode.accept(jsVisitor); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 print('Hello'); | 143 print('Hello'); |
| 142 print('World'); | 144 print('World'); |
| 143 } | 145 } |
| 144 """, const ['memory:test.dart:[2,3]', | 146 """, const ['memory:test.dart:[2,3]', |
| 145 'memory:test.dart:[3,3]']), | 147 'memory:test.dart:[3,3]']), |
| 146 ]; | 148 ]; |
| 147 | 149 |
| 148 void main() { | 150 void main() { |
| 149 runTests(tests); | 151 runTests(tests); |
| 150 } | 152 } |
| OLD | NEW |