| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import '../compiler_helper.dart'; | 5 import '../compiler_helper.dart'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/src/dart2jslib.dart'; | 8 import 'package:compiler/src/dart2jslib.dart'; |
| 9 import 'package:compiler/src/dart_backend/dart_backend.dart'; | 9 import 'package:compiler/src/dart_backend/dart_backend.dart'; |
| 10 import 'package:compiler/src/dart_backend/backend_ast_to_frontend_ast.dart' | 10 import 'package:compiler/src/dart_backend/backend_ast_to_frontend_ast.dart' |
| 11 show INSERT_NEW_BACKEND_COMMENT; | 11 show INSERT_NEW_BACKEND_COMMENT; |
| 12 | 12 |
| 13 const String TestStaticField = """ | 13 const String TestStaticField = """ |
| 14 class Foo { | 14 class Foo { |
| 15 static int x = 1; | 15 static int x = 1; |
| 16 } | 16 } |
| 17 main() { | 17 main() { |
| 18 print(Foo.x); | 18 print(Foo.x); |
| 19 } | 19 } |
| 20 """; | 20 """; |
| 21 | 21 |
| 22 Future<String> compile(String code) { | 22 Future<String> compile(String code) { |
| 23 OutputCollector outputCollector = new OutputCollector(); |
| 23 MockCompiler compiler = new MockCompiler.internal( | 24 MockCompiler compiler = new MockCompiler.internal( |
| 24 emitJavaScript: false, | 25 emitJavaScript: false, |
| 25 enableMinification: false); | 26 enableMinification: false, |
| 27 outputProvider: outputCollector); |
| 26 return compiler.init().then((_) { | 28 return compiler.init().then((_) { |
| 27 compiler.parseScript(code); | 29 compiler.parseScript(code); |
| 28 Element element = compiler.mainApp.find('main'); | 30 Element element = compiler.mainApp.find('main'); |
| 29 if (element == null) return null; | 31 if (element == null) return null; |
| 30 compiler.mainFunction = element; | 32 compiler.mainFunction = element; |
| 31 compiler.phase = Compiler.PHASE_RESOLVING; | 33 compiler.phase = Compiler.PHASE_RESOLVING; |
| 32 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, | 34 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, |
| 33 compiler.globalDependencies); | 35 compiler.globalDependencies); |
| 34 compiler.processQueue(compiler.enqueuer.resolution, element); | 36 compiler.processQueue(compiler.enqueuer.resolution, element); |
| 35 compiler.world.populate(); | 37 compiler.world.populate(); |
| 36 compiler.backend.onResolutionComplete(); | 38 compiler.backend.onResolutionComplete(); |
| 37 compiler.irBuilder.buildNodes(); | 39 compiler.irBuilder.buildNodes(); |
| 38 compiler.phase = Compiler.PHASE_COMPILING; | 40 compiler.phase = Compiler.PHASE_COMPILING; |
| 39 DartBackend backend = compiler.backend; | 41 DartBackend backend = compiler.backend; |
| 40 backend.assembleProgram(); | 42 backend.assembleProgram(); |
| 41 String generated = compiler.assembledCode; | 43 String generated = outputCollector.getOutput('', 'dart'); |
| 42 return generated; | 44 return generated; |
| 43 }); | 45 }); |
| 44 } | 46 } |
| 45 | 47 |
| 46 Future test(String code, String feature) { | 48 Future test(String code, String feature) { |
| 47 return compile(code).then((output) { | 49 return compile(code).then((output) { |
| 48 if (output == null || !output.contains('main() /* new backend */')) { | 50 if (output == null || !output.contains('main() /* new backend */')) { |
| 49 throw 'New backend appears to be deactivated for $feature.\n' | 51 throw 'New backend appears to be deactivated for $feature.\n' |
| 50 'Output was: $output'; | 52 'Output was: $output'; |
| 51 } | 53 } |
| 52 }); | 54 }); |
| 53 } | 55 } |
| 54 | 56 |
| 55 main() { | 57 main() { |
| 56 INSERT_NEW_BACKEND_COMMENT = true; | 58 INSERT_NEW_BACKEND_COMMENT = true; |
| 57 | 59 |
| 58 asyncTest(() => Future.forEach([ | 60 asyncTest(() => Future.forEach([ |
| 59 () => test(TestStaticField, 'static fields'), | 61 () => test(TestStaticField, 'static fields'), |
| 60 ], (f) => f())); | 62 ], (f) => f())); |
| 61 } | 63 } |
| OLD | NEW |