OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 @override | 222 @override |
223 Local getLocal(ir.VariableDeclaration variable) { | 223 Local getLocal(ir.VariableDeclaration variable) { |
224 // If this is a synthetic local, return the synthetic local | 224 // If this is a synthetic local, return the synthetic local |
225 if (variable.name == null) { | 225 if (variable.name == null) { |
226 return _syntheticLocals.putIfAbsent( | 226 return _syntheticLocals.putIfAbsent( |
227 variable, () => new SyntheticLocal("x", null, null)); | 227 variable, () => new SyntheticLocal("x", null, null)); |
228 } | 228 } |
229 return getElement(variable) as LocalElement; | 229 return getElement(variable) as LocalElement; |
230 } | 230 } |
231 | 231 |
| 232 @override |
| 233 JumpTarget getJumpTargetForBreak(ir.BreakStatement node) { |
| 234 return getJumpTarget(node.target); |
| 235 } |
| 236 |
| 237 @override |
| 238 JumpTarget getJumpTargetForLabel(ir.LabeledStatement node) { |
| 239 return getJumpTarget(node); |
| 240 } |
| 241 |
| 242 @override |
| 243 JumpTarget getJumpTargetForSwitch(ir.SwitchStatement node) { |
| 244 return getJumpTarget(node); |
| 245 } |
| 246 |
| 247 @override |
| 248 JumpTarget getJumpTargetForContinueSwitch(ir.ContinueSwitchStatement node) { |
| 249 return getJumpTarget(node.target); |
| 250 } |
| 251 |
| 252 @override |
| 253 JumpTarget getJumpTargetForSwitchCase(ir.SwitchCase node) { |
| 254 return getJumpTarget(node, isContinueTarget: true); |
| 255 } |
| 256 |
| 257 @override |
| 258 JumpTarget getJumpTargetForDo(ir.DoStatement node) { |
| 259 return getJumpTarget(node); |
| 260 } |
| 261 |
| 262 @override |
| 263 JumpTarget getJumpTargetForFor(ir.ForStatement node) { |
| 264 return getJumpTarget(node); |
| 265 } |
| 266 |
| 267 @override |
| 268 JumpTarget getJumpTargetForForIn(ir.ForInStatement node) { |
| 269 return getJumpTarget(node); |
| 270 } |
| 271 |
| 272 @override |
| 273 JumpTarget getJumpTargetForWhile(ir.WhileStatement node) { |
| 274 return getJumpTarget(node); |
| 275 } |
| 276 |
232 KernelJumpTarget getJumpTarget(ir.TreeNode node, | 277 KernelJumpTarget getJumpTarget(ir.TreeNode node, |
233 {bool isContinueTarget: false}) { | 278 {bool isContinueTarget: false}) { |
234 return _jumpTargets.putIfAbsent(node, () { | 279 return _jumpTargets.putIfAbsent(node, () { |
235 if (node is ir.LabeledStatement && _jumpTargets.containsKey(node.body)) { | 280 if (node is ir.LabeledStatement && _jumpTargets.containsKey(node.body)) { |
236 return _jumpTargets[node.body]; | 281 return _jumpTargets[node.body]; |
237 } | 282 } |
238 return new KernelJumpTarget(node, this, | 283 return new KernelJumpTarget(node, this, |
239 makeContinueLabel: isContinueTarget); | 284 makeContinueLabel: isContinueTarget); |
240 }); | 285 }); |
241 } | 286 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 424 } |
380 | 425 |
381 @override | 426 @override |
382 ResolutionDartType visitInvalidType(ir.InvalidType node) { | 427 ResolutionDartType visitInvalidType(ir.InvalidType node) { |
383 // Root uses such a `o is Unresolved` and `o as Unresolved` must be special | 428 // Root uses such a `o is Unresolved` and `o as Unresolved` must be special |
384 // cased in the builder, nested invalid types are treated as `dynamic`. | 429 // cased in the builder, nested invalid types are treated as `dynamic`. |
385 return const ResolutionDynamicType(); | 430 return const ResolutionDynamicType(); |
386 } | 431 } |
387 } | 432 } |
388 | 433 |
389 class KernelJumpTarget extends JumpTarget<ast.Node> { | 434 class KernelJumpTarget implements JumpTargetX { |
390 static int index = 0; | 435 static int index = 0; |
391 | 436 |
392 /// Pointer to the actual executable statements that a jump target refers to. | 437 /// Pointer to the actual executable statements that a jump target refers to. |
393 /// If this jump target was not initially constructed with a LabeledStatement, | 438 /// If this jump target was not initially constructed with a LabeledStatement, |
394 /// this value is identical to originalStatement. This Node is actually of | 439 /// this value is identical to originalStatement. This Node is actually of |
395 /// type either ir.Statement or ir.SwitchCase. | 440 /// type either ir.Statement or ir.SwitchCase. |
396 ir.Node targetStatement; | 441 ir.Node targetStatement; |
397 | 442 |
398 /// The original statement used to construct this jump target. | 443 /// The original statement used to construct this jump target. |
399 /// If this jump target was not initially constructed with a LabeledStatement, | 444 /// If this jump target was not initially constructed with a LabeledStatement, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 } | 488 } |
444 | 489 |
445 if (makeContinueLabel) { | 490 if (makeContinueLabel) { |
446 labels.add( | 491 labels.add( |
447 new LabelDefinitionX(null, 'L${index++}', this)..setContinueTarget()); | 492 new LabelDefinitionX(null, 'L${index++}', this)..setContinueTarget()); |
448 isContinueTarget = true; | 493 isContinueTarget = true; |
449 } | 494 } |
450 } | 495 } |
451 | 496 |
452 @override | 497 @override |
453 LabelDefinition<ast.Node> addLabel(ast.Label label, String labelName) { | 498 LabelDefinition<ast.Node> addLabel(ast.Label label, String labelName, |
454 LabelDefinition result = new LabelDefinitionX(label, labelName, this); | 499 {bool isBreakTarget: false}) { |
| 500 LabelDefinitionX result = new LabelDefinitionX(label, labelName, this); |
455 labels.add(result); | 501 labels.add(result); |
| 502 if (isBreakTarget) { |
| 503 result.setBreakTarget(); |
| 504 } |
456 return result; | 505 return result; |
457 } | 506 } |
458 | 507 |
459 @override | 508 @override |
460 ExecutableElement get executableContext => null; | 509 ExecutableElement get executableContext => null; |
461 | 510 |
462 @override | 511 @override |
463 MemberElement get memberContext => null; | 512 MemberElement get memberContext => null; |
464 | 513 |
465 @override | 514 @override |
(...skipping 21 matching lines...) Expand all Loading... |
487 ir.SwitchStatement switchStatement, KernelToLocalsMap localsMap) | 536 ir.SwitchStatement switchStatement, KernelToLocalsMap localsMap) |
488 : super(builder, target) { | 537 : super(builder, target) { |
489 // The switch case indices must match those computed in | 538 // The switch case indices must match those computed in |
490 // [KernelSsaBuilder.buildSwitchCaseConstants]. | 539 // [KernelSsaBuilder.buildSwitchCaseConstants]. |
491 // Switch indices are 1-based so we can bypass the synthetic loop when no | 540 // Switch indices are 1-based so we can bypass the synthetic loop when no |
492 // cases match simply by branching on the index (which defaults to null). | 541 // cases match simply by branching on the index (which defaults to null). |
493 // TODO | 542 // TODO |
494 int switchIndex = 1; | 543 int switchIndex = 1; |
495 for (ir.SwitchCase switchCase in switchStatement.cases) { | 544 for (ir.SwitchCase switchCase in switchStatement.cases) { |
496 JumpTarget continueTarget = | 545 JumpTarget continueTarget = |
497 localsMap.getJumpTarget(switchCase, isContinueTarget: true); | 546 localsMap.getJumpTargetForSwitchCase(switchCase); |
498 assert(continueTarget is KernelJumpTarget); | 547 assert(continueTarget is KernelJumpTarget); |
499 targetIndexMap[continueTarget] = switchIndex; | 548 targetIndexMap[continueTarget] = switchIndex; |
500 assert(builder.jumpTargets[continueTarget] == null); | 549 assert(builder.jumpTargets[continueTarget] == null); |
501 builder.jumpTargets[continueTarget] = this; | 550 builder.jumpTargets[continueTarget] = this; |
502 switchIndex++; | 551 switchIndex++; |
503 } | 552 } |
504 } | 553 } |
505 } | 554 } |
506 | 555 |
507 class KernelAstTypeInferenceMap implements KernelToTypeInferenceMap { | 556 class KernelAstTypeInferenceMap implements KernelToTypeInferenceMap { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { | 662 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { |
614 return TypeMaskFactory.inferredTypeForSelector( | 663 return TypeMaskFactory.inferredTypeForSelector( |
615 selector, mask, _globalInferenceResults); | 664 selector, mask, _globalInferenceResults); |
616 } | 665 } |
617 | 666 |
618 TypeMask typeFromNativeBehavior( | 667 TypeMask typeFromNativeBehavior( |
619 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { | 668 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { |
620 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); | 669 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); |
621 } | 670 } |
622 } | 671 } |
OLD | NEW |