OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 'package:compiler/src/common.dart'; | 5 import 'package:compiler/src/common.dart'; |
6 import 'package:compiler/src/compiler.dart'; | 6 import 'package:compiler/src/compiler.dart'; |
7 import 'package:compiler/src/elements/elements.dart'; | 7 import 'package:compiler/src/elements/elements.dart'; |
8 import 'package:compiler/src/elements/entities.dart'; | 8 import 'package:compiler/src/elements/entities.dart'; |
9 import 'package:compiler/src/tree/nodes.dart'; | 9 import 'package:compiler/src/tree/nodes.dart'; |
10 import 'package:compiler/src/types/types.dart'; | 10 import 'package:compiler/src/types/types.dart'; |
11 | 11 |
12 import '../equivalence/id_equivalence.dart'; | 12 import '../equivalence/id_equivalence.dart'; |
13 import '../equivalence/id_equivalence_helper.dart'; | 13 import '../equivalence/id_equivalence_helper.dart'; |
14 | 14 |
15 void checkMemberAstTypeMasks( | 15 /// Compute type inference data for [_member] as a [MemberElement]. |
16 Compiler compiler, Map<Id, String> expectedMap, MemberEntity _member) { | 16 /// |
| 17 /// Fills [actualMap] with the data and [sourceSpanMap] with the source spans |
| 18 /// for the data origin. |
| 19 void computeMemberAstTypeMasks(Compiler compiler, MemberEntity _member, |
| 20 Map<Id, String> actualMap, Map<Id, Spannable> spannableMap) { |
17 MemberElement member = _member; | 21 MemberElement member = _member; |
18 ResolvedAst resolvedAst = member.resolvedAst; | 22 ResolvedAst resolvedAst = member.resolvedAst; |
19 if (resolvedAst.kind != ResolvedAstKind.PARSED) return; | 23 if (resolvedAst.kind != ResolvedAstKind.PARSED) return; |
20 compiler.reporter.withCurrentElement(member.implementation, () { | 24 compiler.reporter.withCurrentElement(member.implementation, () { |
21 new TypeMaskChecker(compiler.reporter, expectedMap, resolvedAst, | 25 new TypeMaskComputer(compiler.reporter, actualMap, spannableMap, |
22 compiler.globalInference.results) | 26 resolvedAst, compiler.globalInference.results) |
23 .check(); | 27 .run(); |
24 }); | 28 }); |
25 } | 29 } |
26 | 30 |
27 class TypeMaskChecker extends AbstractResolvedAstChecker { | 31 /// AST visitor for computing inference data for a member. |
| 32 class TypeMaskComputer extends AbstractResolvedAstComputer { |
28 final GlobalTypeInferenceResults results; | 33 final GlobalTypeInferenceResults results; |
29 final GlobalTypeInferenceElementResult result; | 34 final GlobalTypeInferenceElementResult result; |
30 | 35 |
31 TypeMaskChecker(DiagnosticReporter reporter, Map<Id, String> expectedMap, | 36 TypeMaskComputer(DiagnosticReporter reporter, Map<Id, String> actualMap, |
32 ResolvedAst resolvedAst, this.results) | 37 Map<Id, Spannable> spannableMap, ResolvedAst resolvedAst, this.results) |
33 : result = results.resultOfMember(resolvedAst.element as MemberElement), | 38 : result = results.resultOfMember(resolvedAst.element as MemberElement), |
34 super(reporter, expectedMap, resolvedAst); | 39 super(reporter, actualMap, spannableMap, resolvedAst); |
35 | 40 |
36 @override | 41 @override |
37 String computeElementValue(AstElement element) { | 42 String computeElementValue(AstElement element) { |
38 GlobalTypeInferenceElementResult elementResult = | 43 GlobalTypeInferenceElementResult elementResult = |
39 results.resultOfElement(element); | 44 results.resultOfElement(element); |
40 TypeMask value = | 45 TypeMask value = |
41 element.isFunction ? elementResult.returnType : elementResult.type; | 46 element.isFunction ? elementResult.returnType : elementResult.type; |
42 return value != null ? '$value' : null; | 47 return value != null ? '$value' : null; |
43 } | 48 } |
44 | 49 |
45 @override | 50 @override |
46 String computeNodeValue(Node node, [AstElement element]) { | 51 String computeNodeValue(Node node, [AstElement element]) { |
47 if (node is Send) { | 52 if (node is Send) { |
48 TypeMask value = result.typeOfSend(node); | 53 TypeMask value = result.typeOfSend(node); |
49 return value != null ? '$value' : null; | 54 return value != null ? '$value' : null; |
50 } else if (element != null && element.isLocal) { | 55 } else if (element != null && element.isLocal) { |
51 return computeElementValue(element); | 56 return computeElementValue(element); |
52 } | 57 } |
53 return null; | 58 return null; |
54 } | 59 } |
55 } | 60 } |
OLD | NEW |