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

Side by Side Diff: runtime/vm/parser.cc

Issue 9416067: Fix cacthing exception object: a null exception is always caught. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 4827 matching lines...) Expand 10 before | Expand all | Expand 10 after
4838 // Now create a label for the end of catch block processing so that we can 4838 // Now create a label for the end of catch block processing so that we can
4839 // jump over the catch block code after executing the try block. 4839 // jump over the catch block code after executing the try block.
4840 SourceLabel* end_catch_label = 4840 SourceLabel* end_catch_label =
4841 SourceLabel::New(token_index_, NULL, SourceLabel::kCatch); 4841 SourceLabel::New(token_index_, NULL, SourceLabel::kCatch);
4842 4842
4843 // Now parse the 'catch' blocks if any and merge all of them into 4843 // Now parse the 'catch' blocks if any and merge all of them into
4844 // an if-then sequence of the different types specified using the 'is' 4844 // an if-then sequence of the different types specified using the 'is'
4845 // operator. 4845 // operator.
4846 bool catch_seen = false; 4846 bool catch_seen = false;
4847 bool generic_catch_seen = false; 4847 bool generic_catch_seen = false;
4848 intptr_t catch_clause_count = 0;
4848 SequenceNode* catch_handler_list = NULL; 4849 SequenceNode* catch_handler_list = NULL;
4849 const intptr_t handler_pos = token_index_; 4850 const intptr_t handler_pos = token_index_;
4850 OpenBlock(); // Start the catch block sequence. 4851 OpenBlock(); // Start the catch block sequence.
4851 current_block_->scope->AddLabel(end_catch_label); 4852 current_block_->scope->AddLabel(end_catch_label);
4852 while (CurrentToken() == Token::kCATCH) { 4853 while (CurrentToken() == Token::kCATCH) {
4854 catch_clause_count++;
4853 catch_seen = true; 4855 catch_seen = true;
4854 const intptr_t catch_pos = token_index_; 4856 const intptr_t catch_pos = token_index_;
4855 ConsumeToken(); // Consume the 'catch'. 4857 ConsumeToken(); // Consume the 'catch'.
4856 ExpectToken(Token::kLPAREN); 4858 ExpectToken(Token::kLPAREN);
4857 CatchParamDesc exception_param; 4859 CatchParamDesc exception_param;
4858 CatchParamDesc stack_trace_param; 4860 CatchParamDesc stack_trace_param;
4859 ParseCatchParameter(&exception_param); 4861 ParseCatchParameter(&exception_param);
4860 if (CurrentToken() == Token::kCOMMA) { 4862 if (CurrentToken() == Token::kCOMMA) {
4861 ConsumeToken(); 4863 ConsumeToken();
4862 ParseCatchParameter(&stack_trace_param); 4864 ParseCatchParameter(&stack_trace_param);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4913 if (!exception_param.type->IsDynamicType()) { // Has a type specification. 4915 if (!exception_param.type->IsDynamicType()) { // Has a type specification.
4914 // Now form an 'if type check' as an exception type exists in 4916 // Now form an 'if type check' as an exception type exists in
4915 // the catch specifier. 4917 // the catch specifier.
4916 if (!exception_param.type->IsInstantiated() && 4918 if (!exception_param.type->IsInstantiated() &&
4917 (current_block_->scope->function_level() > 0)) { 4919 (current_block_->scope->function_level() > 0)) {
4918 // Make sure that the instantiator is captured. 4920 // Make sure that the instantiator is captured.
4919 CaptureReceiver(); 4921 CaptureReceiver();
4920 } 4922 }
4921 AstNode* exception_type = new TypeNode(catch_pos, *exception_param.type); 4923 AstNode* exception_type = new TypeNode(catch_pos, *exception_param.type);
4922 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var); 4924 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var);
4923 AstNode* cond_expr = new ComparisonNode( 4925 AstNode* type_cond_expr = new ComparisonNode(
4924 catch_pos, Token::kIS, exception_var, exception_type); 4926 catch_pos, Token::kIS, exception_var, exception_type);
4925 current_block_->statements->Add( 4927 if (catch_clause_count == 1) {
4926 new IfNode(catch_pos, cond_expr, catch_handler, NULL)); 4928 // Null is also allowed, but check only in the first clause.
4929 AstNode* null_literal =
4930 new LiteralNode(catch_pos, Instance::ZoneHandle(Instance::null()));
4931 AstNode* null_cond_expr = new ComparisonNode(
4932 catch_pos, Token::kEQ_STRICT, exception_var, null_literal);
4933 AstNode* or_node = new BinaryOpNode(
4934 catch_pos, Token::kOR, null_cond_expr, type_cond_expr);
4935 current_block_->statements->Add(
4936 new IfNode(catch_pos, or_node, catch_handler, NULL));
4937 } else {
4938 current_block_->statements->Add(
4939 new IfNode(catch_pos, type_cond_expr, catch_handler, NULL));
4940 }
4927 } else { 4941 } else {
4928 // No exception type exists in the catch specifier so execute the 4942 // No exception type exists in the catch specifier so execute the
4929 // catch handler code unconditionally. 4943 // catch handler code unconditionally.
4930 current_block_->statements->Add(catch_handler); 4944 current_block_->statements->Add(catch_handler);
4931 generic_catch_seen = true; 4945 generic_catch_seen = true;
4932 } 4946 }
4933 catch_clause = CloseBlock(); 4947 catch_clause = CloseBlock();
4934 4948
4935 // Add this individual catch handler to the catch handlers list. 4949 // Add this individual catch handler to the catch handlers list.
4936 current_block_->statements->Add(catch_clause); 4950 current_block_->statements->Add(catch_clause);
(...skipping 2910 matching lines...) Expand 10 before | Expand all | Expand 10 after
7847 void Parser::SkipQualIdent() { 7861 void Parser::SkipQualIdent() {
7848 ASSERT(IsIdentifier()); 7862 ASSERT(IsIdentifier());
7849 ConsumeToken(); 7863 ConsumeToken();
7850 if (CurrentToken() == Token::kPERIOD) { 7864 if (CurrentToken() == Token::kPERIOD) {
7851 ConsumeToken(); // Consume the kPERIOD token. 7865 ConsumeToken(); // Consume the kPERIOD token.
7852 ExpectIdentifier("identifier expected after '.'"); 7866 ExpectIdentifier("identifier expected after '.'");
7853 } 7867 }
7854 } 7868 }
7855 7869
7856 } // namespace dart 7870 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698