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 'dart:io'; | 5 import 'dart:io'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'package:compiler/src/commandline_options.dart'; | 7 import 'package:compiler/src/commandline_options.dart'; |
8 import 'package:compiler/src/common.dart'; | 8 import 'package:compiler/src/common.dart'; |
9 import 'package:compiler/src/compiler.dart'; | 9 import 'package:compiler/src/compiler.dart'; |
10 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 10 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 /// | 42 /// |
43 /// Fills [actualMap] with the data and [sourceSpanMap] with the source spans | 43 /// Fills [actualMap] with the data and [sourceSpanMap] with the source spans |
44 /// for the data origin. | 44 /// for the data origin. |
45 void computeKernelJumpsData( | 45 void computeKernelJumpsData( |
46 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap, | 46 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap, |
47 {bool verbose: false}) { | 47 {bool verbose: false}) { |
48 KernelBackendStrategy backendStrategy = compiler.backendStrategy; | 48 KernelBackendStrategy backendStrategy = compiler.backendStrategy; |
49 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap; | 49 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap; |
50 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting; | 50 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting; |
51 MemberDefinition definition = elementMap.getMemberDefinition(member); | 51 MemberDefinition definition = elementMap.getMemberDefinition(member); |
52 new JumpsIrChecker(actualMap, localsMap.getLocalsMap(member)) | 52 new JumpsIrChecker( |
| 53 compiler.reporter, actualMap, localsMap.getLocalsMap(member)) |
53 .run(definition.node); | 54 .run(definition.node); |
54 } | 55 } |
55 | 56 |
56 class TargetData { | 57 class TargetData { |
57 final int index; | 58 final int index; |
58 final NodeId id; | 59 final NodeId id; |
59 final SourceSpan sourceSpan; | 60 final SourceSpan sourceSpan; |
60 final JumpTarget target; | 61 final JumpTarget target; |
61 | 62 |
62 TargetData(this.index, this.id, this.sourceSpan, this.target); | 63 TargetData(this.index, this.id, this.sourceSpan, this.target); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 JumpsAstComputer(DiagnosticReporter reporter, Map<Id, ActualData> actualMap, | 120 JumpsAstComputer(DiagnosticReporter reporter, Map<Id, ActualData> actualMap, |
120 ResolvedAst resolvedAst) | 121 ResolvedAst resolvedAst) |
121 : super(reporter, actualMap, resolvedAst); | 122 : super(reporter, actualMap, resolvedAst); |
122 | 123 |
123 void run() { | 124 void run() { |
124 super.run(); | 125 super.run(); |
125 processData(); | 126 processData(); |
126 } | 127 } |
127 | 128 |
128 @override | 129 @override |
129 String computeNodeValue(ast.Node node, [AstElement element]) { | 130 String computeNodeValue(Id id, ast.Node node, [AstElement element]) { |
130 // Node values are computed post-visit in [processData]. | 131 // Node values are computed post-visit in [processData]. |
131 return null; | 132 return null; |
132 } | 133 } |
133 | 134 |
134 @override | 135 @override |
135 String computeElementValue(AstElement element) { | 136 String computeElementValue(Id id, AstElement element) { |
136 return null; | 137 return null; |
137 } | 138 } |
138 | 139 |
139 @override | 140 @override |
140 visitLoop(ast.Loop node) { | 141 visitLoop(ast.Loop node) { |
141 JumpTarget target = elements.getTargetDefinition(node); | 142 JumpTarget target = elements.getTargetDefinition(node); |
142 if (target != null) { | 143 if (target != null) { |
143 NodeId id = computeLoopNodeId(node); | 144 NodeId id = createLoopId(node); |
144 SourceSpan sourceSpan = computeSourceSpan(node); | 145 SourceSpan sourceSpan = computeSourceSpan(node); |
145 targets[target] = new TargetData(index++, id, sourceSpan, target); | 146 targets[target] = new TargetData(index++, id, sourceSpan, target); |
146 } | 147 } |
147 super.visitLoop(node); | 148 super.visitLoop(node); |
148 } | 149 } |
149 | 150 |
150 @override | 151 @override |
151 visitGotoStatement(ast.GotoStatement node) { | 152 visitGotoStatement(ast.GotoStatement node) { |
152 JumpTarget target = elements.getTargetOf(node); | 153 JumpTarget target = elements.getTargetOf(node); |
153 assert(target != null, 'No target for $node.'); | 154 assert(target != null, 'No target for $node.'); |
154 NodeId id = computeGotoNodeId(node); | 155 NodeId id = createGotoId(node); |
155 SourceSpan sourceSpan = computeSourceSpan(node); | 156 SourceSpan sourceSpan = computeSourceSpan(node); |
156 gotos.add(new GotoData(id, sourceSpan, target)); | 157 gotos.add(new GotoData(id, sourceSpan, target)); |
157 super.visitGotoStatement(node); | 158 super.visitGotoStatement(node); |
158 } | 159 } |
159 | 160 |
160 @override | 161 @override |
161 visitSwitchStatement(ast.SwitchStatement node) { | 162 visitSwitchStatement(ast.SwitchStatement node) { |
162 JumpTarget target = elements.getTargetDefinition(node); | 163 JumpTarget target = elements.getTargetDefinition(node); |
163 if (target != null) { | 164 if (target != null) { |
164 NodeId id = computeLoopNodeId(node); | 165 NodeId id = createLoopId(node); |
165 SourceSpan sourceSpan = computeSourceSpan(node); | 166 SourceSpan sourceSpan = computeSourceSpan(node); |
166 targets[target] = new TargetData(index++, id, sourceSpan, target); | 167 targets[target] = new TargetData(index++, id, sourceSpan, target); |
167 } | 168 } |
168 super.visitSwitchStatement(node); | 169 super.visitSwitchStatement(node); |
169 } | 170 } |
170 | 171 |
171 @override | 172 @override |
172 visitSwitchCase(ast.SwitchCase node) { | 173 visitSwitchCase(ast.SwitchCase node) { |
173 JumpTarget target = elements.getTargetDefinition(node); | 174 JumpTarget target = elements.getTargetDefinition(node); |
174 if (target != null) { | 175 if (target != null) { |
175 NodeId id = computeSwitchCaseNodeId(node); | 176 NodeId id = createSwitchCaseId(node); |
176 SourceSpan sourceSpan = computeSourceSpan(node); | 177 SourceSpan sourceSpan = computeSourceSpan(node); |
177 targets[target] = new TargetData(index++, id, sourceSpan, target); | 178 targets[target] = new TargetData(index++, id, sourceSpan, target); |
178 } | 179 } |
179 super.visitSwitchCase(node); | 180 super.visitSwitchCase(node); |
180 } | 181 } |
181 } | 182 } |
182 | 183 |
183 /// Kernel IR visitor for computing jump data. | 184 /// Kernel IR visitor for computing jump data. |
184 class JumpsIrChecker extends IrDataExtractor with JumpsMixin { | 185 class JumpsIrChecker extends IrDataExtractor with JumpsMixin { |
185 final KernelToLocalsMap _localsMap; | 186 final KernelToLocalsMap _localsMap; |
186 | 187 |
187 JumpsIrChecker(Map<Id, ActualData> actualMap, this._localsMap) | 188 JumpsIrChecker(DiagnosticReporter reporter, Map<Id, ActualData> actualMap, |
188 : super(actualMap); | 189 this._localsMap) |
| 190 : super(reporter, actualMap); |
189 | 191 |
190 void run(ir.Node root) { | 192 void run(ir.Node root) { |
191 super.run(root); | 193 super.run(root); |
192 processData(); | 194 processData(); |
193 } | 195 } |
194 | 196 |
195 @override | 197 @override |
196 String computeNodeValue(ir.Node node) { | 198 String computeNodeValue(Id id, ir.Node node) { |
197 // Node values are computed post-visit in [processData]. | 199 // Node values are computed post-visit in [processData]. |
198 return null; | 200 return null; |
199 } | 201 } |
200 | 202 |
201 @override | 203 @override |
202 String computeMemberValue(ir.Member member) { | 204 String computeMemberValue(Id id, ir.Member member) { |
203 return null; | 205 return null; |
204 } | 206 } |
205 | 207 |
206 void addTargetData(ir.TreeNode node, NodeId id, JumpTarget target) { | 208 void addTargetData(ir.TreeNode node, NodeId id, JumpTarget target) { |
207 if (target != null) { | 209 if (target != null) { |
208 SourceSpan sourceSpan = computeSourceSpan(node); | 210 SourceSpan sourceSpan = computeSourceSpan(node); |
209 targets[target] = new TargetData(index++, id, sourceSpan, target); | 211 targets[target] = new TargetData(index++, id, sourceSpan, target); |
210 } | 212 } |
211 } | 213 } |
212 | 214 |
213 visitForStatement(ir.ForStatement node) { | 215 visitForStatement(ir.ForStatement node) { |
214 addTargetData( | 216 addTargetData( |
215 node, computeLoopNodeId(node), _localsMap.getJumpTargetForFor(node)); | 217 node, createLoopId(node), _localsMap.getJumpTargetForFor(node)); |
216 super.visitForStatement(node); | 218 super.visitForStatement(node); |
217 } | 219 } |
218 | 220 |
219 visitForInStatement(ir.ForInStatement node) { | 221 visitForInStatement(ir.ForInStatement node) { |
220 addTargetData( | 222 addTargetData( |
221 node, computeLoopNodeId(node), _localsMap.getJumpTargetForForIn(node)); | 223 node, createLoopId(node), _localsMap.getJumpTargetForForIn(node)); |
222 super.visitForInStatement(node); | 224 super.visitForInStatement(node); |
223 } | 225 } |
224 | 226 |
225 visitWhileStatement(ir.WhileStatement node) { | 227 visitWhileStatement(ir.WhileStatement node) { |
226 addTargetData( | 228 addTargetData( |
227 node, computeLoopNodeId(node), _localsMap.getJumpTargetForWhile(node)); | 229 node, createLoopId(node), _localsMap.getJumpTargetForWhile(node)); |
228 super.visitWhileStatement(node); | 230 super.visitWhileStatement(node); |
229 } | 231 } |
230 | 232 |
231 visitDoStatement(ir.DoStatement node) { | 233 visitDoStatement(ir.DoStatement node) { |
232 addTargetData( | 234 addTargetData( |
233 node, computeLoopNodeId(node), _localsMap.getJumpTargetForDo(node)); | 235 node, createLoopId(node), _localsMap.getJumpTargetForDo(node)); |
234 super.visitDoStatement(node); | 236 super.visitDoStatement(node); |
235 } | 237 } |
236 | 238 |
237 visitBreakStatement(ir.BreakStatement node) { | 239 visitBreakStatement(ir.BreakStatement node) { |
238 JumpTarget target = _localsMap.getJumpTargetForBreak(node); | 240 JumpTarget target = _localsMap.getJumpTargetForBreak(node); |
239 assert(target != null, 'No target for $node.'); | 241 assert(target != null, 'No target for $node.'); |
240 NodeId id = computeGotoNodeId(node); | 242 NodeId id = createGotoId(node); |
241 SourceSpan sourceSpan = computeSourceSpan(node); | 243 SourceSpan sourceSpan = computeSourceSpan(node); |
242 gotos.add(new GotoData(id, sourceSpan, target)); | 244 gotos.add(new GotoData(id, sourceSpan, target)); |
243 super.visitBreakStatement(node); | 245 super.visitBreakStatement(node); |
244 } | 246 } |
245 | 247 |
246 visitSwitchStatement(ir.SwitchStatement node) { | 248 visitSwitchStatement(ir.SwitchStatement node) { |
247 addTargetData( | 249 addTargetData( |
248 node, computeLoopNodeId(node), _localsMap.getJumpTargetForSwitch(node)); | 250 node, createSwitchId(node), _localsMap.getJumpTargetForSwitch(node)); |
249 super.visitSwitchStatement(node); | 251 super.visitSwitchStatement(node); |
250 } | 252 } |
251 | 253 |
252 visitSwitchCase(ir.SwitchCase node) { | 254 visitSwitchCase(ir.SwitchCase node) { |
253 addTargetData(node, computeSwitchCaseNodeId(node), | 255 addTargetData(node, createSwitchCaseId(node), |
254 _localsMap.getJumpTargetForSwitchCase(node)); | 256 _localsMap.getJumpTargetForSwitchCase(node)); |
255 super.visitSwitchCase(node); | 257 super.visitSwitchCase(node); |
256 } | 258 } |
257 | 259 |
258 visitContinueSwitchStatement(ir.ContinueSwitchStatement node) { | 260 visitContinueSwitchStatement(ir.ContinueSwitchStatement node) { |
259 JumpTarget target = _localsMap.getJumpTargetForContinueSwitch(node); | 261 JumpTarget target = _localsMap.getJumpTargetForContinueSwitch(node); |
260 assert(target != null, 'No target for $node.'); | 262 assert(target != null, 'No target for $node.'); |
261 NodeId id = computeGotoNodeId(node); | 263 NodeId id = createGotoId(node); |
262 SourceSpan sourceSpan = computeSourceSpan(node); | 264 SourceSpan sourceSpan = computeSourceSpan(node); |
263 gotos.add(new GotoData(id, sourceSpan, target)); | 265 gotos.add(new GotoData(id, sourceSpan, target)); |
264 super.visitContinueSwitchStatement(node); | 266 super.visitContinueSwitchStatement(node); |
265 } | 267 } |
266 } | 268 } |
OLD | NEW |