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

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

Issue 1307363005: Add optional message argument to assert statements in the VM. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: More tests. Created 4 years 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
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 #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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 DEFINE_FLAG(bool, warn_patch, false, "Warn on old-style patch syntax."); 64 DEFINE_FLAG(bool, warn_patch, false, "Warn on old-style patch syntax.");
65 DEFINE_FLAG( 65 DEFINE_FLAG(
66 bool, 66 bool,
67 await_is_keyword, 67 await_is_keyword,
68 false, 68 false,
69 "await and yield are treated as proper keywords in synchronous code."); 69 "await and yield are treated as proper keywords in synchronous code.");
70 DEFINE_FLAG(bool, 70 DEFINE_FLAG(bool,
71 assert_initializer, 71 assert_initializer,
72 false, 72 false,
73 "Allow asserts in initializer lists."); 73 "Allow asserts in initializer lists.");
74 DEFINE_FLAG(bool, assert_message, false, "Allow message in assert statements");
74 75
75 DECLARE_FLAG(bool, profile_vm); 76 DECLARE_FLAG(bool, profile_vm);
76 DECLARE_FLAG(bool, trace_service); 77 DECLARE_FLAG(bool, trace_service);
77 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); 78 DECLARE_FLAG(bool, ignore_patch_signature_mismatch);
78 79
79 // Quick access to the current thread, isolate and zone. 80 // Quick access to the current thread, isolate and zone.
80 #define T (thread()) 81 #define T (thread())
81 #define I (isolate()) 82 #define I (isolate())
82 #define Z (zone()) 83 #define Z (zone())
83 84
(...skipping 9098 matching lines...) Expand 10 before | Expand all | Expand 10 after
9182 const Class& cls = Class::Handle(Z, Library::LookupCoreClass(cls_name)); 9183 const Class& cls = Class::Handle(Z, Library::LookupCoreClass(cls_name));
9183 ASSERT(!cls.IsNull()); 9184 ASSERT(!cls.IsNull());
9184 const Function& func = Function::ZoneHandle( 9185 const Function& func = Function::ZoneHandle(
9185 Z, Resolver::ResolveStatic(cls, func_name, arguments->length(), 9186 Z, Resolver::ResolveStatic(cls, func_name, arguments->length(),
9186 arguments->names())); 9187 arguments->names()));
9187 ASSERT(!func.IsNull()); 9188 ASSERT(!func.IsNull());
9188 return new (Z) StaticCallNode(arguments->token_pos(), func, arguments); 9189 return new (Z) StaticCallNode(arguments->token_pos(), func, arguments);
9189 } 9190 }
9190 9191
9191 9192
9193 AstNode* Parser::MakeAssertCall(TokenPosition begin,
9194 TokenPosition end,
9195 AstNode* message) {
9196 ArgumentListNode* arguments = new (Z) ArgumentListNode(begin);
9197 arguments->Add(new (Z) LiteralNode(
9198 begin, Integer::ZoneHandle(Z, Integer::New(begin.Pos()))));
9199 arguments->Add(new (Z) LiteralNode(
9200 end, Integer::ZoneHandle(Z, Integer::New(end.Pos()))));
9201 if (message == NULL) {
9202 message = new (Z) LiteralNode(end, Instance::ZoneHandle(Z));
9203 }
9204 arguments->Add(message);
9205 return MakeStaticCall(Symbols::AssertionError(),
9206 Library::PrivateCoreLibName(Symbols::ThrowNew()),
9207 arguments);
9208 }
9209
9210
9192 AstNode* Parser::ParseAssertStatement(bool is_const) { 9211 AstNode* Parser::ParseAssertStatement(bool is_const) {
9193 TRACE_PARSER("ParseAssertStatement"); 9212 TRACE_PARSER("ParseAssertStatement");
9194 ConsumeToken(); // Consume assert keyword. 9213 ConsumeToken(); // Consume assert keyword.
9195 ExpectToken(Token::kLPAREN); 9214 ExpectToken(Token::kLPAREN);
9196 const TokenPosition condition_pos = TokenPos(); 9215 const TokenPosition condition_pos = TokenPos();
9197 if (!I->asserts()) { 9216 if (!I->asserts()) {
9198 SkipExpr(); 9217 SkipExpr();
9218 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) {
9219 ConsumeToken();
9220 SkipExpr();
9221 }
9199 ExpectToken(Token::kRPAREN); 9222 ExpectToken(Token::kRPAREN);
9200 return NULL; 9223 return NULL;
9201 } 9224 }
9202 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); 9225 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL);
9203 if (is_const && !condition->IsPotentiallyConst()) { 9226 if (is_const && !condition->IsPotentiallyConst()) {
9204 ReportError(condition_pos, 9227 ReportError(condition_pos,
9205 "initializer assert expression must be compile time constant."); 9228 "initializer assert expression must be compile time constant.");
9206 } 9229 }
9207 const TokenPosition condition_end = TokenPos(); 9230 const TokenPosition condition_end = TokenPos();
9231 AstNode* message = NULL;
9232 TokenPosition message_pos = TokenPosition::kNoSource;
9233 if (FLAG_assert_message && CurrentToken() == Token::kCOMMA) {
9234 ConsumeToken();
9235 message_pos = TokenPos();
9236 message = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL);
9237 if (is_const && !message->IsPotentiallyConst()) {
9238 ReportError(
9239 message_pos,
9240 "initializer assert expression must be compile time constant.");
9241 }
9242 }
9208 ExpectToken(Token::kRPAREN); 9243 ExpectToken(Token::kRPAREN);
9209 9244
9210 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); 9245 if (!is_const) {
9211 arguments->Add(condition); 9246 // Check for being a function if not const.
9212 arguments->Add(new (Z) LiteralNode( 9247 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos);
9213 condition_pos, 9248 arguments->Add(condition);
9214 Integer::ZoneHandle(Z, Integer::New(condition_pos.value(), Heap::kOld)))); 9249 condition = MakeStaticCall(
9215 arguments->Add(new (Z) LiteralNode( 9250 Symbols::AssertionError(),
9216 condition_end, 9251 Library::PrivateCoreLibName(Symbols::CheckAssertion()), arguments);
9217 Integer::ZoneHandle(Z, Integer::New(condition_end.value(), Heap::kOld)))); 9252 }
9218 AstNode* assert_throw = MakeStaticCall( 9253 AstNode* not_condition =
9219 Symbols::AssertionError(), 9254 new (Z) UnaryOpNode(condition_pos, Token::kNOT, condition);
9220 Library::PrivateCoreLibName(is_const ? Symbols::CheckConstAssertion() 9255 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end, message);
9221 : Symbols::CheckAssertion()), 9256 return new (Z)
9222 arguments); 9257 IfNode(condition_pos, not_condition,
9223 9258 NodeAsSequenceNode((message == NULL) ? condition_pos : message_pos,
9224 return assert_throw; 9259 assert_throw, NULL),
9260 NULL);
9225 } 9261 }
9226 9262
9227 9263
9228 // Populate local scope of the catch block with the catch parameters. 9264 // Populate local scope of the catch block with the catch parameters.
9229 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, 9265 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param,
9230 CatchParamDesc* stack_trace_param, 9266 CatchParamDesc* stack_trace_param,
9231 LocalScope* scope) { 9267 LocalScope* scope) {
9232 if (exception_param->name != NULL) { 9268 if (exception_param->name != NULL) {
9233 LocalVariable* var = new (Z) 9269 LocalVariable* var = new (Z)
9234 LocalVariable(exception_param->token_pos, exception_param->token_pos, 9270 LocalVariable(exception_param->token_pos, exception_param->token_pos,
(...skipping 5283 matching lines...) Expand 10 before | Expand all | Expand 10 after
14518 const ArgumentListNode& function_args, 14554 const ArgumentListNode& function_args,
14519 const LocalVariable* temp_for_last_arg, 14555 const LocalVariable* temp_for_last_arg,
14520 bool is_super_invocation) { 14556 bool is_super_invocation) {
14521 UNREACHABLE(); 14557 UNREACHABLE();
14522 return NULL; 14558 return NULL;
14523 } 14559 }
14524 14560
14525 } // namespace dart 14561 } // namespace dart
14526 14562
14527 #endif // DART_PRECOMPILED_RUNTIME 14563 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('j') | sdk/lib/core/errors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698