| 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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3402 intptr_t Function::NumImplicitParameters() const { | 3402 intptr_t Function::NumImplicitParameters() const { |
| 3403 if (kind() == RawFunction::kConstructor) { | 3403 if (kind() == RawFunction::kConstructor) { |
| 3404 if (is_static()) { | 3404 if (is_static()) { |
| 3405 ASSERT(IsFactory()); | 3405 ASSERT(IsFactory()); |
| 3406 return 1; // Type arguments. | 3406 return 1; // Type arguments. |
| 3407 } else { | 3407 } else { |
| 3408 ASSERT(IsConstructor()); | 3408 ASSERT(IsConstructor()); |
| 3409 return 2; // Instance, phase. | 3409 return 2; // Instance, phase. |
| 3410 } | 3410 } |
| 3411 } | 3411 } |
| 3412 if (!is_static() && | 3412 if ((kind() == RawFunction::kClosureFunction) || |
| 3413 kind() != RawFunction::kClosureFunction && | 3413 (kind() == RawFunction::kSignatureFunction)) { |
| 3414 kind() != RawFunction::kSignatureFunction) { | 3414 return 1; // Closure object. |
| 3415 } |
| 3416 if (!is_static()) { |
| 3415 // Closure functions defined inside instance (i.e. non-static) functions are | 3417 // Closure functions defined inside instance (i.e. non-static) functions are |
| 3416 // marked as non-static, but they do not have a receiver. | 3418 // marked as non-static, but they do not have a receiver. |
| 3419 // Closures are handled above. |
| 3420 ASSERT((kind() != RawFunction::kClosureFunction) && |
| 3421 (kind() != RawFunction::kSignatureFunction)); |
| 3417 return 1; // Receiver. | 3422 return 1; // Receiver. |
| 3418 } | 3423 } |
| 3419 return 0; // No implicit parameters. | 3424 return 0; // No implicit parameters. |
| 3420 } | 3425 } |
| 3421 | 3426 |
| 3422 | 3427 |
| 3423 bool Function::AreValidArgumentCounts(int num_arguments, | 3428 bool Function::AreValidArgumentCounts(int num_arguments, |
| 3424 int num_named_arguments, | 3429 int num_named_arguments, |
| 3425 String* error_message) const { | 3430 String* error_message) const { |
| 3426 if (num_named_arguments > NumOptionalNamedParameters()) { | 3431 if (num_named_arguments > NumOptionalNamedParameters()) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3859 context_scope ^= ContextScope::New(0); | 3864 context_scope ^= ContextScope::New(0); |
| 3860 } else { | 3865 } else { |
| 3861 context_scope ^= LocalScope::CreateImplicitClosureScope(*this); | 3866 context_scope ^= LocalScope::CreateImplicitClosureScope(*this); |
| 3862 } | 3867 } |
| 3863 closure_function.set_context_scope(context_scope); | 3868 closure_function.set_context_scope(context_scope); |
| 3864 | 3869 |
| 3865 // Set closure function's result type to this result type. | 3870 // Set closure function's result type to this result type. |
| 3866 closure_function.set_result_type(AbstractType::Handle(result_type())); | 3871 closure_function.set_result_type(AbstractType::Handle(result_type())); |
| 3867 | 3872 |
| 3868 // Set closure function's formal parameters to this formal parameters, | 3873 // Set closure function's formal parameters to this formal parameters, |
| 3869 // removing the receiver if this is an instance method. | 3874 // removing the receiver if this is an instance method and adding the closure |
| 3875 // object as first parameter. |
| 3876 const int kClosure = 1; |
| 3870 const int has_receiver = is_static() ? 0 : 1; | 3877 const int has_receiver = is_static() ? 0 : 1; |
| 3871 const int num_fixed_params = num_fixed_parameters() - has_receiver; | 3878 const int num_fixed_params = kClosure - has_receiver + num_fixed_parameters(); |
| 3872 const int num_opt_params = NumOptionalParameters(); | 3879 const int num_opt_params = NumOptionalParameters(); |
| 3873 const bool has_opt_pos_params = HasOptionalPositionalParameters(); | 3880 const bool has_opt_pos_params = HasOptionalPositionalParameters(); |
| 3874 const int num_params = num_fixed_params + num_opt_params; | 3881 const int num_params = num_fixed_params + num_opt_params; |
| 3875 closure_function.set_num_fixed_parameters(num_fixed_params); | 3882 closure_function.set_num_fixed_parameters(num_fixed_params); |
| 3876 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params); | 3883 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params); |
| 3877 closure_function.set_parameter_types(Array::Handle(Array::New(num_params, | 3884 closure_function.set_parameter_types(Array::Handle(Array::New(num_params, |
| 3878 Heap::kOld))); | 3885 Heap::kOld))); |
| 3879 closure_function.set_parameter_names(Array::Handle(Array::New(num_params, | 3886 closure_function.set_parameter_names(Array::Handle(Array::New(num_params, |
| 3880 Heap::kOld))); | 3887 Heap::kOld))); |
| 3881 AbstractType& param_type = AbstractType::Handle(); | 3888 AbstractType& param_type = AbstractType::Handle(); |
| 3882 String& param_name = String::Handle(); | 3889 String& param_name = String::Handle(); |
| 3883 for (int i = 0; i < num_params; i++) { | 3890 // Add implicit closure object parameter. |
| 3884 param_type = ParameterTypeAt(i + has_receiver); | 3891 param_type = Type::DynamicType(); |
| 3892 closure_function.SetParameterTypeAt(0, param_type); |
| 3893 param_name = Symbols::ClosureParameter(); |
| 3894 closure_function.SetParameterNameAt(0, param_name); |
| 3895 for (int i = kClosure; i < num_params; i++) { |
| 3896 param_type = ParameterTypeAt(has_receiver - kClosure + i); |
| 3885 closure_function.SetParameterTypeAt(i, param_type); | 3897 closure_function.SetParameterTypeAt(i, param_type); |
| 3886 param_name = ParameterNameAt(i + has_receiver); | 3898 param_name = ParameterNameAt(has_receiver - kClosure + i); |
| 3887 closure_function.SetParameterNameAt(i, param_name); | 3899 closure_function.SetParameterNameAt(i, param_name); |
| 3888 } | 3900 } |
| 3889 | 3901 |
| 3890 // Lookup or create a new signature class for the closure function in the | 3902 // Lookup or create a new signature class for the closure function in the |
| 3891 // library of the owner class. | 3903 // library of the owner class. |
| 3892 const Class& owner_class = Class::Handle(Owner()); | 3904 const Class& owner_class = Class::Handle(Owner()); |
| 3893 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner())); | 3905 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner())); |
| 3894 const Library& library = Library::Handle(owner_class.library()); | 3906 const Library& library = Library::Handle(owner_class.library()); |
| 3895 ASSERT(!library.IsNull()); | 3907 ASSERT(!library.IsNull()); |
| 3896 const String& signature = String::Handle(closure_function.Signature()); | 3908 const String& signature = String::Handle(closure_function.Signature()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3969 } | 3981 } |
| 3970 } | 3982 } |
| 3971 AbstractType& param_type = AbstractType::Handle(); | 3983 AbstractType& param_type = AbstractType::Handle(); |
| 3972 const intptr_t num_params = NumParameters(); | 3984 const intptr_t num_params = NumParameters(); |
| 3973 const intptr_t num_fixed_params = num_fixed_parameters(); | 3985 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3974 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 3986 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
| 3975 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 3987 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
| 3976 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 3988 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
| 3977 ASSERT((num_fixed_params + num_opt_params) == num_params); | 3989 ASSERT((num_fixed_params + num_opt_params) == num_params); |
| 3978 pieces.Add(kLParen); | 3990 pieces.Add(kLParen); |
| 3979 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3991 intptr_t i = 0; |
| 3992 if (name_visibility == kUserVisibleName) { |
| 3993 // Hide implicit parameters. |
| 3994 i = NumImplicitParameters(); |
| 3995 } |
| 3996 while (i < num_fixed_params) { |
| 3980 param_type = ParameterTypeAt(i); | 3997 param_type = ParameterTypeAt(i); |
| 3981 ASSERT(!param_type.IsNull()); | 3998 ASSERT(!param_type.IsNull()); |
| 3982 if (instantiate && !param_type.IsInstantiated()) { | 3999 if (instantiate && !param_type.IsInstantiated()) { |
| 3983 param_type = param_type.InstantiateFrom(instantiator); | 4000 param_type = param_type.InstantiateFrom(instantiator); |
| 3984 } | 4001 } |
| 3985 name = param_type.BuildName(name_visibility); | 4002 name = param_type.BuildName(name_visibility); |
| 3986 pieces.Add(name); | 4003 pieces.Add(name); |
| 3987 if (i != (num_params - 1)) { | 4004 if (i != (num_params - 1)) { |
| 3988 pieces.Add(kCommaSpace); | 4005 pieces.Add(kCommaSpace); |
| 3989 } | 4006 } |
| 4007 i++; |
| 3990 } | 4008 } |
| 3991 if (num_opt_params > 0) { | 4009 if (num_opt_params > 0) { |
| 3992 if (num_opt_pos_params > 0) { | 4010 if (num_opt_pos_params > 0) { |
| 3993 pieces.Add(kLBracket); | 4011 pieces.Add(kLBracket); |
| 3994 } else { | 4012 } else { |
| 3995 pieces.Add(kLBrace); | 4013 pieces.Add(kLBrace); |
| 3996 } | 4014 } |
| 3997 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 4015 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 3998 // The parameter name of an optional positional parameter does not need | 4016 // The parameter name of an optional positional parameter does not need |
| 3999 // to be part of the signature, since it is not used. | 4017 // to be part of the signature, since it is not used. |
| (...skipping 7933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11933 } | 11951 } |
| 11934 return result.raw(); | 11952 return result.raw(); |
| 11935 } | 11953 } |
| 11936 | 11954 |
| 11937 | 11955 |
| 11938 const char* WeakProperty::ToCString() const { | 11956 const char* WeakProperty::ToCString() const { |
| 11939 return "_WeakProperty"; | 11957 return "_WeakProperty"; |
| 11940 } | 11958 } |
| 11941 | 11959 |
| 11942 } // namespace dart | 11960 } // namespace dart |
| OLD | NEW |