| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw())); | 304 deferred_prefixes_->Add(&LibraryPrefix::ZoneHandle(Z, prefix.raw())); |
| 305 } | 305 } |
| 306 | 306 |
| 307 | 307 |
| 308 void ParsedFunction::AllocateVariables() { | 308 void ParsedFunction::AllocateVariables() { |
| 309 ASSERT(!function().IsIrregexpFunction()); | 309 ASSERT(!function().IsIrregexpFunction()); |
| 310 LocalScope* scope = node_sequence()->scope(); | 310 LocalScope* scope = node_sequence()->scope(); |
| 311 const intptr_t num_fixed_params = function().num_fixed_parameters(); | 311 const intptr_t num_fixed_params = function().num_fixed_parameters(); |
| 312 const intptr_t num_opt_params = function().NumOptionalParameters(); | 312 const intptr_t num_opt_params = function().NumOptionalParameters(); |
| 313 const intptr_t num_params = num_fixed_params + num_opt_params; | 313 const intptr_t num_params = num_fixed_params + num_opt_params; |
| 314 const intptr_t type_args_slot = function().IsGeneric() ? 1 : 0; |
| 315 |
| 314 // Compute start indices to parameters and locals, and the number of | 316 // Compute start indices to parameters and locals, and the number of |
| 315 // parameters to copy. | 317 // parameters to copy. |
| 316 if (num_opt_params == 0) { | 318 if (num_opt_params == 0) { |
| 317 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and | 319 // Parameter i will be at fp[kParamEndSlotFromFp + num_params - i] and |
| 318 // local variable j will be at fp[kFirstLocalSlotFromFp - j]. | 320 // local variable j will be at fp[kFirstLocalSlotFromFp - j]. |
| 319 first_parameter_index_ = kParamEndSlotFromFp + num_params; | 321 first_parameter_index_ = kParamEndSlotFromFp + num_params; |
| 320 first_stack_local_index_ = kFirstLocalSlotFromFp; | 322 first_stack_local_index_ = kFirstLocalSlotFromFp; |
| 321 num_copied_params_ = 0; | 323 num_copied_params_ = 0; |
| 322 } else { | 324 } else { |
| 323 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable | 325 // Parameter i will be at fp[kFirstLocalSlotFromFp - i] and local variable |
| 324 // j will be at fp[kFirstLocalSlotFromFp - num_params - j]. | 326 // j will be at fp[kFirstLocalSlotFromFp - num_params - j]. |
| 325 first_parameter_index_ = kFirstLocalSlotFromFp; | 327 first_parameter_index_ = kFirstLocalSlotFromFp; |
| 326 first_stack_local_index_ = first_parameter_index_ - num_params; | 328 first_stack_local_index_ = first_parameter_index_ - num_params; |
| 327 num_copied_params_ = num_params; | 329 num_copied_params_ = num_params; |
| 328 } | 330 } |
| 329 | 331 |
| 330 // Allocate parameters and local variables, either in the local frame or | 332 // Allocate parameters and local variables, either in the local frame or |
| 331 // in the context(s). | 333 // in the context(s). |
| 332 bool found_captured_variables = false; | 334 bool found_captured_variables = false; |
| 333 int next_free_frame_index = scope->AllocateVariables( | 335 int next_free_frame_index = scope->AllocateVariables( |
| 334 first_parameter_index_, num_params, first_stack_local_index_, NULL, | 336 first_parameter_index_, num_params, type_args_slot, |
| 335 &found_captured_variables); | 337 first_stack_local_index_, NULL, &found_captured_variables); |
| 336 | 338 |
| 337 // Frame indices are relative to the frame pointer and are decreasing. | 339 // Frame indices are relative to the frame pointer and are decreasing. |
| 338 ASSERT(next_free_frame_index <= first_stack_local_index_); | 340 ASSERT(next_free_frame_index <= first_stack_local_index_); |
| 339 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; | 341 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; |
| 340 } | 342 } |
| 341 | 343 |
| 342 | 344 |
| 343 struct CatchParamDesc { | 345 struct CatchParamDesc { |
| 344 CatchParamDesc() | 346 CatchParamDesc() |
| 345 : token_pos(TokenPosition::kNoSource), | 347 : token_pos(TokenPosition::kNoSource), |
| (...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 load_receiver, NULL); | 1764 load_receiver, NULL); |
| 1763 | 1765 |
| 1764 ReturnNode* return_node = new ReturnNode(ident_pos, closure); | 1766 ReturnNode* return_node = new ReturnNode(ident_pos, closure); |
| 1765 current_block_->statements->Add(return_node); | 1767 current_block_->statements->Add(return_node); |
| 1766 return CloseBlock(); | 1768 return CloseBlock(); |
| 1767 } | 1769 } |
| 1768 | 1770 |
| 1769 | 1771 |
| 1770 void Parser::BuildDispatcherScope(const Function& func, | 1772 void Parser::BuildDispatcherScope(const Function& func, |
| 1771 const ArgumentsDescriptor& desc) { | 1773 const ArgumentsDescriptor& desc) { |
| 1774 if (desc.TypeArgsLen() > 0) { |
| 1775 // TODO(regis): Make func generic. |
| 1776 UNIMPLEMENTED(); |
| 1777 } |
| 1772 ParamList params; | 1778 ParamList params; |
| 1773 // Receiver first. | 1779 // Receiver first. |
| 1774 TokenPosition token_pos = func.token_pos(); | 1780 TokenPosition token_pos = func.token_pos(); |
| 1775 params.AddReceiver(ReceiverType(current_class()), token_pos); | 1781 params.AddReceiver(ReceiverType(current_class()), token_pos); |
| 1776 // Remaining positional parameters. | 1782 // Remaining positional parameters. |
| 1777 intptr_t i = 1; | 1783 intptr_t i = 1; |
| 1778 for (; i < desc.PositionalCount(); ++i) { | 1784 for (; i < desc.PositionalCount(); ++i) { |
| 1779 ParamDesc p; | 1785 ParamDesc p; |
| 1780 char name[64]; | 1786 char name[64]; |
| 1781 OS::SNPrint(name, 64, ":p%" Pd, i); | 1787 OS::SNPrint(name, 64, ":p%" Pd, i); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1866 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func) { | 1872 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func) { |
| 1867 TRACE_PARSER("ParseInvokeFieldDispatcher"); | 1873 TRACE_PARSER("ParseInvokeFieldDispatcher"); |
| 1868 ASSERT(func.IsInvokeFieldDispatcher()); | 1874 ASSERT(func.IsInvokeFieldDispatcher()); |
| 1869 TokenPosition token_pos = func.token_pos(); | 1875 TokenPosition token_pos = func.token_pos(); |
| 1870 ASSERT(func.token_pos() == TokenPosition::kMinSource); | 1876 ASSERT(func.token_pos() == TokenPosition::kMinSource); |
| 1871 ASSERT(current_class().raw() == func.Owner()); | 1877 ASSERT(current_class().raw() == func.Owner()); |
| 1872 | 1878 |
| 1873 const Array& args_desc = Array::Handle(Z, func.saved_args_desc()); | 1879 const Array& args_desc = Array::Handle(Z, func.saved_args_desc()); |
| 1874 ArgumentsDescriptor desc(args_desc); | 1880 ArgumentsDescriptor desc(args_desc); |
| 1875 ASSERT(desc.Count() > 0); | 1881 ASSERT(desc.Count() > 0); |
| 1882 if (desc.TypeArgsLen() > 0) { |
| 1883 ASSERT(func.IsGeneric()); |
| 1884 // TODO(regis): Pass type argument vector. |
| 1885 UNIMPLEMENTED(); |
| 1886 } |
| 1876 | 1887 |
| 1877 // Set up scope for this function. | 1888 // Set up scope for this function. |
| 1878 BuildDispatcherScope(func, desc); | 1889 BuildDispatcherScope(func, desc); |
| 1879 | 1890 |
| 1880 // Receiver is local 0. | 1891 // Receiver is local 0. |
| 1881 LocalScope* scope = current_block_->scope; | 1892 LocalScope* scope = current_block_->scope; |
| 1882 ArgumentListNode* no_args = new ArgumentListNode(token_pos); | 1893 ArgumentListNode* no_args = new ArgumentListNode(token_pos); |
| 1883 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); | 1894 LoadLocalNode* receiver = new LoadLocalNode(token_pos, scope->VariableAt(0)); |
| 1884 | 1895 |
| 1885 const Class& closure_cls = | 1896 const Class& closure_cls = |
| (...skipping 3806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5692 } | 5703 } |
| 5693 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); | 5704 types.Add(&AbstractType::ZoneHandle(Z, type.raw())); |
| 5694 } while (CurrentToken() == Token::kCOMMA); | 5705 } while (CurrentToken() == Token::kCOMMA); |
| 5695 Token::Kind token = CurrentToken(); | 5706 Token::Kind token = CurrentToken(); |
| 5696 if ((token == Token::kGT) || (token == Token::kSHR)) { | 5707 if ((token == Token::kGT) || (token == Token::kSHR)) { |
| 5697 ConsumeRightAngleBracket(); | 5708 ConsumeRightAngleBracket(); |
| 5698 } else { | 5709 } else { |
| 5699 ReportError("right angle bracket expected"); | 5710 ReportError("right angle bracket expected"); |
| 5700 } | 5711 } |
| 5701 if (finalization != ClassFinalizer::kIgnore) { | 5712 if (finalization != ClassFinalizer::kIgnore) { |
| 5702 return NewTypeArguments(types); | 5713 TypeArguments& type_args = TypeArguments::Handle(NewTypeArguments(types)); |
| 5714 if (finalization == ClassFinalizer::kCanonicalize) { |
| 5715 type_args = type_args.Canonicalize(); |
| 5716 } |
| 5717 return type_args.raw(); |
| 5703 } | 5718 } |
| 5704 } | 5719 } |
| 5705 return TypeArguments::null(); | 5720 return TypeArguments::null(); |
| 5706 } | 5721 } |
| 5707 | 5722 |
| 5708 | 5723 |
| 5709 // Parse interface list and add to class cls. | 5724 // Parse interface list and add to class cls. |
| 5710 void Parser::ParseInterfaceList(const Class& cls) { | 5725 void Parser::ParseInterfaceList(const Class& cls) { |
| 5711 TRACE_PARSER("ParseInterfaceList"); | 5726 TRACE_PARSER("ParseInterfaceList"); |
| 5712 ASSERT(CurrentToken() == Token::kIMPLEMENTS); | 5727 ASSERT(CurrentToken() == Token::kIMPLEMENTS); |
| (...skipping 6846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12559 } | 12574 } |
| 12560 *type = type_parameter.raw(); | 12575 *type = type_parameter.raw(); |
| 12561 return; | 12576 return; |
| 12562 } | 12577 } |
| 12563 } | 12578 } |
| 12564 } | 12579 } |
| 12565 // Resolve type arguments, if any. | 12580 // Resolve type arguments, if any. |
| 12566 if (type->arguments() != TypeArguments::null()) { | 12581 if (type->arguments() != TypeArguments::null()) { |
| 12567 const TypeArguments& arguments = | 12582 const TypeArguments& arguments = |
| 12568 TypeArguments::Handle(Z, type->arguments()); | 12583 TypeArguments::Handle(Z, type->arguments()); |
| 12569 const intptr_t num_arguments = arguments.Length(); | 12584 // Already resolved if canonical. |
| 12570 AbstractType& type_argument = AbstractType::Handle(Z); | 12585 if (!arguments.IsCanonical()) { |
| 12571 for (intptr_t i = 0; i < num_arguments; i++) { | 12586 const intptr_t num_arguments = arguments.Length(); |
| 12572 type_argument = arguments.TypeAt(i); | 12587 AbstractType& type_argument = AbstractType::Handle(Z); |
| 12573 ResolveType(&type_argument); | 12588 for (intptr_t i = 0; i < num_arguments; i++) { |
| 12574 arguments.SetTypeAt(i, type_argument); | 12589 type_argument = arguments.TypeAt(i); |
| 12590 ResolveType(&type_argument); |
| 12591 arguments.SetTypeAt(i, type_argument); |
| 12592 } |
| 12575 } | 12593 } |
| 12576 } | 12594 } |
| 12577 if (type->IsFunctionType()) { | 12595 if (type->IsFunctionType()) { |
| 12578 const Function& signature = | 12596 const Function& signature = |
| 12579 Function::Handle(Z, Type::Cast(*type).signature()); | 12597 Function::Handle(Z, Type::Cast(*type).signature()); |
| 12580 Type& signature_type = Type::Handle(Z, signature.SignatureType()); | 12598 Type& signature_type = Type::Handle(Z, signature.SignatureType()); |
| 12581 if (signature_type.raw() != type->raw()) { | 12599 if (signature_type.raw() != type->raw()) { |
| 12582 ResolveType(&signature_type); | 12600 ResolveType(&signature_type); |
| 12583 } else { | 12601 } else { |
| 12584 ResolveSignature(signature); | 12602 ResolveSignature(signature); |
| (...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15314 TokenPosition* start, | 15332 TokenPosition* start, |
| 15315 TokenPosition* end) { | 15333 TokenPosition* end) { |
| 15316 UNREACHABLE(); | 15334 UNREACHABLE(); |
| 15317 return false; | 15335 return false; |
| 15318 } | 15336 } |
| 15319 | 15337 |
| 15320 | 15338 |
| 15321 } // namespace dart | 15339 } // namespace dart |
| 15322 | 15340 |
| 15323 #endif // DART_PRECOMPILED_RUNTIME | 15341 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |