| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 | 127 |
| 128 #define TRACE_PARSER(s) \ | 128 #define TRACE_PARSER(s) \ |
| 129 TraceParser __p__(this->TokenPos(), this->script_, &this->trace_indent_, s) | 129 TraceParser __p__(this->TokenPos(), this->script_, &this->trace_indent_, s) |
| 130 | 130 |
| 131 #else // not DEBUG | 131 #else // not DEBUG |
| 132 #define TRACE_PARSER(s) | 132 #define TRACE_PARSER(s) |
| 133 #endif // DEBUG | 133 #endif // DEBUG |
| 134 | 134 |
| 135 EnterParserScope::EnterParserScope(Thread* thread) |
| 136 : StackResource(thread), old_(thread->inside_parser_) { |
| 137 thread->inside_parser_ = true; |
| 138 } |
| 139 EnterParserScope::~EnterParserScope() { |
| 140 RELEASE_ASSERT(thread()->inside_parser_); |
| 141 thread()->inside_parser_ = old_; |
| 142 } |
| 143 |
| 144 |
| 145 LeaveParserScope::LeaveParserScope(Thread* thread) |
| 146 : StackResource(thread), old_(thread->inside_parser_) { |
| 147 thread->inside_parser_ = false; |
| 148 } |
| 149 LeaveParserScope::~LeaveParserScope() { |
| 150 RELEASE_ASSERT(!thread()->inside_parser_); |
| 151 thread()->inside_parser_ = old_; |
| 152 } |
| 153 |
| 135 | 154 |
| 136 class BoolScope : public ValueObject { | 155 class BoolScope : public ValueObject { |
| 137 public: | 156 public: |
| 138 BoolScope(bool* addr, bool new_value) : _addr(addr), _saved_value(*addr) { | 157 BoolScope(bool* addr, bool new_value) : _addr(addr), _saved_value(*addr) { |
| 139 *_addr = new_value; | 158 *_addr = new_value; |
| 140 } | 159 } |
| 141 ~BoolScope() { *_addr = _saved_value; } | 160 ~BoolScope() { *_addr = _saved_value; } |
| 142 | 161 |
| 143 private: | 162 private: |
| 144 bool* _addr; | 163 bool* _addr; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 469 } |
| 451 } | 470 } |
| 452 | 471 |
| 453 | 472 |
| 454 // For parsing a compilation unit. | 473 // For parsing a compilation unit. |
| 455 Parser::Parser(const Script& script, | 474 Parser::Parser(const Script& script, |
| 456 const Library& library, | 475 const Library& library, |
| 457 TokenPosition token_pos) | 476 TokenPosition token_pos) |
| 458 : thread_(Thread::Current()), | 477 : thread_(Thread::Current()), |
| 459 isolate_(thread()->isolate()), | 478 isolate_(thread()->isolate()), |
| 460 allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld), | 479 enter_parser_scope_(thread_), |
| 480 allocation_space_(Heap::kOld), |
| 461 script_(Script::Handle(zone(), script.raw())), | 481 script_(Script::Handle(zone(), script.raw())), |
| 462 tokens_iterator_(zone(), | 482 tokens_iterator_(zone(), |
| 463 TokenStream::Handle(zone(), script.tokens()), | 483 TokenStream::Handle(zone(), script.tokens()), |
| 464 token_pos), | 484 token_pos), |
| 465 token_kind_(Token::kILLEGAL), | 485 token_kind_(Token::kILLEGAL), |
| 466 current_block_(NULL), | 486 current_block_(NULL), |
| 467 is_top_level_(false), | 487 is_top_level_(false), |
| 468 await_is_keyword_(false), | 488 await_is_keyword_(false), |
| 469 current_member_(NULL), | 489 current_member_(NULL), |
| 470 allow_function_literals_(true), | 490 allow_function_literals_(true), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 483 ASSERT(!library.IsNull()); | 503 ASSERT(!library.IsNull()); |
| 484 } | 504 } |
| 485 | 505 |
| 486 | 506 |
| 487 // For parsing a function. | 507 // For parsing a function. |
| 488 Parser::Parser(const Script& script, | 508 Parser::Parser(const Script& script, |
| 489 ParsedFunction* parsed_function, | 509 ParsedFunction* parsed_function, |
| 490 TokenPosition token_pos) | 510 TokenPosition token_pos) |
| 491 : thread_(Thread::Current()), | 511 : thread_(Thread::Current()), |
| 492 isolate_(thread()->isolate()), | 512 isolate_(thread()->isolate()), |
| 493 allocation_space_(thread_->IsMutatorThread() ? Heap::kNew : Heap::kOld), | 513 enter_parser_scope_(thread_), |
| 514 allocation_space_(Heap::kOld), |
| 494 script_(Script::Handle(zone(), script.raw())), | 515 script_(Script::Handle(zone(), script.raw())), |
| 495 tokens_iterator_(zone(), | 516 tokens_iterator_(zone(), |
| 496 TokenStream::Handle(zone(), script.tokens()), | 517 TokenStream::Handle(zone(), script.tokens()), |
| 497 token_pos), | 518 token_pos), |
| 498 token_kind_(Token::kILLEGAL), | 519 token_kind_(Token::kILLEGAL), |
| 499 current_block_(NULL), | 520 current_block_(NULL), |
| 500 is_top_level_(false), | 521 is_top_level_(false), |
| 501 await_is_keyword_(false), | 522 await_is_keyword_(false), |
| 502 current_member_(NULL), | 523 current_member_(NULL), |
| 503 allow_function_literals_(true), | 524 allow_function_literals_(true), |
| (...skipping 5629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6133 } | 6154 } |
| 6134 return Object::null(); | 6155 return Object::null(); |
| 6135 } | 6156 } |
| 6136 ReportError(token_pos, "no library handler registered"); | 6157 ReportError(token_pos, "no library handler registered"); |
| 6137 } | 6158 } |
| 6138 // Block class finalization attempts when calling into the library | 6159 // Block class finalization attempts when calling into the library |
| 6139 // tag handler. | 6160 // tag handler. |
| 6140 I->BlockClassFinalization(); | 6161 I->BlockClassFinalization(); |
| 6141 Object& result = Object::Handle(Z); | 6162 Object& result = Object::Handle(Z); |
| 6142 { | 6163 { |
| 6164 LeaveParserScope _(thread_); |
| 6143 TransitionVMToNative transition(T); | 6165 TransitionVMToNative transition(T); |
| 6144 Api::Scope api_scope(T); | 6166 Api::Scope api_scope(T); |
| 6145 Dart_Handle retval = handler(tag, Api::NewHandle(T, library_.raw()), | 6167 Dart_Handle retval = handler(tag, Api::NewHandle(T, library_.raw()), |
| 6146 Api::NewHandle(T, url.raw())); | 6168 Api::NewHandle(T, url.raw())); |
| 6147 result = Api::UnwrapHandle(retval); | 6169 result = Api::UnwrapHandle(retval); |
| 6148 } | 6170 } |
| 6149 I->UnblockClassFinalization(); | 6171 I->UnblockClassFinalization(); |
| 6150 if (result.IsError()) { | 6172 if (result.IsError()) { |
| 6151 // In case of an error we append an explanatory error message to the | 6173 // In case of an error we append an explanatory error message to the |
| 6152 // error obtained from the library tag handler. | 6174 // error obtained from the library tag handler. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6239 continue; | 6261 continue; |
| 6240 } | 6262 } |
| 6241 // Check if this conditional line overrides the default import. | 6263 // Check if this conditional line overrides the default import. |
| 6242 const String& key = String::Handle(String::ConcatAll( | 6264 const String& key = String::Handle(String::ConcatAll( |
| 6243 Array::Handle(Array::MakeArray(pieces)), allocation_space_)); | 6265 Array::Handle(Array::MakeArray(pieces)), allocation_space_)); |
| 6244 const String& value = | 6266 const String& value = |
| 6245 (valueNode == NULL) | 6267 (valueNode == NULL) |
| 6246 ? Symbols::True() | 6268 ? Symbols::True() |
| 6247 : String::Cast(valueNode->AsLiteralNode()->literal()); | 6269 : String::Cast(valueNode->AsLiteralNode()->literal()); |
| 6248 // Call the embedder to supply us with the environment. | 6270 // Call the embedder to supply us with the environment. |
| 6249 const String& env_value = | 6271 String& env_value = String::Handle(); |
| 6250 String::Handle(Api::GetEnvironmentValue(T, key)); | 6272 { |
| 6273 LeaveParserScope _(thread_); |
| 6274 env_value = Api::GetEnvironmentValue(T, key); |
| 6275 } |
| 6251 if (!env_value.IsNull() && env_value.Equals(value)) { | 6276 if (!env_value.IsNull() && env_value.Equals(value)) { |
| 6252 condition_triggered = true; | 6277 condition_triggered = true; |
| 6253 url_literal = conditional_url_literal; | 6278 url_literal = conditional_url_literal; |
| 6254 } | 6279 } |
| 6255 } | 6280 } |
| 6256 } | 6281 } |
| 6257 ASSERT(url_literal->IsLiteralNode()); | 6282 ASSERT(url_literal->IsLiteralNode()); |
| 6258 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); | 6283 ASSERT(url_literal->AsLiteralNode()->literal().IsString()); |
| 6259 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); | 6284 const String& url = String::Cast(url_literal->AsLiteralNode()->literal()); |
| 6260 if (url.Length() == 0) { | 6285 if (url.Length() == 0) { |
| (...skipping 6461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12722 NoOOBMessageScope no_msg_scope(thread()); | 12747 NoOOBMessageScope no_msg_scope(thread()); |
| 12723 field.SetStaticValue(Object::transition_sentinel()); | 12748 field.SetStaticValue(Object::transition_sentinel()); |
| 12724 const int kTypeArgsLen = 0; // No type argument vector. | 12749 const int kTypeArgsLen = 0; // No type argument vector. |
| 12725 const int kNumArguments = 0; // No arguments. | 12750 const int kNumArguments = 0; // No arguments. |
| 12726 const Function& func = Function::Handle( | 12751 const Function& func = Function::Handle( |
| 12727 Z, Resolver::ResolveStatic(field_owner, getter_name, kTypeArgsLen, | 12752 Z, Resolver::ResolveStatic(field_owner, getter_name, kTypeArgsLen, |
| 12728 kNumArguments, Object::empty_array())); | 12753 kNumArguments, Object::empty_array())); |
| 12729 ASSERT(!func.IsNull()); | 12754 ASSERT(!func.IsNull()); |
| 12730 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); | 12755 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); |
| 12731 Object& const_value = Object::Handle(Z); | 12756 Object& const_value = Object::Handle(Z); |
| 12732 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); | 12757 { |
| 12758 LeaveParserScope _(thread_); |
| 12759 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); |
| 12760 } |
| 12733 if (const_value.IsError()) { | 12761 if (const_value.IsError()) { |
| 12734 const Error& error = Error::Cast(const_value); | 12762 const Error& error = Error::Cast(const_value); |
| 12735 if (error.IsUnhandledException()) { | 12763 if (error.IsUnhandledException()) { |
| 12736 // An exception may not occur in every parse attempt, i.e., the | 12764 // An exception may not occur in every parse attempt, i.e., the |
| 12737 // generated AST is not deterministic. Therefore mark the function as | 12765 // generated AST is not deterministic. Therefore mark the function as |
| 12738 // not optimizable. | 12766 // not optimizable. |
| 12739 current_function().SetIsOptimizable(false); | 12767 current_function().SetIsOptimizable(false); |
| 12740 field.SetStaticValue(Object::null_instance()); | 12768 field.SetStaticValue(Object::null_instance()); |
| 12741 // It is a compile-time error if evaluation of a compile-time constant | 12769 // It is a compile-time error if evaluation of a compile-time constant |
| 12742 // would raise an exception. | 12770 // would raise an exception. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12802 } | 12830 } |
| 12803 for (int i = 0; i < arguments->length(); i++) { | 12831 for (int i = 0; i < arguments->length(); i++) { |
| 12804 AstNode* arg = arguments->NodeAt(i); | 12832 AstNode* arg = arguments->NodeAt(i); |
| 12805 // Arguments have been evaluated to a literal value already. | 12833 // Arguments have been evaluated to a literal value already. |
| 12806 ASSERT(arg->IsLiteralNode()); | 12834 ASSERT(arg->IsLiteralNode()); |
| 12807 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); | 12835 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); |
| 12808 } | 12836 } |
| 12809 const Array& args_descriptor = | 12837 const Array& args_descriptor = |
| 12810 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments, | 12838 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments, |
| 12811 arguments->names())); | 12839 arguments->names())); |
| 12812 const Object& result = Object::Handle( | 12840 |
| 12813 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); | 12841 Object& result = Object::Handle(Z); |
| 12842 { |
| 12843 LeaveParserScope _(thread_); |
| 12844 result = |
| 12845 DartEntry::InvokeFunction(constructor, arg_values, args_descriptor); |
| 12846 } |
| 12847 |
| 12814 if (result.IsError()) { | 12848 if (result.IsError()) { |
| 12815 // An exception may not occur in every parse attempt, i.e., the | 12849 // An exception may not occur in every parse attempt, i.e., the |
| 12816 // generated AST is not deterministic. Therefore mark the function as | 12850 // generated AST is not deterministic. Therefore mark the function as |
| 12817 // not optimizable. | 12851 // not optimizable. |
| 12818 current_function().SetIsOptimizable(false); | 12852 current_function().SetIsOptimizable(false); |
| 12819 if (result.IsUnhandledException()) { | 12853 if (result.IsUnhandledException()) { |
| 12820 return result.raw(); | 12854 return result.raw(); |
| 12821 } else { | 12855 } else { |
| 12822 thread()->long_jump_base()->Jump(1, Error::Cast(result)); | 12856 thread()->long_jump_base()->Jump(1, Error::Cast(result)); |
| 12823 UNREACHABLE(); | 12857 UNREACHABLE(); |
| (...skipping 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14405 ASSERT(values[i]->IsLiteralNode()); | 14439 ASSERT(values[i]->IsLiteralNode()); |
| 14406 value_arr.SetAt(i, values[i]->AsLiteralNode()->literal()); | 14440 value_arr.SetAt(i, values[i]->AsLiteralNode()->literal()); |
| 14407 } | 14441 } |
| 14408 | 14442 |
| 14409 // Build argument array to pass to the interpolation function. | 14443 // Build argument array to pass to the interpolation function. |
| 14410 const Array& interpolate_arg = Array::Handle(Z, Array::New(1, Heap::kOld)); | 14444 const Array& interpolate_arg = Array::Handle(Z, Array::New(1, Heap::kOld)); |
| 14411 interpolate_arg.SetAt(0, value_arr); | 14445 interpolate_arg.SetAt(0, value_arr); |
| 14412 | 14446 |
| 14413 // Call interpolation function. | 14447 // Call interpolation function. |
| 14414 Object& result = Object::Handle(Z); | 14448 Object& result = Object::Handle(Z); |
| 14415 result = DartEntry::InvokeFunction(func, interpolate_arg); | 14449 { |
| 14450 LeaveParserScope _(thread_); |
| 14451 result = DartEntry::InvokeFunction(func, interpolate_arg); |
| 14452 } |
| 14416 if (result.IsUnhandledException()) { | 14453 if (result.IsUnhandledException()) { |
| 14417 ReportError("%s", Error::Cast(result).ToErrorCString()); | 14454 ReportError("%s", Error::Cast(result).ToErrorCString()); |
| 14418 } | 14455 } |
| 14419 String& concatenated = String::ZoneHandle(Z); | 14456 String& concatenated = String::ZoneHandle(Z); |
| 14420 concatenated ^= result.raw(); | 14457 concatenated ^= result.raw(); |
| 14421 concatenated = Symbols::New(T, concatenated); | 14458 concatenated = Symbols::New(T, concatenated); |
| 14422 return concatenated; | 14459 return concatenated; |
| 14423 } | 14460 } |
| 14424 | 14461 |
| 14425 | 14462 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14772 return value; | 14809 return value; |
| 14773 } | 14810 } |
| 14774 ReturnNode* ret = new (Z) ReturnNode(expr_pos, expr); | 14811 ReturnNode* ret = new (Z) ReturnNode(expr_pos, expr); |
| 14775 // Compile time constant expressions cannot reference anything from a | 14812 // Compile time constant expressions cannot reference anything from a |
| 14776 // local scope. | 14813 // local scope. |
| 14777 LocalScope* empty_scope = new (Z) LocalScope(NULL, 0, 0); | 14814 LocalScope* empty_scope = new (Z) LocalScope(NULL, 0, 0); |
| 14778 SequenceNode* seq = new (Z) SequenceNode(expr_pos, empty_scope); | 14815 SequenceNode* seq = new (Z) SequenceNode(expr_pos, empty_scope); |
| 14779 seq->Add(ret); | 14816 seq->Add(ret); |
| 14780 | 14817 |
| 14781 INC_STAT(thread_, num_execute_const, 1); | 14818 INC_STAT(thread_, num_execute_const, 1); |
| 14782 Object& result = Object::Handle(Z, Compiler::ExecuteOnce(seq)); | 14819 Object& result = Object::Handle(Z); |
| 14820 { |
| 14821 LeaveParserScope _(thread_); |
| 14822 result = Compiler::ExecuteOnce(seq); |
| 14823 } |
| 14783 if (result.IsError()) { | 14824 if (result.IsError()) { |
| 14784 ReportErrors(Error::Cast(result), script_, expr_pos, | 14825 ReportErrors(Error::Cast(result), script_, expr_pos, |
| 14785 "error evaluating constant expression"); | 14826 "error evaluating constant expression"); |
| 14786 } | 14827 } |
| 14787 ASSERT(result.IsInstance() || result.IsNull()); | 14828 ASSERT(result.IsInstance() || result.IsNull()); |
| 14788 value ^= result.raw(); | 14829 value ^= result.raw(); |
| 14789 value = TryCanonicalize(value, expr_pos); | 14830 value = TryCanonicalize(value, expr_pos); |
| 14790 CacheConstantValue(expr_pos, value); | 14831 CacheConstantValue(expr_pos, value); |
| 14791 return value; | 14832 return value; |
| 14792 } | 14833 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15254 const ArgumentListNode& function_args, | 15295 const ArgumentListNode& function_args, |
| 15255 const LocalVariable* temp_for_last_arg, | 15296 const LocalVariable* temp_for_last_arg, |
| 15256 bool is_super_invocation) { | 15297 bool is_super_invocation) { |
| 15257 UNREACHABLE(); | 15298 UNREACHABLE(); |
| 15258 return NULL; | 15299 return NULL; |
| 15259 } | 15300 } |
| 15260 | 15301 |
| 15261 } // namespace dart | 15302 } // namespace dart |
| 15262 | 15303 |
| 15263 #endif // DART_PRECOMPILED_RUNTIME | 15304 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |