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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
6 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 DEFINE_FLAG(bool, warn_patch, false, "Warn on old-style patch syntax."); | 63 DEFINE_FLAG(bool, warn_patch, false, "Warn on old-style patch syntax."); |
64 DEFINE_FLAG( | 64 DEFINE_FLAG( |
65 bool, | 65 bool, |
66 await_is_keyword, | 66 await_is_keyword, |
67 false, | 67 false, |
68 "await and yield are treated as proper keywords in synchronous code."); | 68 "await and yield are treated as proper keywords in synchronous code."); |
69 DEFINE_FLAG(bool, | 69 DEFINE_FLAG(bool, |
70 assert_initializer, | 70 assert_initializer, |
71 false, | 71 false, |
72 "Allow asserts in initializer lists."); | 72 "Allow asserts in initializer lists."); |
| 73 DEFINE_FLAG(bool, assert_message, false, "Allow message in assert statements"); |
73 | 74 |
74 DECLARE_FLAG(bool, profile_vm); | 75 DECLARE_FLAG(bool, profile_vm); |
75 DECLARE_FLAG(bool, trace_service); | 76 DECLARE_FLAG(bool, trace_service); |
76 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 77 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
77 | 78 |
78 // Quick access to the current thread, isolate and zone. | 79 // Quick access to the current thread, isolate and zone. |
79 #define T (thread()) | 80 #define T (thread()) |
80 #define I (isolate()) | 81 #define I (isolate()) |
81 #define Z (zone()) | 82 #define Z (zone()) |
82 | 83 |
(...skipping 9074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9157 } | 9158 } |
9158 | 9159 |
9159 | 9160 |
9160 AstNode* Parser::ParseAssertStatement(bool is_const) { | 9161 AstNode* Parser::ParseAssertStatement(bool is_const) { |
9161 TRACE_PARSER("ParseAssertStatement"); | 9162 TRACE_PARSER("ParseAssertStatement"); |
9162 ConsumeToken(); // Consume assert keyword. | 9163 ConsumeToken(); // Consume assert keyword. |
9163 ExpectToken(Token::kLPAREN); | 9164 ExpectToken(Token::kLPAREN); |
9164 const TokenPosition condition_pos = TokenPos(); | 9165 const TokenPosition condition_pos = TokenPos(); |
9165 if (!I->asserts()) { | 9166 if (!I->asserts()) { |
9166 SkipExpr(); | 9167 SkipExpr(); |
| 9168 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) { |
| 9169 ConsumeToken(); |
| 9170 SkipExpr(); |
| 9171 } |
9167 ExpectToken(Token::kRPAREN); | 9172 ExpectToken(Token::kRPAREN); |
9168 return NULL; | 9173 return NULL; |
9169 } | 9174 } |
9170 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); | 9175 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); |
9171 if (is_const && !condition->IsPotentiallyConst()) { | 9176 if (is_const && !condition->IsPotentiallyConst()) { |
9172 ReportError(condition_pos, | 9177 ReportError(condition_pos, |
9173 "initializer assert expression must be compile time constant."); | 9178 "initializer assert expression must be compile time constant."); |
9174 } | 9179 } |
9175 const TokenPosition condition_end = TokenPos(); | 9180 const TokenPosition condition_end = TokenPos(); |
| 9181 AstNode* message = NULL; |
| 9182 TokenPosition message_pos = TokenPosition::kNoSource; |
| 9183 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) { |
| 9184 ConsumeToken(); |
| 9185 message_pos = TokenPos(); |
| 9186 message = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); |
| 9187 if (is_const && !message->IsPotentiallyConst()) { |
| 9188 ReportError( |
| 9189 message_pos, |
| 9190 "initializer assert expression must be compile time constant."); |
| 9191 } |
| 9192 } |
9176 ExpectToken(Token::kRPAREN); | 9193 ExpectToken(Token::kRPAREN); |
9177 | 9194 |
| 9195 if (!is_const) { |
| 9196 // Check for being a function if not const. |
| 9197 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); |
| 9198 arguments->Add(condition); |
| 9199 condition = MakeStaticCall( |
| 9200 Symbols::AssertionError(), |
| 9201 Library::PrivateCoreLibName(Symbols::CheckAssertion()), arguments); |
| 9202 } |
| 9203 AstNode* not_condition = |
| 9204 new (Z) UnaryOpNode(condition_pos, Token::kNOT, condition); |
| 9205 |
| 9206 // Build call to _AsertionError._throwNew |
9178 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); | 9207 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); |
9179 arguments->Add(condition); | |
9180 arguments->Add(new (Z) LiteralNode( | 9208 arguments->Add(new (Z) LiteralNode( |
9181 condition_pos, | 9209 condition_pos, |
9182 Integer::ZoneHandle(Z, Integer::New(condition_pos.value(), Heap::kOld)))); | 9210 Integer::ZoneHandle(Z, Integer::New(condition_pos.Pos())))); |
9183 arguments->Add(new (Z) LiteralNode( | 9211 arguments->Add(new (Z) LiteralNode( |
9184 condition_end, | 9212 condition_end, |
9185 Integer::ZoneHandle(Z, Integer::New(condition_end.value(), Heap::kOld)))); | 9213 Integer::ZoneHandle(Z, Integer::New(condition_end.Pos())))); |
| 9214 if (message == NULL) { |
| 9215 message = new (Z) LiteralNode(condition_end, Instance::ZoneHandle(Z)); |
| 9216 } |
| 9217 arguments->Add(message); |
9186 AstNode* assert_throw = MakeStaticCall( | 9218 AstNode* assert_throw = MakeStaticCall( |
9187 Symbols::AssertionError(), | 9219 Symbols::AssertionError(), |
9188 Library::PrivateCoreLibName(is_const ? Symbols::CheckConstAssertion() | 9220 Library::PrivateCoreLibName(Symbols::ThrowNew()), arguments); |
9189 : Symbols::CheckAssertion()), | |
9190 arguments); | |
9191 | 9221 |
9192 return assert_throw; | 9222 return new (Z) |
| 9223 IfNode(condition_pos, not_condition, |
| 9224 NodeAsSequenceNode((message == NULL) ? condition_pos : message_pos, |
| 9225 assert_throw, NULL), |
| 9226 NULL); |
9193 } | 9227 } |
9194 | 9228 |
9195 | 9229 |
9196 // Populate local scope of the catch block with the catch parameters. | 9230 // Populate local scope of the catch block with the catch parameters. |
9197 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, | 9231 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, |
9198 CatchParamDesc* stack_trace_param, | 9232 CatchParamDesc* stack_trace_param, |
9199 LocalScope* scope) { | 9233 LocalScope* scope) { |
9200 if (exception_param->name != NULL) { | 9234 if (exception_param->name != NULL) { |
9201 LocalVariable* var = new (Z) | 9235 LocalVariable* var = new (Z) |
9202 LocalVariable(exception_param->token_pos, exception_param->token_pos, | 9236 LocalVariable(exception_param->token_pos, exception_param->token_pos, |
(...skipping 5281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14484 const ArgumentListNode& function_args, | 14518 const ArgumentListNode& function_args, |
14485 const LocalVariable* temp_for_last_arg, | 14519 const LocalVariable* temp_for_last_arg, |
14486 bool is_super_invocation) { | 14520 bool is_super_invocation) { |
14487 UNREACHABLE(); | 14521 UNREACHABLE(); |
14488 return NULL; | 14522 return NULL; |
14489 } | 14523 } |
14490 | 14524 |
14491 } // namespace dart | 14525 } // namespace dart |
14492 | 14526 |
14493 #endif // DART_PRECOMPILED_RUNTIME | 14527 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |