| 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"); | |
| 74 | 73 |
| 75 DECLARE_FLAG(bool, profile_vm); | 74 DECLARE_FLAG(bool, profile_vm); |
| 76 DECLARE_FLAG(bool, trace_service); | 75 DECLARE_FLAG(bool, trace_service); |
| 77 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); | 76 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); |
| 78 | 77 |
| 79 // Quick access to the current thread, isolate and zone. | 78 // Quick access to the current thread, isolate and zone. |
| 80 #define T (thread()) | 79 #define T (thread()) |
| 81 #define I (isolate()) | 80 #define I (isolate()) |
| 82 #define Z (zone()) | 81 #define Z (zone()) |
| 83 | 82 |
| (...skipping 9074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9158 } | 9157 } |
| 9159 | 9158 |
| 9160 | 9159 |
| 9161 AstNode* Parser::ParseAssertStatement(bool is_const) { | 9160 AstNode* Parser::ParseAssertStatement(bool is_const) { |
| 9162 TRACE_PARSER("ParseAssertStatement"); | 9161 TRACE_PARSER("ParseAssertStatement"); |
| 9163 ConsumeToken(); // Consume assert keyword. | 9162 ConsumeToken(); // Consume assert keyword. |
| 9164 ExpectToken(Token::kLPAREN); | 9163 ExpectToken(Token::kLPAREN); |
| 9165 const TokenPosition condition_pos = TokenPos(); | 9164 const TokenPosition condition_pos = TokenPos(); |
| 9166 if (!I->asserts()) { | 9165 if (!I->asserts()) { |
| 9167 SkipExpr(); | 9166 SkipExpr(); |
| 9168 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) { | |
| 9169 ConsumeToken(); | |
| 9170 SkipExpr(); | |
| 9171 } | |
| 9172 ExpectToken(Token::kRPAREN); | 9167 ExpectToken(Token::kRPAREN); |
| 9173 return NULL; | 9168 return NULL; |
| 9174 } | 9169 } |
| 9175 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); | 9170 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); |
| 9176 if (is_const && !condition->IsPotentiallyConst()) { | 9171 if (is_const && !condition->IsPotentiallyConst()) { |
| 9177 ReportError(condition_pos, | 9172 ReportError(condition_pos, |
| 9178 "initializer assert expression must be compile time constant."); | 9173 "initializer assert expression must be compile time constant."); |
| 9179 } | 9174 } |
| 9180 const TokenPosition condition_end = TokenPos(); | 9175 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 } | |
| 9193 ExpectToken(Token::kRPAREN); | 9176 ExpectToken(Token::kRPAREN); |
| 9194 | 9177 |
| 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 | |
| 9207 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); | 9178 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); |
| 9179 arguments->Add(condition); |
| 9208 arguments->Add(new (Z) LiteralNode( | 9180 arguments->Add(new (Z) LiteralNode( |
| 9209 condition_pos, | 9181 condition_pos, |
| 9210 Integer::ZoneHandle(Z, Integer::New(condition_pos.Pos())))); | 9182 Integer::ZoneHandle(Z, Integer::New(condition_pos.value(), Heap::kOld)))); |
| 9211 arguments->Add(new (Z) LiteralNode( | 9183 arguments->Add(new (Z) LiteralNode( |
| 9212 condition_end, | 9184 condition_end, |
| 9213 Integer::ZoneHandle(Z, Integer::New(condition_end.Pos())))); | 9185 Integer::ZoneHandle(Z, Integer::New(condition_end.value(), Heap::kOld)))); |
| 9214 if (message == NULL) { | |
| 9215 message = new (Z) LiteralNode(condition_end, Instance::ZoneHandle(Z)); | |
| 9216 } | |
| 9217 arguments->Add(message); | |
| 9218 AstNode* assert_throw = MakeStaticCall( | 9186 AstNode* assert_throw = MakeStaticCall( |
| 9219 Symbols::AssertionError(), | 9187 Symbols::AssertionError(), |
| 9220 Library::PrivateCoreLibName(Symbols::ThrowNew()), arguments); | 9188 Library::PrivateCoreLibName(is_const ? Symbols::CheckConstAssertion() |
| 9189 : Symbols::CheckAssertion()), |
| 9190 arguments); |
| 9221 | 9191 |
| 9222 return new (Z) | 9192 return assert_throw; |
| 9223 IfNode(condition_pos, not_condition, | |
| 9224 NodeAsSequenceNode((message == NULL) ? condition_pos : message_pos, | |
| 9225 assert_throw, NULL), | |
| 9226 NULL); | |
| 9227 } | 9193 } |
| 9228 | 9194 |
| 9229 | 9195 |
| 9230 // Populate local scope of the catch block with the catch parameters. | 9196 // Populate local scope of the catch block with the catch parameters. |
| 9231 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, | 9197 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, |
| 9232 CatchParamDesc* stack_trace_param, | 9198 CatchParamDesc* stack_trace_param, |
| 9233 LocalScope* scope) { | 9199 LocalScope* scope) { |
| 9234 if (exception_param->name != NULL) { | 9200 if (exception_param->name != NULL) { |
| 9235 LocalVariable* var = new (Z) | 9201 LocalVariable* var = new (Z) |
| 9236 LocalVariable(exception_param->token_pos, exception_param->token_pos, | 9202 LocalVariable(exception_param->token_pos, exception_param->token_pos, |
| (...skipping 5281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14518 const ArgumentListNode& function_args, | 14484 const ArgumentListNode& function_args, |
| 14519 const LocalVariable* temp_for_last_arg, | 14485 const LocalVariable* temp_for_last_arg, |
| 14520 bool is_super_invocation) { | 14486 bool is_super_invocation) { |
| 14521 UNREACHABLE(); | 14487 UNREACHABLE(); |
| 14522 return NULL; | 14488 return NULL; |
| 14523 } | 14489 } |
| 14524 | 14490 |
| 14525 } // namespace dart | 14491 } // namespace dart |
| 14526 | 14492 |
| 14527 #endif // DART_PRECOMPILED_RUNTIME | 14493 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |