OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of resolution; | 5 part of resolution; |
6 | 6 |
7 abstract class TreeElements { | 7 abstract class TreeElements { |
8 Element get currentElement; | 8 Element get currentElement; |
9 Set<Node> get superUses; | 9 Set<Node> get superUses; |
10 | 10 |
(...skipping 2957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2968 error(node, MessageKind.NO_CATCH_NOR_FINALLY); | 2968 error(node, MessageKind.NO_CATCH_NOR_FINALLY); |
2969 } | 2969 } |
2970 visit(node.catchBlocks); | 2970 visit(node.catchBlocks); |
2971 visit(node.finallyBlock); | 2971 visit(node.finallyBlock); |
2972 } | 2972 } |
2973 | 2973 |
2974 visitCatchBlock(CatchBlock node) { | 2974 visitCatchBlock(CatchBlock node) { |
2975 compiler.backend.registerCatchStatement(world, mapping); | 2975 compiler.backend.registerCatchStatement(world, mapping); |
2976 // Check that if catch part is present, then | 2976 // Check that if catch part is present, then |
2977 // it has one or two formal parameters. | 2977 // it has one or two formal parameters. |
| 2978 VariableDefinitions exceptionDefinition; |
| 2979 VariableDefinitions stackTraceDefinition; |
2978 if (node.formals != null) { | 2980 if (node.formals != null) { |
2979 if (node.formals.isEmpty) { | 2981 Link<Node> formalsToProcess = node.formals.nodes; |
| 2982 if (formalsToProcess.isEmpty) { |
2980 error(node, MessageKind.EMPTY_CATCH_DECLARATION); | 2983 error(node, MessageKind.EMPTY_CATCH_DECLARATION); |
2981 } | 2984 } else { |
2982 if (!node.formals.nodes.tail.isEmpty) { | 2985 exceptionDefinition = formalsToProcess.head; |
2983 if (!node.formals.nodes.tail.tail.isEmpty) { | 2986 formalsToProcess = formalsToProcess.tail; |
2984 for (Node extra in node.formals.nodes.tail.tail) { | 2987 if (!formalsToProcess.isEmpty) { |
2985 error(extra, MessageKind.EXTRA_CATCH_DECLARATION); | 2988 stackTraceDefinition = formalsToProcess.head; |
| 2989 formalsToProcess = formalsToProcess.tail; |
| 2990 if (!formalsToProcess.isEmpty) { |
| 2991 for (Node extra in formalsToProcess) { |
| 2992 error(extra, MessageKind.EXTRA_CATCH_DECLARATION); |
| 2993 } |
2986 } | 2994 } |
| 2995 compiler.backend.registerStackTraceInCatch(mapping); |
2987 } | 2996 } |
2988 compiler.backend.registerStackTraceInCatch(mapping); | |
2989 } | 2997 } |
2990 | 2998 |
2991 // Check that the formals aren't optional and that they have no | 2999 // Check that the formals aren't optional and that they have no |
2992 // modifiers or type. | 3000 // modifiers or type. |
2993 for (Link<Node> link = node.formals.nodes; | 3001 for (Link<Node> link = node.formals.nodes; |
2994 !link.isEmpty; | 3002 !link.isEmpty; |
2995 link = link.tail) { | 3003 link = link.tail) { |
2996 // If the formal parameter is a node list, it means that it is a | 3004 // If the formal parameter is a node list, it means that it is a |
2997 // sequence of optional parameters. | 3005 // sequence of optional parameters. |
2998 NodeList nodeList = link.head.asNodeList(); | 3006 NodeList nodeList = link.head.asNodeList(); |
(...skipping 15 matching lines...) Expand all Loading... |
3014 Scope blockScope = new BlockScope(scope); | 3022 Scope blockScope = new BlockScope(scope); |
3015 var wasTypeRequired = typeRequired; | 3023 var wasTypeRequired = typeRequired; |
3016 typeRequired = true; | 3024 typeRequired = true; |
3017 doInCheckContext(() => visitIn(node.type, blockScope)); | 3025 doInCheckContext(() => visitIn(node.type, blockScope)); |
3018 typeRequired = wasTypeRequired; | 3026 typeRequired = wasTypeRequired; |
3019 visitIn(node.formals, blockScope); | 3027 visitIn(node.formals, blockScope); |
3020 var oldInCatchBlock = inCatchBlock; | 3028 var oldInCatchBlock = inCatchBlock; |
3021 inCatchBlock = true; | 3029 inCatchBlock = true; |
3022 visitIn(node.block, blockScope); | 3030 visitIn(node.block, blockScope); |
3023 inCatchBlock = oldInCatchBlock; | 3031 inCatchBlock = oldInCatchBlock; |
| 3032 |
| 3033 if (node.type != null && exceptionDefinition != null) { |
| 3034 DartType exceptionType = mapping.getType(node.type); |
| 3035 Node exceptionVariable = exceptionDefinition.definitions.nodes.head; |
| 3036 VariableElementX exceptionElement = mapping[exceptionVariable]; |
| 3037 exceptionElement.variables.type = exceptionType; |
| 3038 } |
| 3039 if (stackTraceDefinition != null) { |
| 3040 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head; |
| 3041 VariableElementX stackTraceElement = mapping[stackTraceVariable]; |
| 3042 world.registerInstantiatedClass(compiler.stackTraceClass, mapping); |
| 3043 stackTraceElement.variables.type = compiler.stackTraceClass.rawType; |
| 3044 } |
3024 } | 3045 } |
3025 | 3046 |
3026 visitTypedef(Typedef node) { | 3047 visitTypedef(Typedef node) { |
3027 unimplemented(node, 'typedef'); | 3048 unimplemented(node, 'typedef'); |
3028 } | 3049 } |
3029 } | 3050 } |
3030 | 3051 |
3031 class TypeDefinitionVisitor extends MappingVisitor<DartType> { | 3052 class TypeDefinitionVisitor extends MappingVisitor<DartType> { |
3032 Scope scope; | 3053 Scope scope; |
3033 final TypeDeclarationElement enclosingElement; | 3054 final TypeDeclarationElement enclosingElement; |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3939 return e; | 3960 return e; |
3940 } | 3961 } |
3941 | 3962 |
3942 /// Assumed to be called by [resolveRedirectingFactory]. | 3963 /// Assumed to be called by [resolveRedirectingFactory]. |
3943 Element visitReturn(Return node) { | 3964 Element visitReturn(Return node) { |
3944 Node expression = node.expression; | 3965 Node expression = node.expression; |
3945 return finishConstructorReference(visit(expression), | 3966 return finishConstructorReference(visit(expression), |
3946 expression, expression); | 3967 expression, expression); |
3947 } | 3968 } |
3948 } | 3969 } |
OLD | NEW |