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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 10413)
+++ runtime/vm/parser.cc (working copy)
@@ -27,6 +27,7 @@
DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors.");
DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings.");
+DEFINE_FLAG(bool, warn_legacy_catch, false, "Warning on legacy catch syntax");
static void CheckedModeHandler(bool value) {
FLAG_enable_asserts = value;
@@ -5361,6 +5362,8 @@
}
+// TODO(hausner): This structure can be simplified once the old catch
+// syntax is removed. All catch parameters in the new syntax are final.
struct CatchParamDesc {
CatchParamDesc()
: token_pos(0), type(NULL), var(NULL), is_final(false) { }
@@ -5560,17 +5563,63 @@
const intptr_t handler_pos = TokenPos();
OpenBlock(); // Start the catch block sequence.
current_block_->scope->AddLabel(end_catch_label);
- while (CurrentToken() == Token::kCATCH) {
- catch_seen = true;
+ while ((CurrentToken() == Token::kCATCH) || IsLiteral("on")) {
const intptr_t catch_pos = TokenPos();
- ConsumeToken(); // Consume the 'catch'.
- ExpectToken(Token::kLPAREN);
CatchParamDesc exception_param;
CatchParamDesc stack_trace_param;
- ParseCatchParameter(&exception_param);
- if (CurrentToken() == Token::kCOMMA) {
- ConsumeToken();
- ParseCatchParameter(&stack_trace_param);
+ catch_seen = true;
+ if (CurrentToken() == Token::kCATCH) {
+ ConsumeToken(); // Consume the 'catch'.
+ ExpectToken(Token::kLPAREN);
+ if (IsIdentifier() &&
+ ((LookaheadToken(1) == Token::kCOMMA) ||
+ (LookaheadToken(1) == Token::kRPAREN))) {
+ // New catch syntax for untyped exception variable:
+ // catch(e) or catch (e,s).
+ exception_param.is_final = true;
+ exception_param.type =
+ &AbstractType::ZoneHandle(Type::DynamicType());
+ exception_param.token_pos = TokenPos();
+ exception_param.var = ExpectIdentifier("identifier expected");
+ if (CurrentToken() == Token::kCOMMA) {
+ ConsumeToken();
+ stack_trace_param.is_final = true;
+ // TODO(hausner): Make imlicit type be StackTrace, not Dynamic.
+ stack_trace_param.type =
+ &AbstractType::ZoneHandle(Type::DynamicType());
+ stack_trace_param.token_pos = TokenPos();
+ stack_trace_param.var = ExpectIdentifier("identifier expected");
+ }
+ } else {
+ // TODO(hausner): Remove legacy syntax support.
+ if (FLAG_warn_legacy_catch) {
+ Warning("legacy catch syntax");
+ }
+ ParseCatchParameter(&exception_param);
+ if (CurrentToken() == Token::kCOMMA) {
+ ConsumeToken();
+ ParseCatchParameter(&stack_trace_param);
+ }
+ }
+ } else {
+ // on T catch(e) { ...
+ ConsumeToken(); // on
+ exception_param.is_final = true;
+ exception_param.type = &AbstractType::ZoneHandle(
+ ParseType(ClassFinalizer::kCanonicalizeWellFormed));
+ ExpectToken(Token::kCATCH);
+ ExpectToken(Token::kLPAREN);
+ exception_param.token_pos = TokenPos();
+ exception_param.var = ExpectIdentifier("identifier expected");
+ if (CurrentToken() == Token::kCOMMA) {
+ ConsumeToken();
+ stack_trace_param.is_final = true;
+ // TODO(hausner): Make imlicit type be StackTrace, not Dynamic.
+ stack_trace_param.type =
+ &AbstractType::ZoneHandle(Type::DynamicType());
+ stack_trace_param.token_pos = TokenPos();
+ stack_trace_param.var = ExpectIdentifier("identifier expected");
+ }
siva 2012/08/09 19:59:29 The processing of the stacktrace part seems identi
hausner 2012/08/09 20:14:49 True, but when I'll eliminate the code for the old
}
ExpectToken(Token::kRPAREN);
« 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