OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
6 | 6 |
7 import '../closure.dart' as closurelib; | 7 import '../closure.dart' as closurelib; |
8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 // where (C', x) = Build(e, C) | 383 // where (C', x) = Build(e, C) |
384 // | 384 // |
385 // Return without a subexpression is translated as if it were return null. | 385 // Return without a subexpression is translated as if it were return null. |
386 ir.Primitive visitReturn(ast.Return node) { | 386 ir.Primitive visitReturn(ast.Return node) { |
387 assert(irBuilder.isOpen); | 387 assert(irBuilder.isOpen); |
388 assert(invariant(node, node.beginToken.value != 'native')); | 388 assert(invariant(node, node.beginToken.value != 'native')); |
389 irBuilder.buildReturn(build(node.expression)); | 389 irBuilder.buildReturn(build(node.expression)); |
390 return null; | 390 return null; |
391 } | 391 } |
392 | 392 |
| 393 visitSwitchStatement(ast.SwitchStatement node) { |
| 394 assert(irBuilder.isOpen); |
| 395 // We do not handle switch statements with continue to labeled cases. |
| 396 for (ast.SwitchCase switchCase in node.cases) { |
| 397 for (ast.Node labelOrCase in switchCase.labelsAndCases) { |
| 398 if (labelOrCase is ast.Label) { |
| 399 LabelDefinition definition = elements.getLabelDefinition(labelOrCase); |
| 400 if (definition != null && definition.isContinueTarget) { |
| 401 return giveup(node, "continue to a labeled switch case"); |
| 402 } |
| 403 } |
| 404 } |
| 405 } |
| 406 |
| 407 // Each switch case contains a list of interleaved labels and expressions |
| 408 // and a non-empty body. We can ignore the labels because they are not |
| 409 // jump targets. |
| 410 List<SwitchCaseInfo> cases = <SwitchCaseInfo>[]; |
| 411 SwitchCaseInfo defaultCase; |
| 412 for (ast.SwitchCase switchCase in node.cases) { |
| 413 SwitchCaseInfo caseInfo = |
| 414 new SwitchCaseInfo(subbuildSequence(switchCase.statements)); |
| 415 if (switchCase.isDefaultCase) { |
| 416 defaultCase = caseInfo; |
| 417 } else { |
| 418 cases.add(caseInfo); |
| 419 for (ast.Node labelOrCase in switchCase.labelsAndCases) { |
| 420 if (labelOrCase is ast.CaseMatch) { |
| 421 ir.Primitive constant = translateConstant(labelOrCase.expression); |
| 422 caseInfo.addConstant(constant); |
| 423 } |
| 424 } |
| 425 } |
| 426 } |
| 427 ir.Primitive value = visit(node.expression); |
| 428 JumpTarget target = elements.getTargetDefinition(node); |
| 429 Element error = |
| 430 (compiler.backend as JavaScriptBackend).getFallThroughError(); |
| 431 irBuilder.buildSimpleSwitch(target, value, cases, defaultCase, error, |
| 432 sourceInformationBuilder.buildGeneric(node)); |
| 433 } |
| 434 |
393 visitTryStatement(ast.TryStatement node) { | 435 visitTryStatement(ast.TryStatement node) { |
394 // Finally blocks are not yet implemented. | 436 // Finally blocks are not yet implemented. |
395 if (node.finallyBlock != null) { | 437 if (node.finallyBlock != null) { |
396 return giveup(node, 'try/finally'); | 438 return giveup(node, 'try/finally'); |
397 } | 439 } |
398 | 440 |
399 List<CatchClauseInfo> catchClauseInfos = <CatchClauseInfo>[]; | 441 List<CatchClauseInfo> catchClauseInfos = <CatchClauseInfo>[]; |
400 for (ast.CatchBlock catchClause in node.catchBlocks.nodes) { | 442 for (ast.CatchBlock catchClause in node.catchBlocks.nodes) { |
401 assert(catchClause.exception != null); | 443 assert(catchClause.exception != null); |
402 LocalVariableElement exceptionVariable = elements[catchClause.exception]; | 444 LocalVariableElement exceptionVariable = elements[catchClause.exception]; |
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 } | 3137 } |
3096 | 3138 |
3097 processSetStatic(ir.SetStatic node) { | 3139 processSetStatic(ir.SetStatic node) { |
3098 node.body = replacementFor(node.body); | 3140 node.body = replacementFor(node.body); |
3099 } | 3141 } |
3100 | 3142 |
3101 processContinuation(ir.Continuation node) { | 3143 processContinuation(ir.Continuation node) { |
3102 node.body = replacementFor(node.body); | 3144 node.body = replacementFor(node.body); |
3103 } | 3145 } |
3104 } | 3146 } |
OLD | NEW |