From: Zachary Turner Date: Thu, 6 Oct 2016 21:22:44 +0000 (+0000) Subject: Convert UniqueCStringMap to use StringRef. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4fa098a5c0223dab6ae10da6f01541e943cc0bbf;p=platform%2Fupstream%2Fllvm.git Convert UniqueCStringMap to use StringRef. llvm-svn: 283494 --- diff --git a/lldb/include/lldb/Core/Stream.h b/lldb/include/lldb/Core/Stream.h index 17ba3bf..b3bb19c 100644 --- a/lldb/include/lldb/Core/Stream.h +++ b/lldb/include/lldb/Core/Stream.h @@ -364,7 +364,7 @@ public: /// @param[in] cstr /// The string to be output to the stream. //------------------------------------------------------------------ - size_t PutCString(const char *cstr); + size_t PutCString(llvm::StringRef cstr); //------------------------------------------------------------------ /// Output and End of Line character to the stream. diff --git a/lldb/include/lldb/Core/UniqueCStringMap.h b/lldb/include/lldb/Core/UniqueCStringMap.h index 4cfb2b8..77a350a 100644 --- a/lldb/include/lldb/Core/UniqueCStringMap.h +++ b/lldb/include/lldb/Core/UniqueCStringMap.h @@ -33,15 +33,15 @@ namespace lldb_private { template class UniqueCStringMap { public: struct Entry { - Entry() : cstring(nullptr), value() {} + Entry() {} - Entry(const char *cstr) : cstring(cstr), value() {} + Entry(llvm::StringRef cstr) : cstring(cstr), value() {} - Entry(const char *cstr, const T &v) : cstring(cstr), value(v) {} + Entry(llvm::StringRef cstr, const T &v) : cstring(cstr), value(v) {} bool operator<(const Entry &rhs) const { return cstring < rhs.cstring; } - const char *cstring; + llvm::StringRef cstring; T value; }; @@ -50,7 +50,7 @@ public: // this map, then later call UniqueCStringMap::Sort() before doing // any searches by name. //------------------------------------------------------------------ - void Append(const char *unique_cstr, const T &value) { + void Append(llvm::StringRef unique_cstr, const T &value) { m_map.push_back(typename UniqueCStringMap::Entry(unique_cstr, value)); } @@ -62,7 +62,7 @@ public: // Call this function to always keep the map sorted when putting // entries into the map. //------------------------------------------------------------------ - void Insert(const char *unique_cstr, const T &value) { + void Insert(llvm::StringRef unique_cstr, const T &value) { typename UniqueCStringMap::Entry e(unique_cstr, value); m_map.insert(std::upper_bound(m_map.begin(), m_map.end(), e), e); } @@ -85,7 +85,7 @@ public: return false; } - const char *GetCStringAtIndexUnchecked(uint32_t idx) const { + llvm::StringRef GetCStringAtIndexUnchecked(uint32_t idx) const { return m_map[idx].cstring; } @@ -99,8 +99,8 @@ public: return m_map[idx].value; } - const char *GetCStringAtIndex(uint32_t idx) const { - return ((idx < m_map.size()) ? m_map[idx].cstring : nullptr); + llvm::StringRef GetCStringAtIndex(uint32_t idx) const { + return ((idx < m_map.size()) ? m_map[idx].cstring : llvm::StringRef()); } //------------------------------------------------------------------ @@ -111,7 +111,7 @@ public: // T values and only if there is a sensible failure value that can // be returned and that won't match any existing values. //------------------------------------------------------------------ - T Find(const char *unique_cstr, T fail_value) const { + T Find(llvm::StringRef unique_cstr, T fail_value) const { Entry search_entry(unique_cstr); const_iterator end = m_map.end(); const_iterator pos = std::lower_bound(m_map.begin(), end, search_entry); @@ -129,12 +129,12 @@ public: // The caller is responsible for ensuring that the collection does // not change during while using the returned pointer. //------------------------------------------------------------------ - const Entry *FindFirstValueForName(const char *unique_cstr) const { + const Entry *FindFirstValueForName(llvm::StringRef unique_cstr) const { Entry search_entry(unique_cstr); const_iterator end = m_map.end(); const_iterator pos = std::lower_bound(m_map.begin(), end, search_entry); if (pos != end) { - const char *pos_cstr = pos->cstring; + llvm::StringRef pos_cstr = pos->cstring; if (pos_cstr == unique_cstr) return &(*pos); } @@ -162,7 +162,7 @@ public: return nullptr; } - size_t GetValues(const char *unique_cstr, std::vector &values) const { + size_t GetValues(llvm::StringRef unique_cstr, std::vector &values) const { const size_t start_size = values.size(); Entry search_entry(unique_cstr); @@ -238,7 +238,7 @@ public: } } - size_t Erase(const char *unique_cstr) { + size_t Erase(llvm::StringRef unique_cstr) { size_t num_removed = 0; Entry search_entry(unique_cstr); iterator end = m_map.end(); diff --git a/lldb/source/Core/Stream.cpp b/lldb/source/Core/Stream.cpp index a5eca3f..7614d02 100644 --- a/lldb/source/Core/Stream.cpp +++ b/lldb/source/Core/Stream.cpp @@ -97,12 +97,14 @@ size_t Stream::PutULEB128(uint64_t uval) { //------------------------------------------------------------------ // Print a raw NULL terminated C string to the stream. //------------------------------------------------------------------ -size_t Stream::PutCString(const char *cstr) { - size_t cstr_len = strlen(cstr); +size_t Stream::PutCString(llvm::StringRef str) { + size_t bytes_written = 0; + bytes_written = Write(str.data(), str.size()); + // when in binary mode, emit the NULL terminator if (m_flags.Test(eBinary)) - ++cstr_len; - return Write(cstr, cstr_len); + bytes_written += PutChar('\0'); + return bytes_written; } //------------------------------------------------------------------ diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index 88b7f16..026ac38 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -59,7 +59,7 @@ Error OptionValueEnumeration::SetValueFromString(llvm::StringRef value, ConstString const_enumerator_name(value.trim()); const EnumerationMapEntry *enumerator_entry = m_enumerations.FindFirstValueForName( - const_enumerator_name.GetCString()); + const_enumerator_name.GetStringRef()); if (enumerator_entry) { m_current_value = enumerator_entry->value.value; NotifyValueChanged(); @@ -69,9 +69,10 @@ Error OptionValueEnumeration::SetValueFromString(llvm::StringRef value, const size_t count = m_enumerations.GetSize(); if (count) { error_strm.Printf(", valid values are: %s", - m_enumerations.GetCStringAtIndex(0)); + m_enumerations.GetCStringAtIndex(0).str().c_str()); for (size_t i = 1; i < count; ++i) { - error_strm.Printf(", %s", m_enumerations.GetCStringAtIndex(i)); + error_strm.Printf(", %s", + m_enumerations.GetCStringAtIndex(i).str().c_str()); } } error.SetErrorString(error_strm.GetData()); @@ -98,7 +99,7 @@ void OptionValueEnumeration::SetEnumerations( ConstString const_enumerator_name(enumerators[i].string_value); EnumeratorInfo enumerator_info = {enumerators[i].value, enumerators[i].usage}; - m_enumerations.Append(const_enumerator_name.GetCString(), + m_enumerations.Append(const_enumerator_name.GetStringRef(), enumerator_info); } m_enumerations.Sort(); @@ -119,8 +120,8 @@ size_t OptionValueEnumeration::AutoComplete( if (s && s[0]) { const size_t s_len = strlen(s); for (size_t i = 0; i < num_enumerators; ++i) { - const char *name = m_enumerations.GetCStringAtIndex(i); - if (::strncmp(s, name, s_len) == 0) + llvm::StringRef name = m_enumerations.GetCStringAtIndex(i); + if (name.startswith(s)) matches.AppendString(name); } } else { diff --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp index a6fed48..ab9a9d1 100644 --- a/lldb/source/Interpreter/OptionValueProperties.cpp +++ b/lldb/source/Interpreter/OptionValueProperties.cpp @@ -59,7 +59,7 @@ void OptionValueProperties::Initialize(const PropertyDefinition *defs) { for (size_t i = 0; defs[i].name; ++i) { Property property(defs[i]); assert(property.IsValid()); - m_name_to_index.Append(property.GetName().GetCString(), + m_name_to_index.Append(property.GetName().GetStringRef(), m_properties.size()); property.GetValue()->SetParent(shared_from_this()); m_properties.push_back(property); @@ -79,7 +79,7 @@ void OptionValueProperties::AppendProperty(const ConstString &name, bool is_global, const OptionValueSP &value_sp) { Property property(name, desc, is_global, value_sp); - m_name_to_index.Append(name.GetCString(), m_properties.size()); + m_name_to_index.Append(name.GetStringRef(), m_properties.size()); m_properties.push_back(property); value_sp->SetParent(shared_from_this()); m_name_to_index.Sort(); @@ -109,7 +109,7 @@ OptionValueProperties::GetValueForKey(const ExecutionContext *exe_ctx, const ConstString &key, bool will_modify) const { lldb::OptionValueSP value_sp; - size_t idx = m_name_to_index.Find(key.GetCString(), SIZE_MAX); + size_t idx = m_name_to_index.Find(key.GetStringRef(), SIZE_MAX); if (idx < m_properties.size()) value_sp = GetPropertyAtIndex(exe_ctx, will_modify, idx)->GetValue(); return value_sp; @@ -234,15 +234,16 @@ OptionValueProperties::GetPropertyDescriptionAtIndex(uint32_t idx) const { uint32_t OptionValueProperties::GetPropertyIndex(const ConstString &name) const { - return m_name_to_index.Find(name.GetCString(), SIZE_MAX); + return m_name_to_index.Find(name.GetStringRef(), SIZE_MAX); } const Property * OptionValueProperties::GetProperty(const ExecutionContext *exe_ctx, bool will_modify, const ConstString &name) const { - return GetPropertyAtIndex(exe_ctx, will_modify, - m_name_to_index.Find(name.GetCString(), SIZE_MAX)); + return GetPropertyAtIndex( + exe_ctx, will_modify, + m_name_to_index.Find(name.GetStringRef(), SIZE_MAX)); } const Property *OptionValueProperties::GetPropertyAtIndex( diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 81ca95c..5ada1ae 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -307,28 +307,29 @@ public: CPPRuntimeEquivalents() { m_impl.Append(ConstString("std::basic_string, " "std::allocator >") - .AsCString(), + .GetStringRef(), ConstString("basic_string")); // these two (with a prefixed std::) occur when c++stdlib string class // occurs as a template argument in some STL container m_impl.Append(ConstString("std::basic_string, " "std::allocator >") - .AsCString(), + .GetStringRef(), ConstString("std::basic_string")); m_impl.Sort(); } void Add(ConstString &type_name, ConstString &type_equivalent) { - m_impl.Insert(type_name.AsCString(), type_equivalent); + m_impl.Insert(type_name.GetStringRef(), type_equivalent); } uint32_t FindExactMatches(ConstString &type_name, std::vector &equivalents) { uint32_t count = 0; - for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString()); + for (ImplData match = + m_impl.FindFirstValueForName(type_name.GetStringRef()); match != nullptr; match = m_impl.FindNextValueForName(match)) { equivalents.push_back(match->value); count++; @@ -351,13 +352,13 @@ public: std::vector &equivalents) { uint32_t count = 0; - const char *type_name_cstr = type_name.AsCString(); + llvm::StringRef type_name_cstr = type_name.GetStringRef(); size_t items_count = m_impl.GetSize(); for (size_t item = 0; item < items_count; item++) { - const char *key_cstr = m_impl.GetCStringAtIndex(item); - if (strstr(type_name_cstr, key_cstr)) { + llvm::StringRef key_cstr = m_impl.GetCStringAtIndex(item); + if (type_name_cstr.contains(key_cstr)) { count += AppendReplacements(type_name_cstr, key_cstr, equivalents); } } @@ -377,7 +378,8 @@ private: return target; } - uint32_t AppendReplacements(const char *original, const char *matching_key, + uint32_t AppendReplacements(llvm::StringRef original, + llvm::StringRef matching_key, std::vector &equivalents) { std::string matching_key_str(matching_key); ConstString original_const(original); diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp index 8955baa..1d6522f 100644 --- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp +++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp @@ -83,41 +83,46 @@ void ObjCLanguage::MethodName::Clear() { m_category_is_valid = false; } -bool ObjCLanguage::MethodName::SetName(const char *name, bool strict) { +bool ObjCLanguage::MethodName::SetName(llvm::StringRef name, bool strict) { Clear(); - if (name && name[0]) { - // If "strict" is true. then the method must be specified with a - // '+' or '-' at the beginning. If "strict" is false, then the '+' - // or '-' can be omitted - bool valid_prefix = false; - - if (name[0] == '+' || name[0] == '-') { - valid_prefix = name[1] == '['; - if (name[0] == '+') - m_type = eTypeClassMethod; - else - m_type = eTypeInstanceMethod; - } else if (!strict) { - // "strict" is false, the name just needs to start with '[' - valid_prefix = name[0] == '['; - } + if (name.empty()) + return IsValid(strict); + + // If "strict" is true. then the method must be specified with a + // '+' or '-' at the beginning. If "strict" is false, then the '+' + // or '-' can be omitted + bool valid_prefix = false; + + if (name[0] == '+' || name[0] == '-') { + valid_prefix = name[1] == '['; + if (name[0] == '+') + m_type = eTypeClassMethod; + else + m_type = eTypeInstanceMethod; + } else if (!strict) { + // "strict" is false, the name just needs to start with '[' + valid_prefix = name[0] == '['; + } - if (valid_prefix) { - int name_len = strlen(name); - // Objective C methods must have at least: - // "-[" or "+[" prefix - // One character for a class name - // One character for the space between the class name - // One character for the method name - // "]" suffix - if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']') { - m_full.SetCStringWithLength(name, name_len); - } + if (valid_prefix) { + int name_len = name.size(); + // Objective C methods must have at least: + // "-[" or "+[" prefix + // One character for a class name + // One character for the space between the class name + // One character for the method name + // "]" suffix + if (name_len >= (5 + (strict ? 1 : 0)) && name.back() == ']') { + m_full.SetString(name); } } return IsValid(strict); } +bool ObjCLanguage::MethodName::SetName(const char *name, bool strict) { + return SetName(llvm::StringRef(name), strict); +} + const ConstString &ObjCLanguage::MethodName::GetClassName() { if (!m_class) { if (IsValid(false)) { diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h index c5010b6..b458b58 100644 --- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h +++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h @@ -38,6 +38,11 @@ public: m_type(eTypeUnspecified), m_category_is_valid(false) { SetName(name, strict); } + MethodName(llvm::StringRef name, bool strict) + : m_full(), m_class(), m_category(), m_selector(), + m_type(eTypeUnspecified), m_category_is_valid(false) { + SetName(name, strict); + } void Clear(); @@ -60,6 +65,7 @@ public: ConstString GetFullNameWithoutCategory(bool empty_if_no_category); bool SetName(const char *name, bool strict); + bool SetName(llvm::StringRef name, bool strict); const ConstString &GetClassName(); diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index 50961e9..90213ba 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -155,7 +155,7 @@ size_t ObjectContainerBSDArchive::Archive::ParseObjects() { size_t obj_idx = m_objects.size(); m_objects.push_back(obj); // Insert all of the C strings out of order for now... - m_object_name_to_index_map.Append(obj.ar_name.GetCString(), obj_idx); + m_object_name_to_index_map.Append(obj.ar_name.GetStringRef(), obj_idx); offset += obj.ar_file_size; obj.Clear(); } while (data.ValidOffset(offset)); @@ -171,7 +171,7 @@ ObjectContainerBSDArchive::Archive::FindObject( const ConstString &object_name, const TimeValue &object_mod_time) { const ObjectNameToIndexMap::Entry *match = m_object_name_to_index_map.FindFirstValueForName( - object_name.GetCString()); + object_name.GetStringRef()); if (match) { if (object_mod_time.IsValid()) { const uint64_t object_date = object_mod_time.GetAsSecondsSinceJan1_1970(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 44843c2..77da93a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -3840,10 +3840,10 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( if (src_name) { ConstString src_const_name(src_name); if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) - src_name_to_die_artificial.Append(src_const_name.GetCString(), + src_name_to_die_artificial.Append(src_const_name.GetStringRef(), src_die); else - src_name_to_die.Append(src_const_name.GetCString(), src_die); + src_name_to_die.Append(src_const_name.GetStringRef(), src_die); } } } @@ -3860,10 +3860,10 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( if (dst_name) { ConstString dst_const_name(dst_name); if (dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) - dst_name_to_die_artificial.Append(dst_const_name.GetCString(), + dst_name_to_die_artificial.Append(dst_const_name.GetStringRef(), dst_die); else - dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); + dst_name_to_die.Append(dst_const_name.GetStringRef(), dst_die); } } } @@ -3976,7 +3976,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( src_name_to_die.Sort(); for (idx = 0; idx < dst_size; ++idx) { - const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); + llvm::StringRef dst_name = dst_name_to_die.GetCStringAtIndex(idx); dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); src_die = src_name_to_die.Find(dst_name, DWARFDIE()); @@ -4031,7 +4031,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( dst_name_to_die_artificial.Sort(); for (idx = 0; idx < src_size_artificial; ++idx) { - const char *src_name_artificial = + llvm::StringRef src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked(idx); dst_die = @@ -4075,7 +4075,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes( if (dst_size_artificial) { for (idx = 0; idx < dst_size_artificial; ++idx) { - const char *dst_name_artificial = + llvm::StringRef dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx); if (log) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp index df18526..61ccebd 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -28,11 +28,11 @@ void NameToDIE::Finalize() { } void NameToDIE::Insert(const ConstString &name, const DIERef &die_ref) { - m_map.Append(name.GetCString(), die_ref); + m_map.Append(name.GetStringRef(), die_ref); } size_t NameToDIE::Find(const ConstString &name, DIEArray &info_array) const { - return m_map.GetValues(name.GetCString(), info_array); + return m_map.GetValues(name.GetStringRef(), info_array); } size_t NameToDIE::Find(const RegularExpression ®ex, @@ -55,15 +55,15 @@ size_t NameToDIE::FindAllEntriesForCompileUnit(dw_offset_t cu_offset, void NameToDIE::Dump(Stream *s) { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - const char *cstr = m_map.GetCStringAtIndex(i); + llvm::StringRef cstr = m_map.GetCStringAtIndex(i); const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); - s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr, + s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.data(), die_ref.cu_offset, die_ref.die_offset, cstr); } } void NameToDIE::ForEach( - std::function const + std::function const &callback) const { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h index d9a7f19..e3fe321 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -43,7 +43,7 @@ public: DIEArray &info_array) const; void - ForEach(std::function const + ForEach(std::function const &callback) const; protected: diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index ba7ce0d..61f037d 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -952,72 +952,75 @@ ClangASTContext::GetBasicTypeEnumeration(const ConstString &name) { static std::once_flag g_once_flag; std::call_once(g_once_flag, []() { // "void" - g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); + g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid); // "char" - g_type_map.Append(ConstString("char").GetCString(), eBasicTypeChar); - g_type_map.Append(ConstString("signed char").GetCString(), + g_type_map.Append(ConstString("char").GetStringRef(), eBasicTypeChar); + g_type_map.Append(ConstString("signed char").GetStringRef(), eBasicTypeSignedChar); - g_type_map.Append(ConstString("unsigned char").GetCString(), + g_type_map.Append(ConstString("unsigned char").GetStringRef(), eBasicTypeUnsignedChar); - g_type_map.Append(ConstString("wchar_t").GetCString(), eBasicTypeWChar); - g_type_map.Append(ConstString("signed wchar_t").GetCString(), + g_type_map.Append(ConstString("wchar_t").GetStringRef(), eBasicTypeWChar); + g_type_map.Append(ConstString("signed wchar_t").GetStringRef(), eBasicTypeSignedWChar); - g_type_map.Append(ConstString("unsigned wchar_t").GetCString(), + g_type_map.Append(ConstString("unsigned wchar_t").GetStringRef(), eBasicTypeUnsignedWChar); // "short" - g_type_map.Append(ConstString("short").GetCString(), eBasicTypeShort); - g_type_map.Append(ConstString("short int").GetCString(), eBasicTypeShort); - g_type_map.Append(ConstString("unsigned short").GetCString(), + g_type_map.Append(ConstString("short").GetStringRef(), eBasicTypeShort); + g_type_map.Append(ConstString("short int").GetStringRef(), + eBasicTypeShort); + g_type_map.Append(ConstString("unsigned short").GetStringRef(), eBasicTypeUnsignedShort); - g_type_map.Append(ConstString("unsigned short int").GetCString(), + g_type_map.Append(ConstString("unsigned short int").GetStringRef(), eBasicTypeUnsignedShort); // "int" - g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); - g_type_map.Append(ConstString("signed int").GetCString(), eBasicTypeInt); - g_type_map.Append(ConstString("unsigned int").GetCString(), + g_type_map.Append(ConstString("int").GetStringRef(), eBasicTypeInt); + g_type_map.Append(ConstString("signed int").GetStringRef(), + eBasicTypeInt); + g_type_map.Append(ConstString("unsigned int").GetStringRef(), eBasicTypeUnsignedInt); - g_type_map.Append(ConstString("unsigned").GetCString(), + g_type_map.Append(ConstString("unsigned").GetStringRef(), eBasicTypeUnsignedInt); // "long" - g_type_map.Append(ConstString("long").GetCString(), eBasicTypeLong); - g_type_map.Append(ConstString("long int").GetCString(), eBasicTypeLong); - g_type_map.Append(ConstString("unsigned long").GetCString(), + g_type_map.Append(ConstString("long").GetStringRef(), eBasicTypeLong); + g_type_map.Append(ConstString("long int").GetStringRef(), eBasicTypeLong); + g_type_map.Append(ConstString("unsigned long").GetStringRef(), eBasicTypeUnsignedLong); - g_type_map.Append(ConstString("unsigned long int").GetCString(), + g_type_map.Append(ConstString("unsigned long int").GetStringRef(), eBasicTypeUnsignedLong); // "long long" - g_type_map.Append(ConstString("long long").GetCString(), + g_type_map.Append(ConstString("long long").GetStringRef(), eBasicTypeLongLong); - g_type_map.Append(ConstString("long long int").GetCString(), + g_type_map.Append(ConstString("long long int").GetStringRef(), eBasicTypeLongLong); - g_type_map.Append(ConstString("unsigned long long").GetCString(), + g_type_map.Append(ConstString("unsigned long long").GetStringRef(), eBasicTypeUnsignedLongLong); - g_type_map.Append(ConstString("unsigned long long int").GetCString(), + g_type_map.Append(ConstString("unsigned long long int").GetStringRef(), eBasicTypeUnsignedLongLong); // "int128" - g_type_map.Append(ConstString("__int128_t").GetCString(), + g_type_map.Append(ConstString("__int128_t").GetStringRef(), eBasicTypeInt128); - g_type_map.Append(ConstString("__uint128_t").GetCString(), + g_type_map.Append(ConstString("__uint128_t").GetStringRef(), eBasicTypeUnsignedInt128); // Miscellaneous - g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); - g_type_map.Append(ConstString("float").GetCString(), eBasicTypeFloat); - g_type_map.Append(ConstString("double").GetCString(), eBasicTypeDouble); - g_type_map.Append(ConstString("long double").GetCString(), + g_type_map.Append(ConstString("bool").GetStringRef(), eBasicTypeBool); + g_type_map.Append(ConstString("float").GetStringRef(), eBasicTypeFloat); + g_type_map.Append(ConstString("double").GetStringRef(), eBasicTypeDouble); + g_type_map.Append(ConstString("long double").GetStringRef(), eBasicTypeLongDouble); - g_type_map.Append(ConstString("id").GetCString(), eBasicTypeObjCID); - g_type_map.Append(ConstString("SEL").GetCString(), eBasicTypeObjCSel); - g_type_map.Append(ConstString("nullptr").GetCString(), eBasicTypeNullPtr); + g_type_map.Append(ConstString("id").GetStringRef(), eBasicTypeObjCID); + g_type_map.Append(ConstString("SEL").GetStringRef(), eBasicTypeObjCSel); + g_type_map.Append(ConstString("nullptr").GetStringRef(), + eBasicTypeNullPtr); g_type_map.Sort(); }); - return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); + return g_type_map.Find(name.GetStringRef(), eBasicTypeInvalid); } return eBasicTypeInvalid; } diff --git a/lldb/source/Symbol/GoASTContext.cpp b/lldb/source/Symbol/GoASTContext.cpp index 0c69007..0393691 100644 --- a/lldb/source/Symbol/GoASTContext.cpp +++ b/lldb/source/Symbol/GoASTContext.cpp @@ -596,33 +596,33 @@ GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) { static std::once_flag g_once_flag; std::call_once(g_once_flag, []() { // "void" - g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); + g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid); // "int" - g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); - g_type_map.Append(ConstString("uint").GetCString(), + g_type_map.Append(ConstString("int").GetStringRef(), eBasicTypeInt); + g_type_map.Append(ConstString("uint").GetStringRef(), eBasicTypeUnsignedInt); // Miscellaneous - g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); + g_type_map.Append(ConstString("bool").GetStringRef(), eBasicTypeBool); // Others. Should these map to C types? - g_type_map.Append(ConstString("byte").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("uint8").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("uint16").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("uint32").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("uint64").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("int8").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("int16").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("int32").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("int64").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("float32").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("float64").GetCString(), eBasicTypeOther); - g_type_map.Append(ConstString("uintptr").GetCString(), eBasicTypeOther); + g_type_map.Append(ConstString("byte").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("uint8").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("uint16").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("uint32").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("uint64").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("int8").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("int16").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("int32").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("int64").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("float32").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("float64").GetStringRef(), eBasicTypeOther); + g_type_map.Append(ConstString("uintptr").GetStringRef(), eBasicTypeOther); g_type_map.Sort(); }); - return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); + return g_type_map.Find(name.GetStringRef(), eBasicTypeInvalid); } return eBasicTypeInvalid; } diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index 5b16ba56..09cfd8e 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -262,17 +262,16 @@ void Symtab::InitNameIndexes() { continue; const Mangled &mangled = symbol->GetMangled(); - entry.cstring = mangled.GetMangledName().GetCString(); - if (entry.cstring && entry.cstring[0]) { + entry.cstring = mangled.GetMangledName().GetStringRef(); + if (!entry.cstring.empty()) { m_name_to_index.Append(entry); if (symbol->ContainsLinkerAnnotations()) { // If the symbol has linker annotations, also add the version without - // the - // annotations. + // the annotations. entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations( entry.cstring)) - .GetCString(); + .GetStringRef(); m_name_to_index.Append(entry); } @@ -290,8 +289,9 @@ void Symtab::InitNameIndexes() { { CPlusPlusLanguage::MethodName cxx_method( mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus)); - entry.cstring = ConstString(cxx_method.GetBasename()).GetCString(); - if (entry.cstring && entry.cstring[0]) { + entry.cstring = + ConstString(cxx_method.GetBasename()).GetStringRef(); + if (!entry.cstring.empty()) { // ConstString objects permanently store the string in the pool so // calling // GetCString() on the value gets us a const char * that will @@ -336,17 +336,16 @@ void Symtab::InitNameIndexes() { } entry.cstring = - mangled.GetDemangledName(symbol->GetLanguage()).GetCString(); - if (entry.cstring && entry.cstring[0]) { + mangled.GetDemangledName(symbol->GetLanguage()).GetStringRef(); + if (!entry.cstring.empty()) { m_name_to_index.Append(entry); if (symbol->ContainsLinkerAnnotations()) { // If the symbol has linker annotations, also add the version without - // the - // annotations. + // the annotations. entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations( entry.cstring)) - .GetCString(); + .GetStringRef(); m_name_to_index.Append(entry); } } @@ -356,13 +355,13 @@ void Symtab::InitNameIndexes() { // too. ObjCLanguage::MethodName objc_method(entry.cstring, true); if (objc_method.IsValid(true)) { - entry.cstring = objc_method.GetSelector().GetCString(); + entry.cstring = objc_method.GetSelector().GetStringRef(); m_selector_to_index.Append(entry); ConstString objc_method_no_category( objc_method.GetFullNameWithoutCategory(true)); if (objc_method_no_category) { - entry.cstring = objc_method_no_category.GetCString(); + entry.cstring = objc_method_no_category.GetStringRef(); m_name_to_index.Append(entry); } } @@ -440,14 +439,14 @@ void Symtab::AppendSymbolNamesToMap(const IndexCollection &indexes, const Mangled &mangled = symbol->GetMangled(); if (add_demangled) { entry.cstring = - mangled.GetDemangledName(symbol->GetLanguage()).GetCString(); - if (entry.cstring && entry.cstring[0]) + mangled.GetDemangledName(symbol->GetLanguage()).GetStringRef(); + if (!entry.cstring.empty()) name_to_index_map.Append(entry); } if (add_mangled) { - entry.cstring = mangled.GetMangledName().GetCString(); - if (entry.cstring && entry.cstring[0]) + entry.cstring = mangled.GetMangledName().GetStringRef(); + if (!entry.cstring.empty()) name_to_index_map.Append(entry); } } @@ -617,11 +616,10 @@ uint32_t Symtab::AppendSymbolIndexesWithName(const ConstString &symbol_name, Timer scoped_timer(LLVM_PRETTY_FUNCTION, "%s", LLVM_PRETTY_FUNCTION); if (symbol_name) { - const char *symbol_cstr = symbol_name.GetCString(); if (!m_name_indexes_computed) InitNameIndexes(); - return m_name_to_index.GetValues(symbol_cstr, indexes); + return m_name_to_index.GetValues(symbol_name.GetStringRef(), indexes); } return 0; } @@ -638,11 +636,9 @@ uint32_t Symtab::AppendSymbolIndexesWithName(const ConstString &symbol_name, if (!m_name_indexes_computed) InitNameIndexes(); - const char *symbol_cstr = symbol_name.GetCString(); - std::vector all_name_indexes; const size_t name_match_count = - m_name_to_index.GetValues(symbol_cstr, all_name_indexes); + m_name_to_index.GetValues(symbol_name.GetStringRef(), all_name_indexes); for (size_t i = 0; i < name_match_count; ++i) { if (CheckSymbolAtIndex(all_name_indexes[i], symbol_debug_type, symbol_visibility)) @@ -1066,7 +1062,7 @@ size_t Symtab::FindFunctionSymbols(const ConstString &name, size_t count = 0; std::vector symbol_indexes; - const char *name_cstr = name.GetCString(); + llvm::StringRef name_cstr = name.GetStringRef(); // eFunctionNameTypeAuto should be pre-resolved by a call to // Module::LookupInfo::LookupInfo()