| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 5554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5565 } | 5565 } |
| 5566 | 5566 |
| 5567 | 5567 |
| 5568 RawFunction* Function::implicit_closure_function() const { | 5568 RawFunction* Function::implicit_closure_function() const { |
| 5569 if (IsClosureFunction() || | 5569 if (IsClosureFunction() || |
| 5570 IsSignatureFunction() || | 5570 IsSignatureFunction() || |
| 5571 IsFactory()) { | 5571 IsFactory()) { |
| 5572 return Function::null(); | 5572 return Function::null(); |
| 5573 } | 5573 } |
| 5574 const Object& obj = Object::Handle(raw_ptr()->data_); | 5574 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5575 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction()); | 5575 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); |
| 5576 return (obj.IsNull() || obj.IsScript()) ? Function::null() | 5576 if (obj.IsNull() || obj.IsScript()) { |
| 5577 : Function::Cast(obj).raw(); | 5577 return Function::null(); |
| 5578 } |
| 5579 if (obj.IsFunction()) { |
| 5580 return Function::Cast(obj).raw(); |
| 5581 } |
| 5582 ASSERT(is_native()); |
| 5583 ASSERT(obj.IsArray()); |
| 5584 const Object& res = Object::Handle(Array::Cast(obj).At(1)); |
| 5585 return res.IsNull() ? Function::null() : Function::Cast(res).raw(); |
| 5578 } | 5586 } |
| 5579 | 5587 |
| 5580 | 5588 |
| 5581 void Function::set_implicit_closure_function(const Function& value) const { | 5589 void Function::set_implicit_closure_function(const Function& value) const { |
| 5582 ASSERT(!IsClosureFunction() && !IsSignatureFunction()); | 5590 ASSERT(!IsClosureFunction() && !IsSignatureFunction()); |
| 5583 ASSERT(raw_ptr()->data_ == Object::null()); | 5591 if (is_native()) { |
| 5584 set_data(value); | 5592 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5593 ASSERT(obj.IsArray()); |
| 5594 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); |
| 5595 Array::Cast(obj).SetAt(1, value); |
| 5596 } else { |
| 5597 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); |
| 5598 set_data(value); |
| 5599 } |
| 5585 } | 5600 } |
| 5586 | 5601 |
| 5587 | 5602 |
| 5588 RawClass* Function::signature_class() const { | 5603 RawClass* Function::signature_class() const { |
| 5589 if (IsSignatureFunction()) { | 5604 if (IsSignatureFunction()) { |
| 5590 const Object& obj = Object::Handle(raw_ptr()->data_); | 5605 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5591 ASSERT(obj.IsNull() || obj.IsClass()); | 5606 ASSERT(obj.IsNull() || obj.IsClass()); |
| 5592 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw(); | 5607 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw(); |
| 5593 } | 5608 } |
| 5594 if (IsClosureFunction()) { | 5609 if (IsClosureFunction()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5609 const Object& obj = Object::Handle(raw_ptr()->data_); | 5624 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5610 ASSERT(!obj.IsNull()); | 5625 ASSERT(!obj.IsNull()); |
| 5611 ClosureData::Cast(obj).set_signature_class(value); | 5626 ClosureData::Cast(obj).set_signature_class(value); |
| 5612 return; | 5627 return; |
| 5613 } | 5628 } |
| 5614 UNREACHABLE(); | 5629 UNREACHABLE(); |
| 5615 } | 5630 } |
| 5616 | 5631 |
| 5617 | 5632 |
| 5618 bool Function::IsRedirectingFactory() const { | 5633 bool Function::IsRedirectingFactory() const { |
| 5619 if (!IsFactory() || (raw_ptr()->data_ == Object::null())) { | 5634 if (!IsFactory() || !is_redirecting()) { |
| 5620 return false; | 5635 return false; |
| 5621 } | 5636 } |
| 5622 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. | 5637 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. |
| 5623 return true; | 5638 return true; |
| 5624 } | 5639 } |
| 5625 | 5640 |
| 5626 | 5641 |
| 5627 RawType* Function::RedirectionType() const { | 5642 RawType* Function::RedirectionType() const { |
| 5628 ASSERT(IsRedirectingFactory()); | 5643 ASSERT(IsRedirectingFactory()); |
| 5644 ASSERT(!is_native()); |
| 5629 const Object& obj = Object::Handle(raw_ptr()->data_); | 5645 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5630 ASSERT(!obj.IsNull()); | 5646 ASSERT(!obj.IsNull()); |
| 5631 return RedirectionData::Cast(obj).type(); | 5647 return RedirectionData::Cast(obj).type(); |
| 5632 } | 5648 } |
| 5633 | 5649 |
| 5634 | 5650 |
| 5635 const char* Function::KindToCString(RawFunction::Kind kind) { | 5651 const char* Function::KindToCString(RawFunction::Kind kind) { |
| 5636 switch (kind) { | 5652 switch (kind) { |
| 5637 case RawFunction::kRegularFunction: | 5653 case RawFunction::kRegularFunction: |
| 5638 return "RegularFunction"; | 5654 return "RegularFunction"; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5722 ASSERT(IsFactory()); | 5738 ASSERT(IsFactory()); |
| 5723 Object& obj = Object::Handle(raw_ptr()->data_); | 5739 Object& obj = Object::Handle(raw_ptr()->data_); |
| 5724 if (obj.IsNull()) { | 5740 if (obj.IsNull()) { |
| 5725 obj = RedirectionData::New(); | 5741 obj = RedirectionData::New(); |
| 5726 set_data(obj); | 5742 set_data(obj); |
| 5727 } | 5743 } |
| 5728 RedirectionData::Cast(obj).set_target(target); | 5744 RedirectionData::Cast(obj).set_target(target); |
| 5729 } | 5745 } |
| 5730 | 5746 |
| 5731 | 5747 |
| 5748 // This field is heavily overloaded: |
| 5749 // eval function: Script expression source |
| 5750 // signature function: Class signature class |
| 5751 // method extractor: Function extracted closure function |
| 5752 // noSuchMethod dispatcher: Array arguments descriptor |
| 5753 // invoke-field dispatcher: Array arguments descriptor |
| 5754 // redirecting constructor: RedirectionData |
| 5755 // closure function: ClosureData |
| 5756 // irregexp function: Array[0] = JSRegExp |
| 5757 // Array[1] = Smi string specialization cid |
| 5758 // native function: Array[0] = String native name |
| 5759 // Array[1] = Function implicit closure function |
| 5760 // regular function: Function for implicit closure function |
| 5732 void Function::set_data(const Object& value) const { | 5761 void Function::set_data(const Object& value) const { |
| 5733 StorePointer(&raw_ptr()->data_, value.raw()); | 5762 StorePointer(&raw_ptr()->data_, value.raw()); |
| 5734 } | 5763 } |
| 5735 | 5764 |
| 5736 | 5765 |
| 5737 bool Function::IsInFactoryScope() const { | 5766 bool Function::IsInFactoryScope() const { |
| 5738 if (!IsLocalFunction()) { | 5767 if (!IsLocalFunction()) { |
| 5739 return IsFactory(); | 5768 return IsFactory(); |
| 5740 } | 5769 } |
| 5741 Function& outer_function = Function::Handle(parent_function()); | 5770 Function& outer_function = Function::Handle(parent_function()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5777 ASSERT(kind() == RawFunction::kIrregexpFunction); | 5806 ASSERT(kind() == RawFunction::kIrregexpFunction); |
| 5778 ASSERT(RawObject::IsStringClassId(string_specialization_cid)); | 5807 ASSERT(RawObject::IsStringClassId(string_specialization_cid)); |
| 5779 ASSERT(raw_ptr()->data_ == Object::null()); | 5808 ASSERT(raw_ptr()->data_ == Object::null()); |
| 5780 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); | 5809 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); |
| 5781 pair.SetAt(0, regexp); | 5810 pair.SetAt(0, regexp); |
| 5782 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid))); | 5811 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid))); |
| 5783 set_data(pair); | 5812 set_data(pair); |
| 5784 } | 5813 } |
| 5785 | 5814 |
| 5786 | 5815 |
| 5816 RawString* Function::native_name() const { |
| 5817 ASSERT(is_native()); |
| 5818 const Object& obj = Object::Handle(raw_ptr()->data_); |
| 5819 ASSERT(obj.IsArray()); |
| 5820 return String::RawCast(Array::Cast(obj).At(0)); |
| 5821 } |
| 5822 |
| 5823 |
| 5824 void Function::set_native_name(const String& value) const { |
| 5825 ASSERT(is_native()); |
| 5826 ASSERT(raw_ptr()->data_ == Object::null()); |
| 5827 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); |
| 5828 pair.SetAt(0, value); |
| 5829 // pair[1] will be the implicit closure function if needed. |
| 5830 set_data(pair); |
| 5831 } |
| 5832 |
| 5833 |
| 5787 void Function::set_result_type(const AbstractType& value) const { | 5834 void Function::set_result_type(const AbstractType& value) const { |
| 5788 ASSERT(!value.IsNull()); | 5835 ASSERT(!value.IsNull()); |
| 5789 StorePointer(&raw_ptr()->result_type_, value.raw()); | 5836 StorePointer(&raw_ptr()->result_type_, value.raw()); |
| 5790 } | 5837 } |
| 5791 | 5838 |
| 5792 | 5839 |
| 5793 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { | 5840 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { |
| 5794 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 5841 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
| 5795 return AbstractType::RawCast(parameter_types.At(index)); | 5842 return AbstractType::RawCast(parameter_types.At(index)); |
| 5796 } | 5843 } |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6682 set_implicit_closure_function(closure_function); | 6729 set_implicit_closure_function(closure_function); |
| 6683 ASSERT(closure_function.IsImplicitClosureFunction()); | 6730 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 6684 return closure_function.raw(); | 6731 return closure_function.raw(); |
| 6685 } | 6732 } |
| 6686 | 6733 |
| 6687 | 6734 |
| 6688 void Function::DropUncompiledImplicitClosureFunction() const { | 6735 void Function::DropUncompiledImplicitClosureFunction() const { |
| 6689 if (implicit_closure_function() != Function::null()) { | 6736 if (implicit_closure_function() != Function::null()) { |
| 6690 const Function& func = Function::Handle(implicit_closure_function()); | 6737 const Function& func = Function::Handle(implicit_closure_function()); |
| 6691 if (!func.HasCode()) { | 6738 if (!func.HasCode()) { |
| 6692 set_data(Object::null_object()); | 6739 set_implicit_closure_function(Function::Handle()); |
| 6693 } | 6740 } |
| 6694 } | 6741 } |
| 6695 } | 6742 } |
| 6696 | 6743 |
| 6697 | 6744 |
| 6698 RawString* Function::UserVisibleFormalParameters() const { | 6745 RawString* Function::UserVisibleFormalParameters() const { |
| 6699 // Typically 3, 5,.. elements in 'pieces', e.g.: | 6746 // Typically 3, 5,.. elements in 'pieces', e.g.: |
| 6700 // '_LoadRequest', CommaSpace, '_LoadError'. | 6747 // '_LoadRequest', CommaSpace, '_LoadError'. |
| 6701 GrowableHandlePtrArray<const String> pieces(Thread::Current()->zone(), 5); | 6748 GrowableHandlePtrArray<const String> pieces(Thread::Current()->zone(), 5); |
| 6702 const TypeArguments& instantiator = TypeArguments::Handle(); | 6749 const TypeArguments& instantiator = TypeArguments::Handle(); |
| (...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8703 String& source = String::Handle(raw_ptr()->source_); | 8750 String& source = String::Handle(raw_ptr()->source_); |
| 8704 if (source.IsNull()) { | 8751 if (source.IsNull()) { |
| 8705 return GenerateSource(); | 8752 return GenerateSource(); |
| 8706 } | 8753 } |
| 8707 return raw_ptr()->source_; | 8754 return raw_ptr()->source_; |
| 8708 } | 8755 } |
| 8709 | 8756 |
| 8710 | 8757 |
| 8711 RawString* Script::GenerateSource() const { | 8758 RawString* Script::GenerateSource() const { |
| 8712 const TokenStream& token_stream = TokenStream::Handle(tokens()); | 8759 const TokenStream& token_stream = TokenStream::Handle(tokens()); |
| 8760 if (token_stream.IsNull()) { |
| 8761 ASSERT(Dart::IsRunningPrecompiledCode()); |
| 8762 return String::null(); |
| 8763 } |
| 8713 return token_stream.GenerateSource(); | 8764 return token_stream.GenerateSource(); |
| 8714 } | 8765 } |
| 8715 | 8766 |
| 8716 | 8767 |
| 8717 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { | 8768 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { |
| 8718 Zone* zone = Thread::Current()->zone(); | 8769 Zone* zone = Thread::Current()->zone(); |
| 8719 const GrowableObjectArray& info = | 8770 const GrowableObjectArray& info = |
| 8720 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 8771 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
| 8721 const String& source = String::Handle(zone, Source()); | 8772 const String& source = String::Handle(zone, Source()); |
| 8722 const String& key = Symbols::Empty(); | 8773 const String& key = Symbols::Empty(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8866 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8917 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
| 8867 } | 8918 } |
| 8868 | 8919 |
| 8869 | 8920 |
| 8870 void Script::GetTokenLocation(intptr_t token_pos, | 8921 void Script::GetTokenLocation(intptr_t token_pos, |
| 8871 intptr_t* line, | 8922 intptr_t* line, |
| 8872 intptr_t* column, | 8923 intptr_t* column, |
| 8873 intptr_t* token_len) const { | 8924 intptr_t* token_len) const { |
| 8874 ASSERT(line != NULL); | 8925 ASSERT(line != NULL); |
| 8875 const TokenStream& tkns = TokenStream::Handle(tokens()); | 8926 const TokenStream& tkns = TokenStream::Handle(tokens()); |
| 8927 if (tkns.IsNull()) { |
| 8928 ASSERT(Dart::IsRunningPrecompiledCode()); |
| 8929 *line = -1; |
| 8930 if (column != NULL) { |
| 8931 *column = -1; |
| 8932 } |
| 8933 if (token_len != NULL) { |
| 8934 *token_len = 1; |
| 8935 } |
| 8936 return; |
| 8937 } |
| 8876 if (column == NULL) { | 8938 if (column == NULL) { |
| 8877 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); | 8939 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); |
| 8878 intptr_t cur_line = line_offset() + 1; | 8940 intptr_t cur_line = line_offset() + 1; |
| 8879 while (tkit.CurrentPosition() < token_pos && | 8941 while (tkit.CurrentPosition() < token_pos && |
| 8880 tkit.CurrentTokenKind() != Token::kEOS) { | 8942 tkit.CurrentTokenKind() != Token::kEOS) { |
| 8881 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8943 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
| 8882 cur_line++; | 8944 cur_line++; |
| 8883 } | 8945 } |
| 8884 tkit.Advance(); | 8946 tkit.Advance(); |
| 8885 } | 8947 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9108 jsobj.AddProperty("_kind", GetKindAsCString()); | 9170 jsobj.AddProperty("_kind", GetKindAsCString()); |
| 9109 if (ref) { | 9171 if (ref) { |
| 9110 return; | 9172 return; |
| 9111 } | 9173 } |
| 9112 if (!lib.IsNull()) { | 9174 if (!lib.IsNull()) { |
| 9113 jsobj.AddProperty("library", lib); | 9175 jsobj.AddProperty("library", lib); |
| 9114 } | 9176 } |
| 9115 const String& source = String::Handle(Source()); | 9177 const String& source = String::Handle(Source()); |
| 9116 jsobj.AddProperty("lineOffset", line_offset()); | 9178 jsobj.AddProperty("lineOffset", line_offset()); |
| 9117 jsobj.AddProperty("columnOffset", col_offset()); | 9179 jsobj.AddProperty("columnOffset", col_offset()); |
| 9118 jsobj.AddPropertyStr("source", source); | 9180 if (!source.IsNull()) { |
| 9181 jsobj.AddPropertyStr("source", source); |
| 9182 } |
| 9119 | 9183 |
| 9120 // Print the line number table | 9184 // Print the line number table |
| 9121 { | 9185 if (!source.IsNull()) { |
| 9122 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); | 9186 JSONArray tokenPosTable(&jsobj, "tokenPosTable"); |
| 9123 | 9187 |
| 9124 const GrowableObjectArray& lineNumberArray = | 9188 const GrowableObjectArray& lineNumberArray = |
| 9125 GrowableObjectArray::Handle(GenerateLineNumberArray()); | 9189 GrowableObjectArray::Handle(GenerateLineNumberArray()); |
| 9126 Object& value = Object::Handle(); | 9190 Object& value = Object::Handle(); |
| 9127 intptr_t pos = 0; | 9191 intptr_t pos = 0; |
| 9128 | 9192 |
| 9129 // Skip leading null. | 9193 // Skip leading null. |
| 9130 ASSERT(lineNumberArray.Length() > 0); | 9194 ASSERT(lineNumberArray.Length() > 0); |
| 9131 value = lineNumberArray.At(pos); | 9195 value = lineNumberArray.At(pos); |
| (...skipping 12771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21903 return tag_label.ToCString(); | 21967 return tag_label.ToCString(); |
| 21904 } | 21968 } |
| 21905 | 21969 |
| 21906 | 21970 |
| 21907 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21971 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21908 Instance::PrintJSONImpl(stream, ref); | 21972 Instance::PrintJSONImpl(stream, ref); |
| 21909 } | 21973 } |
| 21910 | 21974 |
| 21911 | 21975 |
| 21912 } // namespace dart | 21976 } // namespace dart |
| OLD | NEW |