| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // where (C', x) = Build(e, C) | 372 // where (C', x) = Build(e, C) |
| 373 // | 373 // |
| 374 // Return without a subexpression is translated as if it were return null. | 374 // Return without a subexpression is translated as if it were return null. |
| 375 ir.Primitive visitReturn(ast.Return node) { | 375 ir.Primitive visitReturn(ast.Return node) { |
| 376 assert(irBuilder.isOpen); | 376 assert(irBuilder.isOpen); |
| 377 assert(invariant(node, node.beginToken.value != 'native')); | 377 assert(invariant(node, node.beginToken.value != 'native')); |
| 378 irBuilder.buildReturn(build(node.expression)); | 378 irBuilder.buildReturn(build(node.expression)); |
| 379 return null; | 379 return null; |
| 380 } | 380 } |
| 381 | 381 |
| 382 visitSwitchStatement(ast.SwitchStatement node) { |
| 383 assert(irBuilder.isOpen); |
| 384 // We do not handle switch statements with continue to labeled cases. |
| 385 for (ast.SwitchCase switchCase in node.cases) { |
| 386 for (ast.Node labelOrCase in switchCase.labelsAndCases) { |
| 387 if (labelOrCase is ast.Label) { |
| 388 LabelDefinition definition = elements.getLabelDefinition(labelOrCase); |
| 389 if (definition != null && definition.isContinueTarget) { |
| 390 return giveup(node, "continue to a labeled switch case"); |
| 391 } |
| 392 } |
| 393 } |
| 394 } |
| 395 |
| 396 // Each switch case contains a list of interleaved labels and expressions |
| 397 // and a non-empty body. We can ignore the labels because they are not |
| 398 // jump targets. |
| 399 List<SwitchCaseInfo> cases = <SwitchCaseInfo>[]; |
| 400 SwitchCaseInfo defaultCase; |
| 401 for (ast.SwitchCase switchCase in node.cases) { |
| 402 SwitchCaseInfo caseInfo = |
| 403 new SwitchCaseInfo(subbuildSequence(switchCase.statements)); |
| 404 if (switchCase.isDefaultCase) { |
| 405 defaultCase = caseInfo; |
| 406 } else { |
| 407 cases.add(caseInfo); |
| 408 for (ast.Node labelOrCase in switchCase.labelsAndCases) { |
| 409 if (labelOrCase is ast.CaseMatch) { |
| 410 ir.Primitive constant = translateConstant(labelOrCase.expression); |
| 411 caseInfo.addConstant(constant); |
| 412 } |
| 413 } |
| 414 } |
| 415 } |
| 416 ir.Primitive value = visit(node.expression); |
| 417 JumpTarget target = elements.getTargetDefinition(node); |
| 418 Element error = |
| 419 (compiler.backend as JavaScriptBackend).getFallThroughError(); |
| 420 irBuilder.buildSimpleSwitch(target, value, cases, defaultCase, error, |
| 421 sourceInformationBuilder.buildGeneric(node)); |
| 422 } |
| 423 |
| 382 visitTryStatement(ast.TryStatement node) { | 424 visitTryStatement(ast.TryStatement node) { |
| 383 // Finally blocks are not yet implemented. | 425 // Finally blocks are not yet implemented. |
| 384 if (node.finallyBlock != null) { | 426 if (node.finallyBlock != null) { |
| 385 return giveup(node, 'try/finally'); | 427 return giveup(node, 'try/finally'); |
| 386 } | 428 } |
| 387 | 429 |
| 388 List<CatchClauseInfo> catchClauseInfos = <CatchClauseInfo>[]; | 430 List<CatchClauseInfo> catchClauseInfos = <CatchClauseInfo>[]; |
| 389 for (ast.CatchBlock catchClause in node.catchBlocks.nodes) { | 431 for (ast.CatchBlock catchClause in node.catchBlocks.nodes) { |
| 390 assert(catchClause.exception != null); | 432 assert(catchClause.exception != null); |
| 391 LocalVariableElement exceptionVariable = elements[catchClause.exception]; | 433 LocalVariableElement exceptionVariable = elements[catchClause.exception]; |
| (...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2862 } | 2904 } |
| 2863 | 2905 |
| 2864 processSetStatic(ir.SetStatic node) { | 2906 processSetStatic(ir.SetStatic node) { |
| 2865 node.body = replacementFor(node.body); | 2907 node.body = replacementFor(node.body); |
| 2866 } | 2908 } |
| 2867 | 2909 |
| 2868 processContinuation(ir.Continuation node) { | 2910 processContinuation(ir.Continuation node) { |
| 2869 node.body = replacementFor(node.body); | 2911 node.body = replacementFor(node.body); |
| 2870 } | 2912 } |
| 2871 } | 2913 } |
| OLD | NEW |