| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/become.h" | 10 #include "vm/become.h" |
| (...skipping 5468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5479 while (!parent.IsNull()) { | 5479 while (!parent.IsNull()) { |
| 5480 if (parent.IsGeneric()) { | 5480 if (parent.IsGeneric()) { |
| 5481 return true; | 5481 return true; |
| 5482 } | 5482 } |
| 5483 parent = parent.parent_function(); | 5483 parent = parent.parent_function(); |
| 5484 } | 5484 } |
| 5485 return false; | 5485 return false; |
| 5486 } | 5486 } |
| 5487 | 5487 |
| 5488 RawFunction* Function::implicit_closure_function() const { | 5488 RawFunction* Function::implicit_closure_function() const { |
| 5489 if (IsClosureFunction() || IsSignatureFunction() || IsFactory()) { | 5489 if (IsClosureFunction() || IsConvertedClosureFunction() || |
| 5490 IsSignatureFunction() || IsFactory()) { |
| 5490 return Function::null(); | 5491 return Function::null(); |
| 5491 } | 5492 } |
| 5492 const Object& obj = Object::Handle(raw_ptr()->data_); | 5493 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5493 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); | 5494 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); |
| 5494 if (obj.IsNull() || obj.IsScript()) { | 5495 if (obj.IsNull() || obj.IsScript()) { |
| 5495 return Function::null(); | 5496 return Function::null(); |
| 5496 } | 5497 } |
| 5497 if (obj.IsFunction()) { | 5498 if (obj.IsFunction()) { |
| 5498 return Function::Cast(obj).raw(); | 5499 return Function::Cast(obj).raw(); |
| 5499 } | 5500 } |
| 5500 ASSERT(is_native()); | 5501 ASSERT(is_native()); |
| 5501 ASSERT(obj.IsArray()); | 5502 ASSERT(obj.IsArray()); |
| 5502 const Object& res = Object::Handle(Array::Cast(obj).At(1)); | 5503 const Object& res = Object::Handle(Array::Cast(obj).At(1)); |
| 5503 return res.IsNull() ? Function::null() : Function::Cast(res).raw(); | 5504 return res.IsNull() ? Function::null() : Function::Cast(res).raw(); |
| 5504 } | 5505 } |
| 5505 | 5506 |
| 5506 void Function::set_implicit_closure_function(const Function& value) const { | 5507 void Function::set_implicit_closure_function(const Function& value) const { |
| 5507 ASSERT(!IsClosureFunction() && !IsSignatureFunction()); | 5508 ASSERT(!IsClosureFunction() && !IsSignatureFunction() && |
| 5509 !IsConvertedClosureFunction()); |
| 5508 if (is_native()) { | 5510 if (is_native()) { |
| 5509 const Object& obj = Object::Handle(raw_ptr()->data_); | 5511 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5510 ASSERT(obj.IsArray()); | 5512 ASSERT(obj.IsArray()); |
| 5511 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); | 5513 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); |
| 5512 Array::Cast(obj).SetAt(1, value); | 5514 Array::Cast(obj).SetAt(1, value); |
| 5513 } else { | 5515 } else { |
| 5514 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); | 5516 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); |
| 5515 set_data(value); | 5517 set_data(value); |
| 5516 } | 5518 } |
| 5517 } | 5519 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5618 switch (kind) { | 5620 switch (kind) { |
| 5619 case RawFunction::kRegularFunction: | 5621 case RawFunction::kRegularFunction: |
| 5620 return "RegularFunction"; | 5622 return "RegularFunction"; |
| 5621 break; | 5623 break; |
| 5622 case RawFunction::kClosureFunction: | 5624 case RawFunction::kClosureFunction: |
| 5623 return "ClosureFunction"; | 5625 return "ClosureFunction"; |
| 5624 break; | 5626 break; |
| 5625 case RawFunction::kImplicitClosureFunction: | 5627 case RawFunction::kImplicitClosureFunction: |
| 5626 return "ImplicitClosureFunction"; | 5628 return "ImplicitClosureFunction"; |
| 5627 break; | 5629 break; |
| 5630 case RawFunction::kConvertedClosureFunction: |
| 5631 return "ConvertedClosureFunction"; |
| 5632 break; |
| 5628 case RawFunction::kSignatureFunction: | 5633 case RawFunction::kSignatureFunction: |
| 5629 return "SignatureFunction"; | 5634 return "SignatureFunction"; |
| 5630 break; | 5635 break; |
| 5631 case RawFunction::kGetterFunction: | 5636 case RawFunction::kGetterFunction: |
| 5632 return "GetterFunction"; | 5637 return "GetterFunction"; |
| 5633 break; | 5638 break; |
| 5634 case RawFunction::kSetterFunction: | 5639 case RawFunction::kSetterFunction: |
| 5635 return "SetterFunction"; | 5640 return "SetterFunction"; |
| 5636 break; | 5641 break; |
| 5637 case RawFunction::kConstructor: | 5642 case RawFunction::kConstructor: |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6345 const Object& owner = Object::Handle(zone, RawOwner()); | 6350 const Object& owner = Object::Handle(zone, RawOwner()); |
| 6346 // Note that parent pointers in newly instantiated signatures still points to | 6351 // Note that parent pointers in newly instantiated signatures still points to |
| 6347 // the original uninstantiated parent signatures. That is not a problem. | 6352 // the original uninstantiated parent signatures. That is not a problem. |
| 6348 const Function& parent = Function::Handle(zone, parent_function()); | 6353 const Function& parent = Function::Handle(zone, parent_function()); |
| 6349 ASSERT(!HasInstantiatedSignature()); | 6354 ASSERT(!HasInstantiatedSignature()); |
| 6350 | 6355 |
| 6351 Function& sig = Function::Handle(zone, Function::null()); | 6356 Function& sig = Function::Handle(zone, Function::null()); |
| 6352 if (IsConvertedClosureFunction()) { | 6357 if (IsConvertedClosureFunction()) { |
| 6353 sig = Function::NewConvertedClosureFunction( | 6358 sig = Function::NewConvertedClosureFunction( |
| 6354 String::Handle(zone, name()), parent, TokenPosition::kNoSource); | 6359 String::Handle(zone, name()), parent, TokenPosition::kNoSource); |
| 6355 // TODO(sjindel): Kernel generic methods undone. Handle type parameters | 6360 // TODO(30455): Kernel generic methods undone. Handle type parameters |
| 6356 // correctly when generic closures are supported. Until then, all type | 6361 // correctly when generic closures are supported. Until then, all type |
| 6357 // parameters to this target are used for captured type variables, so they | 6362 // parameters to this target are used for captured type variables, so they |
| 6358 // aren't relevant to the type of the function. | 6363 // aren't relevant to the type of the function. |
| 6359 sig.set_type_parameters(TypeArguments::Handle(zone, TypeArguments::null())); | 6364 sig.set_type_parameters(TypeArguments::Handle(zone, TypeArguments::null())); |
| 6360 } else { | 6365 } else { |
| 6361 sig = Function::NewSignatureFunction(owner, parent, | 6366 sig = Function::NewSignatureFunction(owner, parent, |
| 6362 TokenPosition::kNoSource, space); | 6367 TokenPosition::kNoSource, space); |
| 6363 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); | 6368 sig.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); |
| 6364 } | 6369 } |
| 6365 | 6370 |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6980 // Set closure function's type parameters. | 6985 // Set closure function's type parameters. |
| 6981 closure_function.set_type_parameters( | 6986 closure_function.set_type_parameters( |
| 6982 TypeArguments::Handle(zone, type_parameters())); | 6987 TypeArguments::Handle(zone, type_parameters())); |
| 6983 | 6988 |
| 6984 // Set closure function's result type to this result type. | 6989 // Set closure function's result type to this result type. |
| 6985 closure_function.set_result_type(AbstractType::Handle(zone, result_type())); | 6990 closure_function.set_result_type(AbstractType::Handle(zone, result_type())); |
| 6986 | 6991 |
| 6987 // Set closure function's end token to this end token. | 6992 // Set closure function's end token to this end token. |
| 6988 closure_function.set_end_token_pos(end_token_pos()); | 6993 closure_function.set_end_token_pos(end_token_pos()); |
| 6989 | 6994 |
| 6990 // The closurized method stub just calls into the original method and should | |
| 6991 // therefore be skipped by the debugger and in stack traces. | |
| 6992 closure_function.set_is_debuggable(false); | |
| 6993 closure_function.set_is_visible(false); | |
| 6994 | |
| 6995 // Set closure function's formal parameters to this formal parameters, | 6995 // Set closure function's formal parameters to this formal parameters, |
| 6996 // removing the first parameter over which the currying is done, and adding | 6996 // removing the first parameter over which the currying is done, and adding |
| 6997 // the closure class instance as the first parameter. So, the overall number | 6997 // the closure class instance as the first parameter. So, the overall number |
| 6998 // of fixed parameters doesn't change. | 6998 // of fixed parameters doesn't change. |
| 6999 const int num_fixed_params = num_fixed_parameters(); | 6999 const int num_fixed_params = num_fixed_parameters(); |
| 7000 const int num_opt_params = NumOptionalParameters(); | 7000 const int num_opt_params = NumOptionalParameters(); |
| 7001 const bool has_opt_pos_params = HasOptionalPositionalParameters(); | 7001 const bool has_opt_pos_params = HasOptionalPositionalParameters(); |
| 7002 const int num_params = num_fixed_params + num_opt_params; | 7002 const int num_params = num_fixed_params + num_opt_params; |
| 7003 | 7003 |
| 7004 closure_function.set_num_fixed_parameters(num_fixed_params); | 7004 closure_function.set_num_fixed_parameters(num_fixed_params); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7110 } | 7110 } |
| 7111 if (num_opt_pos_params > 0) { | 7111 if (num_opt_pos_params > 0) { |
| 7112 pieces->Add(Symbols::RBracket()); | 7112 pieces->Add(Symbols::RBracket()); |
| 7113 } else { | 7113 } else { |
| 7114 pieces->Add(Symbols::RBrace()); | 7114 pieces->Add(Symbols::RBrace()); |
| 7115 } | 7115 } |
| 7116 } | 7116 } |
| 7117 } | 7117 } |
| 7118 | 7118 |
| 7119 RawInstance* Function::ImplicitStaticClosure() const { | 7119 RawInstance* Function::ImplicitStaticClosure() const { |
| 7120 ASSERT(IsImplicitStaticClosureFunction()); |
| 7120 if (implicit_static_closure() == Instance::null()) { | 7121 if (implicit_static_closure() == Instance::null()) { |
| 7121 Zone* zone = Thread::Current()->zone(); | 7122 Zone* zone = Thread::Current()->zone(); |
| 7122 const Context& context = Object::empty_context(); | 7123 const Context& context = Object::empty_context(); |
| 7123 TypeArguments& function_type_arguments = TypeArguments::Handle(zone); | 7124 TypeArguments& function_type_arguments = TypeArguments::Handle(zone); |
| 7124 if (!HasInstantiatedSignature(kFunctions)) { | 7125 if (!HasInstantiatedSignature(kFunctions)) { |
| 7125 function_type_arguments = Object::empty_type_arguments().raw(); | 7126 function_type_arguments = Object::empty_type_arguments().raw(); |
| 7126 } | 7127 } |
| 7127 Instance& closure = | 7128 Instance& closure = |
| 7128 Instance::Handle(zone, Closure::New(Object::null_type_arguments(), | 7129 Instance::Handle(zone, Closure::New(Object::null_type_arguments(), |
| 7129 function_type_arguments, *this, | 7130 function_type_arguments, *this, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7292 // NOTE(turnidge): If you update this function, you probably want to | 7293 // NOTE(turnidge): If you update this function, you probably want to |
| 7293 // update Class::PatchFieldsAndFunctions() at the same time. | 7294 // update Class::PatchFieldsAndFunctions() at the same time. |
| 7294 if (token_pos() == TokenPosition::kMinSource) { | 7295 if (token_pos() == TokenPosition::kMinSource) { |
| 7295 // Testing for position 0 is an optimization that relies on temporary | 7296 // Testing for position 0 is an optimization that relies on temporary |
| 7296 // eval functions having token position 0. | 7297 // eval functions having token position 0. |
| 7297 const Script& script = Script::Handle(eval_script()); | 7298 const Script& script = Script::Handle(eval_script()); |
| 7298 if (!script.IsNull()) { | 7299 if (!script.IsNull()) { |
| 7299 return script.raw(); | 7300 return script.raw(); |
| 7300 } | 7301 } |
| 7301 } | 7302 } |
| 7302 if (IsClosureFunction()) { | 7303 if (IsClosureFunction() || IsConvertedClosureFunction()) { |
| 7303 return Function::Handle(parent_function()).script(); | 7304 return Function::Handle(parent_function()).script(); |
| 7304 } | 7305 } |
| 7305 const Object& obj = Object::Handle(raw_ptr()->owner_); | 7306 const Object& obj = Object::Handle(raw_ptr()->owner_); |
| 7306 if (obj.IsNull()) { | 7307 if (obj.IsNull()) { |
| 7307 ASSERT(IsSignatureFunction()); | 7308 ASSERT(IsSignatureFunction()); |
| 7308 return Script::null(); | 7309 return Script::null(); |
| 7309 } | 7310 } |
| 7310 if (obj.IsClass()) { | 7311 if (obj.IsClass()) { |
| 7311 return Class::Cast(obj).script(); | 7312 return Class::Cast(obj).script(); |
| 7312 } | 7313 } |
| (...skipping 15171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22484 } | 22485 } |
| 22485 return UserTag::null(); | 22486 return UserTag::null(); |
| 22486 } | 22487 } |
| 22487 | 22488 |
| 22488 const char* UserTag::ToCString() const { | 22489 const char* UserTag::ToCString() const { |
| 22489 const String& tag_label = String::Handle(label()); | 22490 const String& tag_label = String::Handle(label()); |
| 22490 return tag_label.ToCString(); | 22491 return tag_label.ToCString(); |
| 22491 } | 22492 } |
| 22492 | 22493 |
| 22493 } // namespace dart | 22494 } // namespace dart |
| OLD | NEW |