| 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 "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 Function& func = Function::Handle(); | 937 Function& func = Function::Handle(); |
| 938 intptr_t len = value.Length(); | 938 intptr_t len = value.Length(); |
| 939 for (intptr_t i = 0; i < len; i++) { | 939 for (intptr_t i = 0; i < len; i++) { |
| 940 func ^= value.At(i); | 940 func ^= value.At(i); |
| 941 func.set_owner(*this); | 941 func.set_owner(*this); |
| 942 } | 942 } |
| 943 StorePointer(&raw_ptr()->functions_, value.raw()); | 943 StorePointer(&raw_ptr()->functions_, value.raw()); |
| 944 } | 944 } |
| 945 | 945 |
| 946 | 946 |
| 947 void Class::AddClosureFunction(const Function& function) const { |
| 948 GrowableObjectArray& closures = |
| 949 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); |
| 950 if (closures.IsNull()) { |
| 951 closures = GrowableObjectArray::New(4); |
| 952 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); |
| 953 } |
| 954 ASSERT(function.IsNonImplicitClosureFunction()); |
| 955 closures.Add(function); |
| 956 } |
| 957 |
| 958 |
| 959 // Lookup the innermost closure function that contains token at token_index. |
| 960 RawFunction* Class::LookupClosureFunction(intptr_t token_index) const { |
| 961 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) { |
| 962 return Function::null(); |
| 963 } |
| 964 const GrowableObjectArray& closures = |
| 965 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); |
| 966 Function& closure = Function::Handle(); |
| 967 intptr_t num_closures = closures.Length(); |
| 968 intptr_t best_fit_token_index = -1; |
| 969 intptr_t best_fit_index = -1; |
| 970 for (intptr_t i = 0; i < num_closures; i++) { |
| 971 closure ^= closures.At(i); |
| 972 ASSERT(!closure.IsNull()); |
| 973 if ((closure.token_index() <= token_index) && |
| 974 (token_index < closure.end_token_index()) && |
| 975 (best_fit_token_index < closure.token_index())) { |
| 976 best_fit_index = i; |
| 977 best_fit_token_index = closure.token_index(); |
| 978 } |
| 979 } |
| 980 closure = Function::null(); |
| 981 if (best_fit_index >= 0) { |
| 982 closure ^= closures.At(best_fit_index); |
| 983 } |
| 984 return closure.raw(); |
| 985 } |
| 986 |
| 987 |
| 947 void Class::set_signature_function(const Function& value) const { | 988 void Class::set_signature_function(const Function& value) const { |
| 948 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 989 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 949 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 990 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 950 } | 991 } |
| 951 | 992 |
| 952 | 993 |
| 953 void Class::set_class_state(int8_t state) const { | 994 void Class::set_class_state(int8_t state) const { |
| 954 ASSERT(state == RawClass::kAllocated || | 995 ASSERT(state == RawClass::kAllocated || |
| 955 state == RawClass::kPreFinalized || | 996 state == RawClass::kPreFinalized || |
| 956 state == RawClass::kFinalized); | 997 state == RawClass::kFinalized); |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 } | 1723 } |
| 1683 | 1724 |
| 1684 // No function found. | 1725 // No function found. |
| 1685 return Function::null(); | 1726 return Function::null(); |
| 1686 } | 1727 } |
| 1687 | 1728 |
| 1688 | 1729 |
| 1689 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const { | 1730 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const { |
| 1690 // TODO(hausner): we can shortcut the negative case if we knew the | 1731 // TODO(hausner): we can shortcut the negative case if we knew the |
| 1691 // beginning and end token position of the class. | 1732 // beginning and end token position of the class. |
| 1733 Function& func = Function::Handle(); |
| 1734 func = LookupClosureFunction(token_index); |
| 1735 if (!func.IsNull()) { |
| 1736 return func.raw(); |
| 1737 } |
| 1692 Array& funcs = Array::Handle(functions()); | 1738 Array& funcs = Array::Handle(functions()); |
| 1693 Function& func = Function::Handle(); | |
| 1694 intptr_t len = funcs.Length(); | 1739 intptr_t len = funcs.Length(); |
| 1695 for (intptr_t i = 0; i < len; i++) { | 1740 for (intptr_t i = 0; i < len; i++) { |
| 1696 func ^= funcs.At(i); | 1741 func ^= funcs.At(i); |
| 1697 if ((func.token_index() <= token_index) && | 1742 if ((func.token_index() <= token_index) && |
| 1698 (token_index < func.end_token_index())) { | 1743 (token_index < func.end_token_index())) { |
| 1699 return func.raw(); | 1744 return func.raw(); |
| 1700 } | 1745 } |
| 1701 } | 1746 } |
| 1702 | |
| 1703 // No function found. | 1747 // No function found. |
| 1704 return Function::null(); | 1748 return Function::null(); |
| 1705 } | 1749 } |
| 1706 | 1750 |
| 1707 | 1751 |
| 1708 RawField* Class::LookupInstanceField(const String& name) const { | 1752 RawField* Class::LookupInstanceField(const String& name) const { |
| 1709 ASSERT(is_finalized()); | 1753 ASSERT(is_finalized()); |
| 1710 const Field& field = Field::Handle(LookupField(name)); | 1754 const Field& field = Field::Handle(LookupField(name)); |
| 1711 if (!field.IsNull()) { | 1755 if (!field.IsNull()) { |
| 1712 if (field.is_static()) { | 1756 if (field.is_static()) { |
| (...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4420 // Script does not contain the given line number. | 4464 // Script does not contain the given line number. |
| 4421 return Function::null(); | 4465 return Function::null(); |
| 4422 } | 4466 } |
| 4423 | 4467 |
| 4424 return LookupFunctionInScript(script, token_index_at_line); | 4468 return LookupFunctionInScript(script, token_index_at_line); |
| 4425 } | 4469 } |
| 4426 | 4470 |
| 4427 | 4471 |
| 4428 RawFunction* Library::LookupFunctionInScript(const Script& script, | 4472 RawFunction* Library::LookupFunctionInScript(const Script& script, |
| 4429 intptr_t token_index) const { | 4473 intptr_t token_index) const { |
| 4430 Object& entry = Object::Handle(); | |
| 4431 Class& cls = Class::Handle(); | 4474 Class& cls = Class::Handle(); |
| 4432 Function& func = Function::Handle(); | 4475 Function& func = Function::Handle(); |
| 4433 DictionaryIterator it(*this); | 4476 ClassDictionaryIterator it(*this); |
| 4434 while (it.HasNext()) { | 4477 while (it.HasNext()) { |
| 4435 entry = it.GetNext(); | 4478 cls = it.GetNextClass(); |
| 4436 if (entry.IsFunction()) { | 4479 if (script.raw() == cls.script()) { |
| 4437 func ^= entry.raw(); | 4480 func = cls.LookupFunctionAtToken(token_index); |
| 4438 cls = func.owner(); | 4481 if (!func.IsNull()) { |
| 4439 if (script.raw() == cls.script()) { | 4482 return func.raw(); |
| 4440 if ((func.token_index() <= token_index) && | |
| 4441 (token_index < func.end_token_index())) { | |
| 4442 return func.raw(); | |
| 4443 } | |
| 4444 } | |
| 4445 } else if (entry.IsClass()) { | |
| 4446 cls ^= entry.raw(); | |
| 4447 if (script.raw() == cls.script()) { | |
| 4448 func = cls.LookupFunctionAtToken(token_index); | |
| 4449 if (!func.IsNull()) { | |
| 4450 return func.raw(); | |
| 4451 } | |
| 4452 } | 4483 } |
| 4453 } | 4484 } |
| 4454 } | 4485 } |
| 4486 // Look in anonymous classes for toplevel functions. |
| 4487 Array& anon_classes = Array::Handle(this->raw_ptr()->anonymous_classes_); |
| 4488 intptr_t num_anonymous = raw_ptr()->num_anonymous_; |
| 4489 for (int i = 0; i < num_anonymous; i++) { |
| 4490 cls ^= anon_classes.At(i); |
| 4491 ASSERT(!cls.IsNull()); |
| 4492 if (script.raw() == cls.script()) { |
| 4493 func = cls.LookupFunctionAtToken(token_index); |
| 4494 if (!func.IsNull()) { |
| 4495 return func.raw(); |
| 4496 } |
| 4497 } |
| 4498 } |
| 4455 return Function::null(); | 4499 return Function::null(); |
| 4456 } | 4500 } |
| 4457 | 4501 |
| 4458 | 4502 |
| 4459 RawObject* Library::LookupLocalObject(const String& name) const { | 4503 RawObject* Library::LookupLocalObject(const String& name) const { |
| 4460 Isolate* isolate = Isolate::Current(); | 4504 Isolate* isolate = Isolate::Current(); |
| 4461 const Array& dict = Array::Handle(isolate, dictionary()); | 4505 const Array& dict = Array::Handle(isolate, dictionary()); |
| 4462 intptr_t dict_size = dict.Length() - 1; | 4506 intptr_t dict_size = dict.Length() - 1; |
| 4463 intptr_t index = name.Hash() % dict_size; | 4507 intptr_t index = name.Hash() % dict_size; |
| 4464 | 4508 |
| (...skipping 4438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8903 const String& str = String::Handle(pattern()); | 8947 const String& str = String::Handle(pattern()); |
| 8904 const char* format = "JSRegExp: pattern=%s flags=%s"; | 8948 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 8905 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 8949 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 8906 char* chars = reinterpret_cast<char*>( | 8950 char* chars = reinterpret_cast<char*>( |
| 8907 Isolate::Current()->current_zone()->Allocate(len + 1)); | 8951 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 8908 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 8952 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 8909 return chars; | 8953 return chars; |
| 8910 } | 8954 } |
| 8911 | 8955 |
| 8912 } // namespace dart | 8956 } // namespace dart |
| OLD | NEW |