| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2330 | 2330 |
| 2331 bool Function::IsInFactoryScope() const { | 2331 bool Function::IsInFactoryScope() const { |
| 2332 Function& outer_function = Function::Handle(raw()); | 2332 Function& outer_function = Function::Handle(raw()); |
| 2333 while (outer_function.IsLocalFunction()) { | 2333 while (outer_function.IsLocalFunction()) { |
| 2334 outer_function = outer_function.parent_function(); | 2334 outer_function = outer_function.parent_function(); |
| 2335 } | 2335 } |
| 2336 return outer_function.IsFactory(); | 2336 return outer_function.IsFactory(); |
| 2337 } | 2337 } |
| 2338 | 2338 |
| 2339 | 2339 |
| 2340 bool Function::IsInStaticScope() const { | |
| 2341 Function& outer_function = Function::Handle(raw()); | |
| 2342 while (outer_function.IsLocalFunction()) { | |
| 2343 outer_function = outer_function.parent_function(); | |
| 2344 } | |
| 2345 return outer_function.is_static(); | |
| 2346 } | |
| 2347 | |
| 2348 | |
| 2349 void Function::set_name(const String& value) const { | 2340 void Function::set_name(const String& value) const { |
| 2350 ASSERT(value.IsSymbol()); | 2341 ASSERT(value.IsSymbol()); |
| 2351 StorePointer(&raw_ptr()->name_, value.raw()); | 2342 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2352 } | 2343 } |
| 2353 | 2344 |
| 2354 | 2345 |
| 2355 void Function::set_owner(const Class& value) const { | 2346 void Function::set_owner(const Class& value) const { |
| 2356 ASSERT(!value.IsNull()); | 2347 ASSERT(!value.IsNull()); |
| 2357 StorePointer(&raw_ptr()->owner_, value.raw()); | 2348 StorePointer(&raw_ptr()->owner_, value.raw()); |
| 2358 } | 2349 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2710 } | 2701 } |
| 2711 } | 2702 } |
| 2712 if (!found_param_name) { | 2703 if (!found_param_name) { |
| 2713 return false; | 2704 return false; |
| 2714 } | 2705 } |
| 2715 } | 2706 } |
| 2716 return true; | 2707 return true; |
| 2717 } | 2708 } |
| 2718 | 2709 |
| 2719 | 2710 |
| 2711 bool Function::IsImplicitClosureFunction() const { |
| 2712 if (!IsClosureFunction()) { |
| 2713 return false; |
| 2714 } |
| 2715 const Function& parent = Function::Handle(parent_function()); |
| 2716 return parent.raw_ptr()->implicit_closure_function_ == raw(); |
| 2717 } |
| 2718 |
| 2719 |
| 2720 RawFunction* Function::New() { | 2720 RawFunction* Function::New() { |
| 2721 const Class& function_class = Class::Handle(Object::function_class()); | 2721 const Class& function_class = Class::Handle(Object::function_class()); |
| 2722 RawObject* raw = Object::Allocate(function_class, | 2722 RawObject* raw = Object::Allocate(function_class, |
| 2723 Function::InstanceSize(), | 2723 Function::InstanceSize(), |
| 2724 Heap::kOld); | 2724 Heap::kOld); |
| 2725 return reinterpret_cast<RawFunction*>(raw); | 2725 return reinterpret_cast<RawFunction*>(raw); |
| 2726 } | 2726 } |
| 2727 | 2727 |
| 2728 | 2728 |
| 2729 RawFunction* Function::New(const String& name, | 2729 RawFunction* Function::New(const String& name, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2750 | 2750 |
| 2751 RawFunction* Function::NewClosureFunction(const String& name, | 2751 RawFunction* Function::NewClosureFunction(const String& name, |
| 2752 const Function& parent, | 2752 const Function& parent, |
| 2753 intptr_t token_index) { | 2753 intptr_t token_index) { |
| 2754 ASSERT(!parent.IsNull()); | 2754 ASSERT(!parent.IsNull()); |
| 2755 const Class& parent_class = Class::Handle(parent.owner()); | 2755 const Class& parent_class = Class::Handle(parent.owner()); |
| 2756 ASSERT(!parent_class.IsNull()); | 2756 ASSERT(!parent_class.IsNull()); |
| 2757 const Function& result = Function::Handle( | 2757 const Function& result = Function::Handle( |
| 2758 Function::New(name, | 2758 Function::New(name, |
| 2759 RawFunction::kClosureFunction, | 2759 RawFunction::kClosureFunction, |
| 2760 /* is_static = */ true, | 2760 /* is_static = */ parent.is_static(), |
| 2761 /* is_const = */ false, | 2761 /* is_const = */ false, |
| 2762 token_index)); | 2762 token_index)); |
| 2763 result.set_parent_function(parent); | 2763 result.set_parent_function(parent); |
| 2764 result.set_owner(parent_class); | 2764 result.set_owner(parent_class); |
| 2765 return result.raw(); | 2765 return result.raw(); |
| 2766 } | 2766 } |
| 2767 | 2767 |
| 2768 | 2768 |
| 2769 RawFunction* Function::ImplicitClosureFunction() const { | 2769 RawFunction* Function::ImplicitClosureFunction() const { |
| 2770 // Return the existing implicit closure function if any. | 2770 // Return the existing implicit closure function if any. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2823 signature_class = Class::NewSignatureClass(signature, | 2823 signature_class = Class::NewSignatureClass(signature, |
| 2824 closure_function, | 2824 closure_function, |
| 2825 script, | 2825 script, |
| 2826 token_index()); | 2826 token_index()); |
| 2827 library.AddClass(signature_class); | 2827 library.AddClass(signature_class); |
| 2828 } | 2828 } |
| 2829 ASSERT(!Function::Handle(signature_class.signature_function()).IsNull()); | 2829 ASSERT(!Function::Handle(signature_class.signature_function()).IsNull()); |
| 2830 ASSERT(Class::Handle(closure_function.signature_class()).IsNull()); | 2830 ASSERT(Class::Handle(closure_function.signature_class()).IsNull()); |
| 2831 closure_function.set_signature_class(signature_class); | 2831 closure_function.set_signature_class(signature_class); |
| 2832 set_implicit_closure_function(closure_function); | 2832 set_implicit_closure_function(closure_function); |
| 2833 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 2833 return closure_function.raw(); | 2834 return closure_function.raw(); |
| 2834 } | 2835 } |
| 2835 | 2836 |
| 2836 | 2837 |
| 2837 template<typename T> | 2838 template<typename T> |
| 2838 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 2839 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
| 2839 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 2840 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 2840 for (int i = 0; i < objs.length(); i++) { | 2841 for (int i = 0; i < objs.length(); i++) { |
| 2841 a.SetAt(i, *objs[i]); | 2842 a.SetAt(i, *objs[i]); |
| 2842 } | 2843 } |
| (...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6284 const String& str = String::Handle(pattern()); | 6285 const String& str = String::Handle(pattern()); |
| 6285 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6286 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 6286 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6287 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 6287 char* chars = reinterpret_cast<char*>( | 6288 char* chars = reinterpret_cast<char*>( |
| 6288 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6289 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 6289 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6290 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 6290 return chars; | 6291 return chars; |
| 6291 } | 6292 } |
| 6292 | 6293 |
| 6293 } // namespace dart | 6294 } // namespace dart |
| OLD | NEW |