OLD | NEW |
| (Empty) |
1 // Copyright (c) 2017, 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 import 'dart:io'; | |
6 import 'package:async_helper/async_helper.dart'; | |
7 import 'package:compiler/src/compiler.dart'; | |
8 import 'package:compiler/src/commandline_options.dart'; | |
9 import 'package:compiler/src/elements/elements.dart'; | |
10 import 'package:compiler/src/kernel/kernel.dart'; | |
11 import 'package:compiler/src/tree/nodes.dart' as ast; | |
12 import 'package:expect/expect.dart'; | |
13 import 'package:kernel/ast.dart' as ir; | |
14 import 'inference_test_helper.dart'; | |
15 import 'enumerator.dart'; | |
16 | |
17 main() { | |
18 asyncTest(() async { | |
19 Directory dataDir = new Directory.fromUri(Platform.script.resolve('data')); | |
20 await for (FileSystemEntity entity in dataDir.list()) { | |
21 print('Checking ${entity.uri}'); | |
22 String annotatedCode = await new File.fromUri(entity.uri).readAsString(); | |
23 await checkCode(annotatedCode, checkMemberEquivalence, | |
24 options: [Flags.useKernel]); | |
25 } | |
26 }); | |
27 } | |
28 | |
29 /// Check that the ids in [expectedMap] map to equivalent nodes/elements in | |
30 /// the AST and kernel IR. | |
31 void checkMemberEquivalence( | |
32 Compiler compiler, Map<Id, String> expectedMap, MemberElement member) { | |
33 ResolvedAst resolvedAst = member.resolvedAst; | |
34 if (resolvedAst.kind != ResolvedAstKind.PARSED) return; | |
35 Map<Id, ast.Node> astMap = <Id, ast.Node>{}; | |
36 Map<Id, Element> elementMap = <Id, Element>{}; | |
37 AstIdFinder astFinder = new AstIdFinder(resolvedAst.elements); | |
38 for (Id id in expectedMap.keys.toList()) { | |
39 var result = astFinder.find(resolvedAst.node, id); | |
40 if (result is ast.Node) { | |
41 astMap[id] = result; | |
42 } else if (result is AstElement) { | |
43 elementMap[id] = result; | |
44 } | |
45 } | |
46 | |
47 Kernel kernel = compiler.backend.kernelTask.kernel; | |
48 Map<Id, ir.Node> irMap = <Id, ir.Node>{}; | |
49 ir.Node node = kernel.elementToIr(member); | |
50 IrIdFinder irFinder = new IrIdFinder(); | |
51 for (Id id in expectedMap.keys.toList()) { | |
52 ir.Node result = irFinder.find(node, id); | |
53 if (result != null) { | |
54 irMap[id] = result; | |
55 } | |
56 } | |
57 | |
58 elementMap.forEach((Id id, _element) { | |
59 AstElement element = _element; | |
60 ir.Node irNode = irMap[id]; | |
61 Expect.equals(kernel.elementToIr(element), irNode, | |
62 "Element mismatch on $id = $element"); | |
63 expectedMap.remove(id); | |
64 irMap.remove(id); | |
65 }); | |
66 astMap.forEach((Id id, ast.Node astNode) { | |
67 ir.Node irNode = irMap[id]; | |
68 Expect.equals( | |
69 kernel.nodeToAst[irNode], astNode, "Node mismatch on $id = $astNode"); | |
70 expectedMap.remove(id); | |
71 irMap.remove(id); | |
72 }); | |
73 Expect.isTrue(irMap.isEmpty, "Extra IR ids: $irMap"); | |
74 } | |
OLD | NEW |