Chromium Code Reviews| 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 5794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5805 } | 5805 } |
| 5806 } | 5806 } |
| 5807 return true; | 5807 return true; |
| 5808 } | 5808 } |
| 5809 | 5809 |
| 5810 | 5810 |
| 5811 // Helper allocating a C string buffer in the zone, printing the fully qualified | 5811 // Helper allocating a C string buffer in the zone, printing the fully qualified |
| 5812 // name of a function in it, and replacing ':' by '_' to make sure the | 5812 // name of a function in it, and replacing ':' by '_' to make sure the |
| 5813 // constructed name is a valid C++ identifier for debugging purpose. | 5813 // constructed name is a valid C++ identifier for debugging purpose. |
| 5814 // Set 'chars' to allocated buffer and return number of written characters. | 5814 // Set 'chars' to allocated buffer and return number of written characters. |
| 5815 static intptr_t ConstructFunctionFullyQualifiedCString(const Function& function, | 5815 |
| 5816 char** chars, | 5816 enum QualifiedFunctionLibKind { |
| 5817 intptr_t reserve_len, | 5817 kQualifiedFunctionLibKindLibUrl, |
| 5818 bool with_lib) { | 5818 kQualifiedFunctionLibKindLibName |
| 5819 }; | |
| 5820 | |
| 5821 | |
| 5822 static intptr_t ConstructFunctionFullyQualifiedCString( | |
| 5823 const Function& function, | |
| 5824 char** chars, | |
| 5825 intptr_t reserve_len, | |
| 5826 bool with_lib, | |
| 5827 QualifiedFunctionLibKind lib_kind = kQualifiedFunctionLibKindLibUrl) { | |
|
siva
2014/08/20 20:40:09
instead of a default value for the param why not j
Cutch
2014/08/20 20:43:40
Done.
| |
| 5819 const char* name = String::Handle(function.name()).ToCString(); | 5828 const char* name = String::Handle(function.name()).ToCString(); |
| 5820 const char* function_format = (reserve_len == 0) ? "%s" : "%s_"; | 5829 const char* function_format = (reserve_len == 0) ? "%s" : "%s_"; |
| 5821 reserve_len += OS::SNPrint(NULL, 0, function_format, name); | 5830 reserve_len += OS::SNPrint(NULL, 0, function_format, name); |
| 5822 const Function& parent = Function::Handle(function.parent_function()); | 5831 const Function& parent = Function::Handle(function.parent_function()); |
| 5823 intptr_t written = 0; | 5832 intptr_t written = 0; |
| 5824 if (parent.IsNull()) { | 5833 if (parent.IsNull()) { |
| 5825 const Class& function_class = Class::Handle(function.Owner()); | 5834 const Class& function_class = Class::Handle(function.Owner()); |
| 5826 ASSERT(!function_class.IsNull()); | 5835 ASSERT(!function_class.IsNull()); |
| 5827 const char* class_name = String::Handle(function_class.Name()).ToCString(); | 5836 const char* class_name = String::Handle(function_class.Name()).ToCString(); |
| 5828 ASSERT(class_name != NULL); | 5837 ASSERT(class_name != NULL); |
| 5829 const Library& library = Library::Handle(function_class.library()); | 5838 const Library& library = Library::Handle(function_class.library()); |
| 5830 ASSERT(!library.IsNull()); | 5839 ASSERT(!library.IsNull()); |
| 5831 const char* library_name = NULL; | 5840 const char* library_name = NULL; |
| 5832 const char* lib_class_format = NULL; | 5841 const char* lib_class_format = NULL; |
| 5833 if (with_lib) { | 5842 if (with_lib) { |
| 5834 library_name = String::Handle(library.url()).ToCString(); | 5843 switch (lib_kind) { |
| 5844 case kQualifiedFunctionLibKindLibUrl: | |
| 5845 library_name = String::Handle(library.url()).ToCString(); | |
| 5846 break; | |
| 5847 case kQualifiedFunctionLibKindLibName: | |
| 5848 library_name = String::Handle(library.name()).ToCString(); | |
| 5849 break; | |
| 5850 default: | |
| 5851 UNIMPLEMENTED(); | |
|
siva
2014/08/20 20:40:09
UNREACHABLE() instead of unimplemented?
Cutch
2014/08/20 20:43:41
Done.
| |
| 5852 } | |
| 5835 ASSERT(library_name != NULL); | 5853 ASSERT(library_name != NULL); |
| 5836 lib_class_format = (library_name[0] == '\0') ? "%s%s_" : "%s_%s_"; | 5854 lib_class_format = (library_name[0] == '\0') ? "%s%s_" : "%s_%s_"; |
| 5837 } else { | 5855 } else { |
| 5838 library_name = ""; | 5856 library_name = ""; |
| 5839 lib_class_format = "%s%s."; | 5857 lib_class_format = "%s%s."; |
| 5840 } | 5858 } |
| 5841 reserve_len += | 5859 reserve_len += |
| 5842 OS::SNPrint(NULL, 0, lib_class_format, library_name, class_name); | 5860 OS::SNPrint(NULL, 0, lib_class_format, library_name, class_name); |
| 5843 ASSERT(chars != NULL); | 5861 ASSERT(chars != NULL); |
| 5844 *chars = Isolate::Current()->current_zone()->Alloc<char>(reserve_len + 1); | 5862 *chars = Isolate::Current()->current_zone()->Alloc<char>(reserve_len + 1); |
| 5845 written = OS::SNPrint( | 5863 written = OS::SNPrint( |
| 5846 *chars, reserve_len + 1, lib_class_format, library_name, class_name); | 5864 *chars, reserve_len + 1, lib_class_format, library_name, class_name); |
| 5847 } else { | 5865 } else { |
| 5848 written = ConstructFunctionFullyQualifiedCString(parent, | 5866 written = ConstructFunctionFullyQualifiedCString(parent, |
| 5849 chars, | 5867 chars, |
| 5850 reserve_len, | 5868 reserve_len, |
| 5851 with_lib); | 5869 with_lib, |
| 5870 lib_kind); | |
| 5852 } | 5871 } |
| 5853 ASSERT(*chars != NULL); | 5872 ASSERT(*chars != NULL); |
| 5854 char* next = *chars + written; | 5873 char* next = *chars + written; |
| 5855 written += OS::SNPrint(next, reserve_len + 1, function_format, name); | 5874 written += OS::SNPrint(next, reserve_len + 1, function_format, name); |
| 5856 // Replace ":" with "_". | 5875 // Replace ":" with "_". |
| 5857 while (true) { | 5876 while (true) { |
| 5858 next = strchr(next, ':'); | 5877 next = strchr(next, ':'); |
| 5859 if (next == NULL) break; | 5878 if (next == NULL) break; |
| 5860 *next = '_'; | 5879 *next = '_'; |
| 5861 } | 5880 } |
| 5862 return written; | 5881 return written; |
| 5863 } | 5882 } |
| 5864 | 5883 |
| 5865 | 5884 |
| 5866 const char* Function::ToFullyQualifiedCString() const { | 5885 const char* Function::ToFullyQualifiedCString() const { |
| 5867 char* chars = NULL; | 5886 char* chars = NULL; |
| 5868 ConstructFunctionFullyQualifiedCString(*this, &chars, 0, true); | 5887 ConstructFunctionFullyQualifiedCString(*this, &chars, 0, true); |
| 5869 return chars; | 5888 return chars; |
| 5870 } | 5889 } |
| 5871 | 5890 |
| 5872 | 5891 |
| 5892 const char* Function::ToLibNamePrefixedQualifiedCString() const { | |
| 5893 char* chars = NULL; | |
| 5894 ConstructFunctionFullyQualifiedCString(*this, &chars, 0, true, | |
| 5895 kQualifiedFunctionLibKindLibName); | |
| 5896 return chars; | |
| 5897 } | |
| 5898 | |
| 5899 | |
| 5873 const char* Function::ToQualifiedCString() const { | 5900 const char* Function::ToQualifiedCString() const { |
| 5874 char* chars = NULL; | 5901 char* chars = NULL; |
| 5875 ConstructFunctionFullyQualifiedCString(*this, &chars, 0, false); | 5902 ConstructFunctionFullyQualifiedCString(*this, &chars, 0, false); |
| 5876 return chars; | 5903 return chars; |
| 5877 } | 5904 } |
| 5878 | 5905 |
| 5879 | 5906 |
| 5880 bool Function::HasCompatibleParametersWith(const Function& other, | 5907 bool Function::HasCompatibleParametersWith(const Function& other, |
| 5881 Error* bound_error) const { | 5908 Error* bound_error) const { |
| 5882 ASSERT(FLAG_error_on_bad_override); | 5909 ASSERT(FLAG_error_on_bad_override); |
| (...skipping 6119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12002 } | 12029 } |
| 12003 } | 12030 } |
| 12004 code.set_comments(assembler->GetCodeComments()); | 12031 code.set_comments(assembler->GetCodeComments()); |
| 12005 return code.raw(); | 12032 return code.raw(); |
| 12006 } | 12033 } |
| 12007 | 12034 |
| 12008 | 12035 |
| 12009 RawCode* Code::FinalizeCode(const Function& function, | 12036 RawCode* Code::FinalizeCode(const Function& function, |
| 12010 Assembler* assembler, | 12037 Assembler* assembler, |
| 12011 bool optimized) { | 12038 bool optimized) { |
| 12012 // Calling ToFullyQualifiedCString is very expensive, try to avoid it. | 12039 // Calling ToLibNamePrefixedQualifiedCString is very expensive, |
| 12040 // try to avoid it. | |
| 12013 if (CodeObservers::AreActive()) { | 12041 if (CodeObservers::AreActive()) { |
| 12014 return FinalizeCode(function.ToFullyQualifiedCString(), | 12042 return FinalizeCode(function.ToLibNamePrefixedQualifiedCString(), |
| 12015 assembler, | 12043 assembler, |
| 12016 optimized); | 12044 optimized); |
| 12017 } else { | 12045 } else { |
| 12018 return FinalizeCode("", assembler); | 12046 return FinalizeCode("", assembler); |
| 12019 } | 12047 } |
| 12020 } | 12048 } |
| 12021 | 12049 |
| 12022 | 12050 |
| 12023 // Check if object matches find condition. | 12051 // Check if object matches find condition. |
| 12024 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) const { | 12052 bool Code::FindRawCodeVisitor::FindObject(RawObject* obj) const { |
| (...skipping 7448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19473 return tag_label.ToCString(); | 19501 return tag_label.ToCString(); |
| 19474 } | 19502 } |
| 19475 | 19503 |
| 19476 | 19504 |
| 19477 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19505 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 19478 Instance::PrintJSONImpl(stream, ref); | 19506 Instance::PrintJSONImpl(stream, ref); |
| 19479 } | 19507 } |
| 19480 | 19508 |
| 19481 | 19509 |
| 19482 } // namespace dart | 19510 } // namespace dart |
| OLD | NEW |