| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /// Test that the dart2js copy of [KernelVisitor] generates the expected class | |
| 6 /// hierarchy. | |
| 7 | |
| 8 import 'package:compiler/src/commandline_options.dart' show Flags; | |
| 9 import 'package:compiler/src/compiler.dart' show Compiler; | |
| 10 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend; | |
| 11 import 'package:compiler/src/library_loader.dart' show LoadedLibraries; | |
| 12 import 'package:kernel/ast.dart' as ir; | |
| 13 import 'package:kernel/class_hierarchy.dart'; | |
| 14 import 'package:test/test.dart'; | |
| 15 | |
| 16 import '../memory_compiler.dart'; | |
| 17 | |
| 18 main(List<String> arguments) { | |
| 19 Compiler compiler = compilerFor(memorySourceFiles: { | |
| 20 'main.dart': ''' | |
| 21 class S { | |
| 22 sMethod() {} | |
| 23 } | |
| 24 class M { | |
| 25 mMethod() {} | |
| 26 } | |
| 27 class C extends S with M { | |
| 28 cMethod() {} | |
| 29 } | |
| 30 main() {} | |
| 31 ''' | |
| 32 }, options: [ | |
| 33 Flags.analyzeOnly, | |
| 34 Flags.analyzeAll, | |
| 35 Flags.useKernelInSsa | |
| 36 ]); | |
| 37 test('mixin', () async { | |
| 38 Uri mainUri = Uri.parse('memory:main.dart'); | |
| 39 await compiler.run(mainUri); | |
| 40 LoadedLibraries libraries = | |
| 41 await compiler.libraryLoader.loadLibrary(mainUri); | |
| 42 compiler.processLoadedLibraries(libraries); | |
| 43 JavaScriptBackend backend = compiler.backend; | |
| 44 ir.Program program = backend.kernelTask.buildProgram(libraries.rootLibrary); | |
| 45 ClosedWorldClassHierarchy hierarchy = | |
| 46 new ClosedWorldClassHierarchy(program); | |
| 47 | |
| 48 ir.Class getClass(String name) { | |
| 49 for (ir.Class cls in hierarchy.classes) { | |
| 50 if (cls.enclosingLibrary.importUri == mainUri && cls.name == name) { | |
| 51 if (arguments.contains('-v')) { | |
| 52 print('$cls'); | |
| 53 print(' dispatch targets:'); | |
| 54 hierarchy | |
| 55 .getDispatchTargets(cls) | |
| 56 .forEach((member) => print(' $member')); | |
| 57 } | |
| 58 return cls; | |
| 59 } | |
| 60 } | |
| 61 fail('Class $name not found.'); | |
| 62 throw "Not reachable."; | |
| 63 } | |
| 64 | |
| 65 ir.Class classS = getClass('S'); | |
| 66 ir.Class classM = getClass('M'); | |
| 67 ir.Class classC = getClass('C'); | |
| 68 | |
| 69 void checkInheritance(ir.Class superClass, ir.Class subClass) { | |
| 70 for (ir.Member member in hierarchy.getDispatchTargets(superClass)) { | |
| 71 expect( | |
| 72 hierarchy.getDispatchTarget(subClass, member.name), equals(member), | |
| 73 reason: 'Unexpected dispatch target for ${member.name} ' | |
| 74 'in $subClass'); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 checkInheritance(classS, classC); | |
| 79 checkInheritance(classM, classC); | |
| 80 }); | |
| 81 } | |
| OLD | NEW |