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

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

Issue 10827240: Implement new catch syntax in vm compiler (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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/co19/co19-runtime.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"
11 #include "vm/dart_api_impl.h" 11 #include "vm/dart_api_impl.h"
12 #include "vm/dart_entry.h" 12 #include "vm/dart_entry.h"
13 #include "vm/flags.h" 13 #include "vm/flags.h"
14 #include "vm/growable_array.h" 14 #include "vm/growable_array.h"
15 #include "vm/longjump.h" 15 #include "vm/longjump.h"
16 #include "vm/native_entry.h" 16 #include "vm/native_entry.h"
17 #include "vm/object.h" 17 #include "vm/object.h"
18 #include "vm/object_store.h" 18 #include "vm/object_store.h"
19 #include "vm/resolver.h" 19 #include "vm/resolver.h"
20 #include "vm/scopes.h" 20 #include "vm/scopes.h"
21 #include "vm/symbols.h" 21 #include "vm/symbols.h"
22 22
23 namespace dart { 23 namespace dart {
24 24
25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); 25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements.");
26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); 26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks.");
27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); 27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); 28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors.");
29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); 29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings.");
30 DEFINE_FLAG(bool, warn_legacy_catch, false, "Warning on legacy catch syntax");
30 31
31 static void CheckedModeHandler(bool value) { 32 static void CheckedModeHandler(bool value) {
32 FLAG_enable_asserts = value; 33 FLAG_enable_asserts = value;
33 FLAG_enable_type_checks = value; 34 FLAG_enable_type_checks = value;
34 } 35 }
35 36
36 DEFINE_FLAG_HANDLER(CheckedModeHandler, 37 DEFINE_FLAG_HANDLER(CheckedModeHandler,
37 enable_checked_mode, 38 enable_checked_mode,
38 "Enabled checked mode."); 39 "Enabled checked mode.");
39 40
(...skipping 5314 matching lines...) Expand 10 before | Expand all | Expand 10 after
5354 condition = InsertClosureCallNodes(condition); 5355 condition = InsertClosureCallNodes(condition);
5355 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition); 5356 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition);
5356 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); 5357 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end);
5357 return new IfNode(condition_pos, 5358 return new IfNode(condition_pos,
5358 condition, 5359 condition,
5359 NodeAsSequenceNode(condition_pos, assert_throw, NULL), 5360 NodeAsSequenceNode(condition_pos, assert_throw, NULL),
5360 NULL); 5361 NULL);
5361 } 5362 }
5362 5363
5363 5364
5365 // TODO(hausner): This structure can be simplified once the old catch
5366 // syntax is removed. All catch parameters in the new syntax are final.
5364 struct CatchParamDesc { 5367 struct CatchParamDesc {
5365 CatchParamDesc() 5368 CatchParamDesc()
5366 : token_pos(0), type(NULL), var(NULL), is_final(false) { } 5369 : token_pos(0), type(NULL), var(NULL), is_final(false) { }
5367 intptr_t token_pos; 5370 intptr_t token_pos;
5368 const AbstractType* type; 5371 const AbstractType* type;
5369 const String* var; 5372 const String* var;
5370 bool is_final; 5373 bool is_final;
5371 }; 5374 };
5372 5375
5373 5376
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
5553 5556
5554 // Now parse the 'catch' blocks if any and merge all of them into 5557 // Now parse the 'catch' blocks if any and merge all of them into
5555 // an if-then sequence of the different types specified using the 'is' 5558 // an if-then sequence of the different types specified using the 'is'
5556 // operator. 5559 // operator.
5557 bool catch_seen = false; 5560 bool catch_seen = false;
5558 bool generic_catch_seen = false; 5561 bool generic_catch_seen = false;
5559 SequenceNode* catch_handler_list = NULL; 5562 SequenceNode* catch_handler_list = NULL;
5560 const intptr_t handler_pos = TokenPos(); 5563 const intptr_t handler_pos = TokenPos();
5561 OpenBlock(); // Start the catch block sequence. 5564 OpenBlock(); // Start the catch block sequence.
5562 current_block_->scope->AddLabel(end_catch_label); 5565 current_block_->scope->AddLabel(end_catch_label);
5563 while (CurrentToken() == Token::kCATCH) { 5566 while ((CurrentToken() == Token::kCATCH) || IsLiteral("on")) {
5564 catch_seen = true;
5565 const intptr_t catch_pos = TokenPos(); 5567 const intptr_t catch_pos = TokenPos();
5566 ConsumeToken(); // Consume the 'catch'.
5567 ExpectToken(Token::kLPAREN);
5568 CatchParamDesc exception_param; 5568 CatchParamDesc exception_param;
5569 CatchParamDesc stack_trace_param; 5569 CatchParamDesc stack_trace_param;
5570 ParseCatchParameter(&exception_param); 5570 catch_seen = true;
5571 if (CurrentToken() == Token::kCOMMA) { 5571 if (CurrentToken() == Token::kCATCH) {
5572 ConsumeToken(); 5572 ConsumeToken(); // Consume the 'catch'.
5573 ParseCatchParameter(&stack_trace_param); 5573 ExpectToken(Token::kLPAREN);
5574 if (IsIdentifier() &&
5575 ((LookaheadToken(1) == Token::kCOMMA) ||
5576 (LookaheadToken(1) == Token::kRPAREN))) {
5577 // New catch syntax for untyped exception variable:
5578 // catch(e) or catch (e,s).
5579 exception_param.is_final = true;
5580 exception_param.type =
5581 &AbstractType::ZoneHandle(Type::DynamicType());
5582 exception_param.token_pos = TokenPos();
5583 exception_param.var = ExpectIdentifier("identifier expected");
5584 if (CurrentToken() == Token::kCOMMA) {
5585 ConsumeToken();
5586 stack_trace_param.is_final = true;
5587 // TODO(hausner): Make imlicit type be StackTrace, not Dynamic.
5588 stack_trace_param.type =
5589 &AbstractType::ZoneHandle(Type::DynamicType());
5590 stack_trace_param.token_pos = TokenPos();
5591 stack_trace_param.var = ExpectIdentifier("identifier expected");
5592 }
5593 } else {
5594 // TODO(hausner): Remove legacy syntax support.
5595 if (FLAG_warn_legacy_catch) {
5596 Warning("legacy catch syntax");
5597 }
5598 ParseCatchParameter(&exception_param);
5599 if (CurrentToken() == Token::kCOMMA) {
5600 ConsumeToken();
5601 ParseCatchParameter(&stack_trace_param);
5602 }
5603 }
5604 } else {
5605 // on T catch(e) { ...
5606 ConsumeToken(); // on
5607 exception_param.is_final = true;
5608 exception_param.type = &AbstractType::ZoneHandle(
5609 ParseType(ClassFinalizer::kCanonicalizeWellFormed));
5610 ExpectToken(Token::kCATCH);
5611 ExpectToken(Token::kLPAREN);
5612 exception_param.token_pos = TokenPos();
5613 exception_param.var = ExpectIdentifier("identifier expected");
5614 if (CurrentToken() == Token::kCOMMA) {
5615 ConsumeToken();
5616 stack_trace_param.is_final = true;
5617 // TODO(hausner): Make imlicit type be StackTrace, not Dynamic.
5618 stack_trace_param.type =
5619 &AbstractType::ZoneHandle(Type::DynamicType());
5620 stack_trace_param.token_pos = TokenPos();
5621 stack_trace_param.var = ExpectIdentifier("identifier expected");
5622 }
5574 } 5623 }
5575 ExpectToken(Token::kRPAREN); 5624 ExpectToken(Token::kRPAREN);
5576 5625
5577 // If a generic "catch all" statement has already been seen then all 5626 // If a generic "catch all" statement has already been seen then all
5578 // subsequent catch statements are dead. We issue an error for now, 5627 // subsequent catch statements are dead. We issue an error for now,
5579 // it might make sense to turn this into a warning. 5628 // it might make sense to turn this into a warning.
5580 if (generic_catch_seen) { 5629 if (generic_catch_seen) {
5581 ErrorMsg("a generic 'catch all' statement already exists for this " 5630 ErrorMsg("a generic 'catch all' statement already exists for this "
5582 "try block. All subsequent catch statements are dead code"); 5631 "try block. All subsequent catch statements are dead code");
5583 } 5632 }
(...skipping 3379 matching lines...) Expand 10 before | Expand all | Expand 10 after
8963 void Parser::SkipQualIdent() { 9012 void Parser::SkipQualIdent() {
8964 ASSERT(IsIdentifier()); 9013 ASSERT(IsIdentifier());
8965 ConsumeToken(); 9014 ConsumeToken();
8966 if (CurrentToken() == Token::kPERIOD) { 9015 if (CurrentToken() == Token::kPERIOD) {
8967 ConsumeToken(); // Consume the kPERIOD token. 9016 ConsumeToken(); // Consume the kPERIOD token.
8968 ExpectIdentifier("identifier expected after '.'"); 9017 ExpectIdentifier("identifier expected after '.'");
8969 } 9018 }
8970 } 9019 }
8971 9020
8972 } // namespace dart 9021 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698