Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: tests/compiler/dart2js/inference/inference_test_helper.dart

Issue 2656583003: Add inference test functionality based on code point id. (Closed)
Patch Set: Updated cf. comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 'package:compiler/src/common.dart';
6 import 'package:compiler/src/compiler.dart';
7 import 'package:compiler/src/elements/elements.dart';
8 import 'package:compiler/src/resolution/tree_elements.dart';
9 import 'package:compiler/src/tree/nodes.dart';
10 import 'package:compiler/src/types/types.dart';
11 import 'package:expect/expect.dart';
12
13 import '../annotated_code_helper.dart';
14 import '../memory_compiler.dart';
15 import 'enumerator.dart';
16
17 checkCode(String annotatedCode) async {
18 AnnotatedCode code = new AnnotatedCode(annotatedCode);
19 Map<Id, String> expectedMap = computeExpectedMap(code);
20 Compiler compiler =
21 compilerFor(memorySourceFiles: {'main.dart': code.sourceCode});
22 compiler.stopAfterTypeInference = true;
23 Uri mainUri = Uri.parse('memory:main.dart');
24 await compiler.run(mainUri);
25 compiler.mainApp.forEachLocalMember((member) {
26 if (member.isFunction) {
27 checkMember(compiler, expectedMap, member);
28 } else if (member.isClass) {
29 member.forEachLocalMember((member) {
30 checkMember(compiler, expectedMap, member);
31 });
32 }
33 });
34 expectedMap.forEach((Id id, String expected) {
35 reportHere(
36 compiler.reporter,
37 new SourceSpan(mainUri, id.value, id.value + 1),
38 'expected:${expected},actual:null');
39 });
40 }
41
42 void checkMember(
43 Compiler compiler, Map<Id, String> expectedMap, MemberElement member) {
44 ResolvedAst resolvedAst = member.resolvedAst;
45 if (resolvedAst.kind != ResolvedAstKind.PARSED) return;
46 compiler.reporter.withCurrentElement(member.implementation, () {
47 resolvedAst.node.accept(new TypeMaskChecker(
48 compiler.reporter,
49 expectedMap,
50 resolvedAst.elements,
51 compiler.globalInference.results.resultOf(member)));
52 });
53 }
54
55 Map<Id, String> computeExpectedMap(AnnotatedCode code) {
56 Map<Id, String> map = <Id, String>{};
57 for (Annotation annotation in code.annotations) {
58 map[new Id(annotation.offset)] = annotation.text;
59 }
60 return map;
61 }
62
63 class TypeMaskChecker extends Visitor with AstEnumeratorMixin {
64 final DiagnosticReporter reporter;
65 final Map<Id, String> expectedMap;
66 final TreeElements elements;
67 final GlobalTypeInferenceElementResult result;
68
69 TypeMaskChecker(this.reporter, this.expectedMap, this.elements, this.result);
70
71 visitNode(Node node) {
72 node.visitChildren(this);
73 }
74
75 String annotationForId(Id id) {
76 if (id == null) return null;
77 return expectedMap.remove(id);
78 }
79
80 void checkValue(Node node, String expected, TypeMask value) {
81 if (value != null || expected != null) {
82 String valueText = '$value';
83 if (valueText != expected) {
84 reportHere(reporter, node, 'expected:${expected},actual:${value}');
85 }
86 Expect.equals(expected, valueText);
87 }
88 }
89
90 void checkSend(Send node) {
91 Id id = computeId(node);
92 TypeMask value = result.typeOfSend(node);
93 String expected = annotationForId(id);
94 checkValue(node, expected, value);
95 }
96
97 visitSend(Send node) {
98 checkSend(node);
99 visitNode(node);
100 }
101
102 visitSendSet(SendSet node) {
103 checkSend(node);
104 visitNode(node);
105 }
106 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/inference/enumerator.dart ('k') | tests/compiler/dart2js/inference/send_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698