| 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'; |
| 11 import 'package:compiler/src/elements/elements.dart'; | 11 import 'package:compiler/src/elements/elements.dart'; |
| 12 import 'package:compiler/src/elements/entities.dart'; | 12 import 'package:compiler/src/elements/entities.dart'; |
| 13 import 'package:compiler/src/elements/jumps.dart'; | 13 import 'package:compiler/src/elements/jumps.dart'; |
| 14 import 'package:compiler/src/js_model/locals.dart'; | 14 import 'package:compiler/src/js_model/locals.dart'; |
| 15 import 'package:compiler/src/kernel/element_map.dart'; | 15 import 'package:compiler/src/kernel/element_map.dart'; |
| 16 import 'package:compiler/src/kernel/kernel_backend_strategy.dart'; | 16 import 'package:compiler/src/kernel/kernel_backend_strategy.dart'; |
| 17 import 'package:compiler/src/tree/nodes.dart' as ast; | 17 import 'package:compiler/src/tree/nodes.dart' as ast; |
| 18 import '../equivalence/id_equivalence.dart'; | 18 import '../equivalence/id_equivalence.dart'; |
| 19 import '../equivalence/id_equivalence_helper.dart'; | 19 import '../equivalence/id_equivalence_helper.dart'; |
| 20 import 'package:kernel/ast.dart' as ir; | 20 import 'package:kernel/ast.dart' as ir; |
| 21 | 21 |
| 22 main() { | 22 main(List<String> args) { |
| 23 asyncTest(() async { | 23 asyncTest(() async { |
| 24 Directory dataDir = new Directory.fromUri(Platform.script.resolve('data')); | 24 Directory dataDir = new Directory.fromUri(Platform.script.resolve('data')); |
| 25 await checkTests(dataDir, computeJumpsData, computeKernelJumpsData, | 25 await checkTests(dataDir, computeJumpsData, computeKernelJumpsData, |
| 26 options: [Flags.disableTypeInference]); | 26 options: [Flags.disableTypeInference], args: args); |
| 27 }); | 27 }); |
| 28 } | 28 } |
| 29 | 29 |
| 30 /// Compute closure data mapping for [_member] as a [MemberElement]. | 30 /// Compute closure data mapping for [_member] as a [MemberElement]. |
| 31 /// | 31 /// |
| 32 /// Fills [actualMap] with the data and [sourceSpanMap] with the source spans | 32 /// Fills [actualMap] with the data and [sourceSpanMap] with the source spans |
| 33 /// for the data origin. | 33 /// for the data origin. |
| 34 void computeJumpsData( | 34 void computeJumpsData( |
| 35 Compiler compiler, MemberEntity _member, Map<Id, ActualData> actualMap, | 35 Compiler compiler, MemberEntity _member, Map<Id, ActualData> actualMap, |
| 36 {bool verbose: false}) { | 36 {bool verbose: false}) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 @override | 160 @override |
| 161 visitSwitchStatement(ast.SwitchStatement node) { | 161 visitSwitchStatement(ast.SwitchStatement node) { |
| 162 JumpTarget target = elements.getTargetDefinition(node); | 162 JumpTarget target = elements.getTargetDefinition(node); |
| 163 if (target != null) { | 163 if (target != null) { |
| 164 NodeId id = computeLoopNodeId(node); | 164 NodeId id = computeLoopNodeId(node); |
| 165 SourceSpan sourceSpan = computeSourceSpan(node); | 165 SourceSpan sourceSpan = computeSourceSpan(node); |
| 166 targets[target] = new TargetData(index++, id, sourceSpan, target); | 166 targets[target] = new TargetData(index++, id, sourceSpan, target); |
| 167 } | 167 } |
| 168 super.visitSwitchStatement(node); | 168 super.visitSwitchStatement(node); |
| 169 } | 169 } |
| 170 |
| 171 @override |
| 172 visitSwitchCase(ast.SwitchCase node) { |
| 173 JumpTarget target = elements.getTargetDefinition(node); |
| 174 if (target != null) { |
| 175 NodeId id = computeSwitchCaseNodeId(node); |
| 176 SourceSpan sourceSpan = computeSourceSpan(node); |
| 177 targets[target] = new TargetData(index++, id, sourceSpan, target); |
| 178 } |
| 179 super.visitSwitchCase(node); |
| 180 } |
| 170 } | 181 } |
| 171 | 182 |
| 172 /// Kernel IR visitor for computing jump data. | 183 /// Kernel IR visitor for computing jump data. |
| 173 class JumpsIrChecker extends IrDataExtractor with JumpsMixin { | 184 class JumpsIrChecker extends IrDataExtractor with JumpsMixin { |
| 174 final KernelToLocalsMap _localsMap; | 185 final KernelToLocalsMap _localsMap; |
| 175 | 186 |
| 176 JumpsIrChecker(Map<Id, ActualData> actualMap, this._localsMap) | 187 JumpsIrChecker(Map<Id, ActualData> actualMap, this._localsMap) |
| 177 : super(actualMap); | 188 : super(actualMap); |
| 178 | 189 |
| 179 void run(ir.Node root) { | 190 void run(ir.Node root) { |
| 180 super.run(root); | 191 super.run(root); |
| 181 processData(); | 192 processData(); |
| 182 } | 193 } |
| 183 | 194 |
| 184 @override | 195 @override |
| 185 String computeNodeValue(ir.Node node) { | 196 String computeNodeValue(ir.Node node) { |
| 186 // Node values are computed post-visit in [processData]. | 197 // Node values are computed post-visit in [processData]. |
| 187 return null; | 198 return null; |
| 188 } | 199 } |
| 189 | 200 |
| 190 @override | 201 @override |
| 191 String computeMemberValue(ir.Member member) { | 202 String computeMemberValue(ir.Member member) { |
| 192 return null; | 203 return null; |
| 193 } | 204 } |
| 194 | 205 |
| 195 void addTargetData(ir.TreeNode node, JumpTarget target) { | 206 void addTargetData(ir.TreeNode node, NodeId id, JumpTarget target) { |
| 196 if (target != null) { | 207 if (target != null) { |
| 197 NodeId id = computeLoopNodeId(node); | |
| 198 SourceSpan sourceSpan = computeSourceSpan(node); | 208 SourceSpan sourceSpan = computeSourceSpan(node); |
| 199 targets[target] = new TargetData(index++, id, sourceSpan, target); | 209 targets[target] = new TargetData(index++, id, sourceSpan, target); |
| 200 } | 210 } |
| 201 } | 211 } |
| 202 | 212 |
| 203 visitForStatement(ir.ForStatement node) { | 213 visitForStatement(ir.ForStatement node) { |
| 204 addTargetData(node, _localsMap.getJumpTargetForFor(node)); | 214 addTargetData( |
| 215 node, computeLoopNodeId(node), _localsMap.getJumpTargetForFor(node)); |
| 205 super.visitForStatement(node); | 216 super.visitForStatement(node); |
| 206 } | 217 } |
| 207 | 218 |
| 208 visitForInStatement(ir.ForInStatement node) { | 219 visitForInStatement(ir.ForInStatement node) { |
| 209 addTargetData(node, _localsMap.getJumpTargetForForIn(node)); | 220 addTargetData( |
| 221 node, computeLoopNodeId(node), _localsMap.getJumpTargetForForIn(node)); |
| 210 super.visitForInStatement(node); | 222 super.visitForInStatement(node); |
| 211 } | 223 } |
| 212 | 224 |
| 213 visitWhileStatement(ir.WhileStatement node) { | 225 visitWhileStatement(ir.WhileStatement node) { |
| 214 addTargetData(node, _localsMap.getJumpTargetForWhile(node)); | 226 addTargetData( |
| 227 node, computeLoopNodeId(node), _localsMap.getJumpTargetForWhile(node)); |
| 215 super.visitWhileStatement(node); | 228 super.visitWhileStatement(node); |
| 216 } | 229 } |
| 217 | 230 |
| 218 visitDoStatement(ir.DoStatement node) { | 231 visitDoStatement(ir.DoStatement node) { |
| 219 addTargetData(node, _localsMap.getJumpTargetForDo(node)); | 232 addTargetData( |
| 233 node, computeLoopNodeId(node), _localsMap.getJumpTargetForDo(node)); |
| 220 super.visitDoStatement(node); | 234 super.visitDoStatement(node); |
| 221 } | 235 } |
| 222 | 236 |
| 223 visitBreakStatement(ir.BreakStatement node) { | 237 visitBreakStatement(ir.BreakStatement node) { |
| 224 JumpTarget target = _localsMap.getJumpTargetForBreak(node); | 238 JumpTarget target = _localsMap.getJumpTargetForBreak(node); |
| 225 assert(target != null, 'No target for $node.'); | 239 assert(target != null, 'No target for $node.'); |
| 226 NodeId id = computeGotoNodeId(node); | 240 NodeId id = computeGotoNodeId(node); |
| 227 SourceSpan sourceSpan = computeSourceSpan(node); | 241 SourceSpan sourceSpan = computeSourceSpan(node); |
| 228 gotos.add(new GotoData(id, sourceSpan, target)); | 242 gotos.add(new GotoData(id, sourceSpan, target)); |
| 229 super.visitBreakStatement(node); | 243 super.visitBreakStatement(node); |
| 230 } | 244 } |
| 231 | 245 |
| 232 visitSwitchStatement(ir.SwitchStatement node) { | 246 visitSwitchStatement(ir.SwitchStatement node) { |
| 233 addTargetData(node, _localsMap.getJumpTargetForSwitch(node)); | 247 addTargetData( |
| 248 node, computeLoopNodeId(node), _localsMap.getJumpTargetForSwitch(node)); |
| 234 super.visitSwitchStatement(node); | 249 super.visitSwitchStatement(node); |
| 235 } | 250 } |
| 251 |
| 252 visitSwitchCase(ir.SwitchCase node) { |
| 253 addTargetData(node, computeSwitchCaseNodeId(node), |
| 254 _localsMap.getJumpTargetForSwitchCase(node)); |
| 255 super.visitSwitchCase(node); |
| 256 } |
| 257 |
| 258 visitContinueSwitchStatement(ir.ContinueSwitchStatement node) { |
| 259 JumpTarget target = _localsMap.getJumpTargetForContinueSwitch(node); |
| 260 assert(target != null, 'No target for $node.'); |
| 261 NodeId id = computeGotoNodeId(node); |
| 262 SourceSpan sourceSpan = computeSourceSpan(node); |
| 263 gotos.add(new GotoData(id, sourceSpan, target)); |
| 264 super.visitContinueSwitchStatement(node); |
| 265 } |
| 236 } | 266 } |
| OLD | NEW |