Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(656)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 15689009: Type check try statements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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> link = node.formals.nodes;
karlklose 2013/05/27 12:43:54 link -> formalsToProcess? formalsLink?
2982 if (link.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 = link.head;
2983 if (!node.formals.nodes.tail.tail.isEmpty) { 2986 link = link.tail;
2984 for (Node extra in node.formals.nodes.tail.tail) { 2987 if (!link.isEmpty) {
2985 error(extra, MessageKind.EXTRA_CATCH_DECLARATION); 2988 stackTraceDefinition = link.head;
2989 link = link.tail;
2990 if (!link.isEmpty) {
2991 for (Node extra in link) {
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.formals.nodes; !link.isEmpty; link = link.tail) {
2994 !link.isEmpty;
2995 link = link.tail) {
2996 // If the formal parameter is a node list, it means that it is a 3002 // If the formal parameter is a node list, it means that it is a
2997 // sequence of optional parameters. 3003 // sequence of optional parameters.
2998 NodeList nodeList = link.head.asNodeList(); 3004 NodeList nodeList = link.head.asNodeList();
2999 if (nodeList != null) { 3005 if (nodeList != null) {
3000 error(nodeList, MessageKind.OPTIONAL_PARAMETER_IN_CATCH); 3006 error(nodeList, MessageKind.OPTIONAL_PARAMETER_IN_CATCH);
3001 } else { 3007 } else {
3002 VariableDefinitions declaration = link.head; 3008 VariableDefinitions declaration = link.head;
3003 for (Node modifier in declaration.modifiers.nodes) { 3009 for (Node modifier in declaration.modifiers.nodes) {
3004 error(modifier, MessageKind.PARAMETER_WITH_MODIFIER_IN_CATCH); 3010 error(modifier, MessageKind.PARAMETER_WITH_MODIFIER_IN_CATCH);
3005 } 3011 }
3006 TypeAnnotation type = declaration.type; 3012 TypeAnnotation type = declaration.type;
3007 if (type != null) { 3013 if (type != null) {
3008 error(type, MessageKind.PARAMETER_WITH_TYPE_IN_CATCH); 3014 error(type, MessageKind.PARAMETER_WITH_TYPE_IN_CATCH);
3009 } 3015 }
3010 } 3016 }
3011 } 3017 }
3012 } 3018 }
3013 3019
3014 Scope blockScope = new BlockScope(scope); 3020 Scope blockScope = new BlockScope(scope);
3015 var wasTypeRequired = typeRequired; 3021 var wasTypeRequired = typeRequired;
3016 typeRequired = true; 3022 typeRequired = true;
3017 doInCheckContext(() => visitIn(node.type, blockScope)); 3023 doInCheckContext(() => visitIn(node.type, blockScope));
3018 typeRequired = wasTypeRequired; 3024 typeRequired = wasTypeRequired;
3019 visitIn(node.formals, blockScope); 3025 visitIn(node.formals, blockScope);
3020 var oldInCatchBlock = inCatchBlock; 3026 var oldInCatchBlock = inCatchBlock;
3021 inCatchBlock = true; 3027 inCatchBlock = true;
3022 visitIn(node.block, blockScope); 3028 visitIn(node.block, blockScope);
3023 inCatchBlock = oldInCatchBlock; 3029 inCatchBlock = oldInCatchBlock;
3030
3031 if (node.type != null && exceptionDefinition != null) {
3032 DartType exceptionType = mapping.getType(node.type);
3033 Node exceptionVariable = exceptionDefinition.definitions.nodes.head;
3034 VariableElementX exceptionElement = mapping[exceptionVariable];
3035 exceptionElement.variables.type = exceptionType;
3036 }
3037 if (stackTraceDefinition != null) {
3038 Node stackTraceVariable = stackTraceDefinition.definitions.nodes.head;
3039 VariableElementX stackTraceElement = mapping[stackTraceVariable];
3040 world.registerInstantiatedClass(compiler.stackTraceClass, mapping);
3041 stackTraceElement.variables.type = compiler.stackTraceClass.rawType;
3042 }
3024 } 3043 }
3025 3044
3026 visitTypedef(Typedef node) { 3045 visitTypedef(Typedef node) {
3027 unimplemented(node, 'typedef'); 3046 unimplemented(node, 'typedef');
3028 } 3047 }
3029 } 3048 }
3030 3049
3031 class TypeDefinitionVisitor extends MappingVisitor<DartType> { 3050 class TypeDefinitionVisitor extends MappingVisitor<DartType> {
3032 Scope scope; 3051 Scope scope;
3033 final TypeDeclarationElement enclosingElement; 3052 final TypeDeclarationElement enclosingElement;
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
3939 return e; 3958 return e;
3940 } 3959 }
3941 3960
3942 /// Assumed to be called by [resolveRedirectingFactory]. 3961 /// Assumed to be called by [resolveRedirectingFactory].
3943 Element visitReturn(Return node) { 3962 Element visitReturn(Return node) {
3944 Node expression = node.expression; 3963 Node expression = node.expression;
3945 return finishConstructorReference(visit(expression), 3964 return finishConstructorReference(visit(expression),
3946 expression, expression); 3965 expression, expression);
3947 } 3966 }
3948 } 3967 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/compiler.dart ('k') | sdk/lib/_internal/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698