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/closure.dart'; | 5 import 'package:compiler/src/closure.dart'; |
6 import 'package:compiler/src/common.dart'; | 6 import 'package:compiler/src/common.dart'; |
7 import 'package:compiler/src/compiler.dart'; | 7 import 'package:compiler/src/compiler.dart'; |
8 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 8 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
9 import 'package:compiler/src/elements/elements.dart'; | 9 import 'package:compiler/src/elements/elements.dart'; |
10 import 'package:compiler/src/elements/entities.dart'; | 10 import 'package:compiler/src/elements/entities.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 with ComputeValueMixin<ast.Node> { | 58 with ComputeValueMixin<ast.Node> { |
59 final GlobalTypeInferenceResults<ast.Node> results; | 59 final GlobalTypeInferenceResults<ast.Node> results; |
60 final GlobalTypeInferenceElementResult<ast.Node> result; | 60 final GlobalTypeInferenceElementResult<ast.Node> result; |
61 | 61 |
62 TypeMaskComputer(DiagnosticReporter reporter, Map<Id, ActualData> actualMap, | 62 TypeMaskComputer(DiagnosticReporter reporter, Map<Id, ActualData> actualMap, |
63 ResolvedAst resolvedAst, this.results) | 63 ResolvedAst resolvedAst, this.results) |
64 : result = results.resultOfMember(resolvedAst.element as MemberElement), | 64 : result = results.resultOfMember(resolvedAst.element as MemberElement), |
65 super(reporter, actualMap, resolvedAst); | 65 super(reporter, actualMap, resolvedAst); |
66 | 66 |
67 @override | 67 @override |
68 String computeElementValue(AstElement element) { | 68 String computeElementValue(Id id, AstElement element) { |
69 if (element.isParameter) { | 69 if (element.isParameter) { |
70 ParameterElement parameter = element; | 70 ParameterElement parameter = element; |
71 return getParameterValue(parameter); | 71 return getParameterValue(parameter); |
72 } else if (element.isLocal) { | 72 } else if (element.isLocal) { |
73 LocalFunctionElement localFunction = element; | 73 LocalFunctionElement localFunction = element; |
74 return getMemberValue(localFunction.callMethod); | 74 return getMemberValue(localFunction.callMethod); |
75 } else { | 75 } else { |
76 MemberElement member = element; | 76 MemberElement member = element; |
77 return getMemberValue(member); | 77 return getMemberValue(member); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 @override | 81 @override |
82 String computeNodeValue(ast.Node node, [AstElement element]) { | 82 String computeNodeValue(Id id, ast.Node node, [AstElement element]) { |
83 if (node is ast.Send) { | 83 if (node is ast.Send) { |
84 return getTypeMaskValue(result.typeOfSend(node)); | 84 return getTypeMaskValue(result.typeOfSend(node)); |
85 } else if (element != null && element.isLocal) { | 85 } else if (element != null && element.isLocal) { |
86 return computeElementValue(element); | 86 return computeElementValue(id, element); |
87 } | 87 } |
88 return null; | 88 return null; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 /// Compute type inference data for [member] from kernel based inference. | 92 /// Compute type inference data for [member] from kernel based inference. |
93 /// | 93 /// |
94 /// Fills [actualMap] with the data. | 94 /// Fills [actualMap] with the data. |
95 void computeMemberIrTypeMasks( | 95 void computeMemberIrTypeMasks( |
96 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap, | 96 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap, |
97 {bool verbose: false}) { | 97 {bool verbose: false}) { |
98 KernelBackendStrategy backendStrategy = compiler.backendStrategy; | 98 KernelBackendStrategy backendStrategy = compiler.backendStrategy; |
99 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap; | 99 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap; |
100 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting; | 100 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting; |
101 MemberDefinition definition = elementMap.getMemberDefinition(member); | 101 MemberDefinition definition = elementMap.getMemberDefinition(member); |
102 new TypeMaskIrComputer( | 102 new TypeMaskIrComputer( |
| 103 compiler.reporter, |
103 actualMap, | 104 actualMap, |
104 elementMap, | 105 elementMap, |
105 member, | 106 member, |
106 localsMap.getLocalsMap(member), | 107 localsMap.getLocalsMap(member), |
107 compiler.globalInference.results, | 108 compiler.globalInference.results, |
108 backendStrategy.closureDataLookup as ClosureDataLookup<ir.Node>) | 109 backendStrategy.closureDataLookup as ClosureDataLookup<ir.Node>) |
109 .run(definition.node); | 110 .run(definition.node); |
110 } | 111 } |
111 | 112 |
112 /// AST visitor for computing inference data for a member. | 113 /// AST visitor for computing inference data for a member. |
113 class TypeMaskIrComputer extends IrDataExtractor | 114 class TypeMaskIrComputer extends IrDataExtractor |
114 with ComputeValueMixin<ir.Node> { | 115 with ComputeValueMixin<ir.Node> { |
115 final GlobalTypeInferenceResults<ir.Node> results; | 116 final GlobalTypeInferenceResults<ir.Node> results; |
116 final GlobalTypeInferenceElementResult<ir.Node> result; | 117 final GlobalTypeInferenceElementResult<ir.Node> result; |
117 final KernelToElementMapForBuilding _elementMap; | 118 final KernelToElementMapForBuilding _elementMap; |
118 final KernelToLocalsMap _localsMap; | 119 final KernelToLocalsMap _localsMap; |
119 final ClosureDataLookup<ir.Node> _closureDataLookup; | 120 final ClosureDataLookup<ir.Node> _closureDataLookup; |
120 | 121 |
121 TypeMaskIrComputer( | 122 TypeMaskIrComputer( |
| 123 DiagnosticReporter reporter, |
122 Map<Id, ActualData> actualMap, | 124 Map<Id, ActualData> actualMap, |
123 this._elementMap, | 125 this._elementMap, |
124 MemberEntity member, | 126 MemberEntity member, |
125 this._localsMap, | 127 this._localsMap, |
126 this.results, | 128 this.results, |
127 this._closureDataLookup) | 129 this._closureDataLookup) |
128 : result = results.resultOfMember(member), | 130 : result = results.resultOfMember(member), |
129 super(actualMap); | 131 super(reporter, actualMap); |
130 | 132 |
131 @override | 133 @override |
132 String computeMemberValue(ir.Member node) { | 134 String computeMemberValue(Id id, ir.Member node) { |
133 return getMemberValue(_elementMap.getMember(node)); | 135 return getMemberValue(_elementMap.getMember(node)); |
134 } | 136 } |
135 | 137 |
136 @override | 138 @override |
137 String computeNodeValue(ir.TreeNode node) { | 139 String computeNodeValue(Id id, ir.TreeNode node) { |
138 if (node is ir.VariableDeclaration && node.parent is ir.FunctionNode) { | 140 if (node is ir.VariableDeclaration && node.parent is ir.FunctionNode) { |
139 Local parameter = _localsMap.getLocalVariable(node); | 141 Local parameter = _localsMap.getLocalVariable(node); |
140 return getParameterValue(parameter); | 142 return getParameterValue(parameter); |
141 } else if (node is ir.FunctionExpression || | 143 } else if (node is ir.FunctionExpression || |
142 node is ir.FunctionDeclaration) { | 144 node is ir.FunctionDeclaration) { |
143 ClosureRepresentationInfo info = _closureDataLookup.getClosureInfo(node); | 145 ClosureRepresentationInfo info = _closureDataLookup.getClosureInfo(node); |
144 return getMemberValue(info.callMethod); | 146 return getMemberValue(info.callMethod); |
145 } else if (node is ir.MethodInvocation) { | 147 } else if (node is ir.MethodInvocation) { |
146 return getTypeMaskValue(result.typeOfSend(node)); | 148 return getTypeMaskValue(result.typeOfSend(node)); |
147 } | 149 } |
148 return null; | 150 return null; |
149 } | 151 } |
150 } | 152 } |
OLD | NEW |