Chromium Code Reviews| 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 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); | 41 DEFINE_FLAG(bool, enable_debug_break, false, "Allow use of break \"message\"."); |
| 42 DEFINE_FLAG(bool, enable_mirrors, true, | 42 DEFINE_FLAG(bool, enable_mirrors, true, |
| 43 "Disable to make importing dart:mirrors an error."); | 43 "Disable to make importing dart:mirrors an error."); |
| 44 DEFINE_FLAG(bool, load_deferred_eagerly, false, | 44 DEFINE_FLAG(bool, load_deferred_eagerly, false, |
| 45 "Load deferred libraries eagerly."); | 45 "Load deferred libraries eagerly."); |
| 46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 46 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
| 47 DEFINE_FLAG(bool, supermixin, false, "Allow super calls in mixins."); | 47 DEFINE_FLAG(bool, supermixin, false, "Allow super calls in mixins."); |
| 48 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); | 48 DEFINE_FLAG(bool, warn_mixin_typedef, true, "Warning on legacy mixin typedef."); |
| 49 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily"); | 49 DEFINE_FLAG(bool, link_natives_lazily, false, "Link native calls lazily"); |
| 50 DEFINE_FLAG(bool, assert_message, false, "Allow message in assert statements"); | |
|
Lasse Reichstein Nielsen
2015/08/28 18:51:59
Should it be "enable_assert_message" instead?
Ivan Posva
2015/09/04 06:39:31
Please coordinate across the implementations. Sinc
| |
| 50 | 51 |
| 51 DECLARE_FLAG(bool, lazy_dispatchers); | 52 DECLARE_FLAG(bool, lazy_dispatchers); |
| 52 DECLARE_FLAG(bool, load_deferred_eagerly); | 53 DECLARE_FLAG(bool, load_deferred_eagerly); |
| 53 DECLARE_FLAG(bool, profile_vm); | 54 DECLARE_FLAG(bool, profile_vm); |
| 54 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); | 55 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); |
| 55 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 56 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 56 | 57 |
| 57 // Quick access to the current thread, isolate and zone. | 58 // Quick access to the current thread, isolate and zone. |
| 58 #define T (thread()) | 59 #define T (thread()) |
| 59 #define I (isolate()) | 60 #define I (isolate()) |
| (...skipping 9048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9108 const Function& func = Function::ZoneHandle(Z, | 9109 const Function& func = Function::ZoneHandle(Z, |
| 9109 Resolver::ResolveStatic(cls, | 9110 Resolver::ResolveStatic(cls, |
| 9110 func_name, | 9111 func_name, |
| 9111 arguments->length(), | 9112 arguments->length(), |
| 9112 arguments->names())); | 9113 arguments->names())); |
| 9113 ASSERT(!func.IsNull()); | 9114 ASSERT(!func.IsNull()); |
| 9114 return new(Z) StaticCallNode(arguments->token_pos(), func, arguments); | 9115 return new(Z) StaticCallNode(arguments->token_pos(), func, arguments); |
| 9115 } | 9116 } |
| 9116 | 9117 |
| 9117 | 9118 |
| 9118 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { | 9119 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end, |
| 9120 AstNode* message) { | |
| 9119 ArgumentListNode* arguments = new(Z) ArgumentListNode(begin); | 9121 ArgumentListNode* arguments = new(Z) ArgumentListNode(begin); |
| 9120 arguments->Add(new(Z) LiteralNode(begin, | 9122 arguments->Add(new(Z) LiteralNode(begin, |
| 9121 Integer::ZoneHandle(Z, Integer::New(begin)))); | 9123 Integer::ZoneHandle(Z, Integer::New(begin)))); |
| 9122 arguments->Add(new(Z) LiteralNode(end, | 9124 arguments->Add(new(Z) LiteralNode(end, |
| 9123 Integer::ZoneHandle(Z, Integer::New(end)))); | 9125 Integer::ZoneHandle(Z, Integer::New(end)))); |
| 9126 if (message == NULL) { | |
| 9127 message = new(Z) LiteralNode(end, Instance::ZoneHandle(Z)); | |
| 9128 } | |
| 9129 arguments->Add(message); | |
| 9124 return MakeStaticCall(Symbols::AssertionError(), | 9130 return MakeStaticCall(Symbols::AssertionError(), |
| 9125 Library::PrivateCoreLibName(Symbols::ThrowNew()), | 9131 Library::PrivateCoreLibName(Symbols::ThrowNew()), |
| 9126 arguments); | 9132 arguments); |
| 9127 } | 9133 } |
| 9128 | 9134 |
| 9129 | 9135 |
| 9130 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { | 9136 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { |
| 9131 if (condition->IsClosureNode() || | 9137 if (condition->IsClosureNode() || |
| 9132 (condition->IsStoreLocalNode() && | 9138 (condition->IsStoreLocalNode() && |
| 9133 condition->AsStoreLocalNode()->value()->IsClosureNode())) { | 9139 condition->AsStoreLocalNode()->value()->IsClosureNode())) { |
| 9134 // Function literal in assert implies a call. | 9140 // Function literal in assert implies a call. |
| 9135 const intptr_t pos = condition->token_pos(); | 9141 const intptr_t pos = condition->token_pos(); |
| 9136 condition = BuildClosureCall(pos, | 9142 condition = BuildClosureCall(pos, |
| 9137 condition, | 9143 condition, |
| 9138 new(Z) ArgumentListNode(pos)); | 9144 new(Z) ArgumentListNode(pos)); |
| 9139 } else if (condition->IsConditionalExprNode()) { | 9145 } else if (condition->IsConditionalExprNode()) { |
| 9140 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode(); | 9146 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode(); |
| 9141 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr())); | 9147 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr())); |
| 9142 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr())); | 9148 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr())); |
| 9143 } | 9149 } |
| 9144 return condition; | 9150 return condition; |
| 9145 } | 9151 } |
| 9146 | 9152 |
| 9147 | 9153 |
| 9148 AstNode* Parser::ParseAssertStatement() { | 9154 AstNode* Parser::ParseAssertStatement() { |
| 9149 TRACE_PARSER("ParseAssertStatement"); | 9155 TRACE_PARSER("ParseAssertStatement"); |
| 9150 ConsumeToken(); // Consume assert keyword. | 9156 ConsumeToken(); // Consume assert keyword. |
| 9151 ExpectToken(Token::kLPAREN); | 9157 ExpectToken(Token::kLPAREN); |
| 9152 const intptr_t condition_pos = TokenPos(); | 9158 const intptr_t condition_pos = TokenPos(); |
| 9153 if (!I->flags().asserts() && !I->flags().type_checks()) { | 9159 if (!I->flags().asserts() && !I->flags().type_checks()) { |
|
Ivan Posva
2015/09/04 06:39:31
This line here testing the flag configuration is w
| |
| 9154 SkipExpr(); | 9160 SkipExpr(); |
| 9161 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) { | |
| 9162 ConsumeToken(); | |
| 9163 SkipExpr(); | |
| 9164 } | |
| 9155 ExpectToken(Token::kRPAREN); | 9165 ExpectToken(Token::kRPAREN); |
| 9156 return NULL; | 9166 return NULL; |
| 9157 } | 9167 } |
| 9158 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); | 9168 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); |
| 9169 AstNode* message = NULL; | |
| 9159 const intptr_t condition_end = TokenPos(); | 9170 const intptr_t condition_end = TokenPos(); |
| 9171 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) { | |
| 9172 ConsumeToken(); | |
| 9173 message = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); | |
| 9174 } | |
| 9160 ExpectToken(Token::kRPAREN); | 9175 ExpectToken(Token::kRPAREN); |
| 9161 condition = InsertClosureCallNodes(condition); | 9176 condition = InsertClosureCallNodes(condition); |
| 9162 condition = new(Z) UnaryOpNode(condition_pos, Token::kNOT, condition); | 9177 condition = new(Z) UnaryOpNode(condition_pos, Token::kNOT, condition); |
| 9163 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); | 9178 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end, message); |
| 9164 return new(Z) IfNode( | 9179 return new(Z) IfNode( |
| 9165 condition_pos, | 9180 condition_pos, |
| 9166 condition, | 9181 condition, |
| 9167 NodeAsSequenceNode(condition_pos, assert_throw, NULL), | 9182 NodeAsSequenceNode(condition_pos, assert_throw, NULL), |
| 9168 NULL); | 9183 NULL); |
| 9169 } | 9184 } |
| 9170 | 9185 |
| 9171 | 9186 |
| 9172 // Populate local scope of the catch block with the catch parameters. | 9187 // Populate local scope of the catch block with the catch parameters. |
| 9173 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, | 9188 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, |
| (...skipping 5115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14289 void Parser::SkipQualIdent() { | 14304 void Parser::SkipQualIdent() { |
| 14290 ASSERT(IsIdentifier()); | 14305 ASSERT(IsIdentifier()); |
| 14291 ConsumeToken(); | 14306 ConsumeToken(); |
| 14292 if (CurrentToken() == Token::kPERIOD) { | 14307 if (CurrentToken() == Token::kPERIOD) { |
| 14293 ConsumeToken(); // Consume the kPERIOD token. | 14308 ConsumeToken(); // Consume the kPERIOD token. |
| 14294 ExpectIdentifier("identifier expected after '.'"); | 14309 ExpectIdentifier("identifier expected after '.'"); |
| 14295 } | 14310 } |
| 14296 } | 14311 } |
| 14297 | 14312 |
| 14298 } // namespace dart | 14313 } // namespace dart |
| OLD | NEW |