diff options
author | Diana Chen <mysekki@gmail.com> | 2014-10-02 14:49:38 +0800 |
---|---|---|
committer | Diana Chen <mysekki@gmail.com> | 2014-10-02 14:49:38 +0800 |
commit | 75c11ff58850a62d272d074cd02c5af7ca544ee0 (patch) | |
tree | 4eb8114b59c9891d5c4696066ecebc02700ed7ee | |
parent | e99db9cf1fa080d9759ced3e90159f71f97a7c10 (diff) | |
download | mclinker-75c11ff58850a62d272d074cd02c5af7ca544ee0.tar.gz |
lint: Fix style for DebugString and MergedStringTable
-rw-r--r-- | include/mcld/LD/DebugString.h | 18 | ||||
-rw-r--r-- | include/mcld/LD/MergedStringTable.h | 23 | ||||
-rw-r--r-- | lib/Core/IRBuilder.cpp | 1 | ||||
-rw-r--r-- | lib/LD/DebugString.cpp | 29 | ||||
-rw-r--r-- | lib/LD/MergedStringTable.cpp | 23 |
5 files changed, 40 insertions, 54 deletions
diff --git a/include/mcld/LD/DebugString.h b/include/mcld/LD/DebugString.h index 831082e7..c63c2e90 100644 --- a/include/mcld/LD/DebugString.h +++ b/include/mcld/LD/DebugString.h @@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_DEBUGSTRING_H -#define MCLD_LD_DEBUGSTRING_H +#ifndef MCLD_LD_DEBUGSTRING_H_ +#define MCLD_LD_DEBUGSTRING_H_ #include <mcld/LD/MergedStringTable.h> @@ -22,12 +22,10 @@ class TargetLDBackend; /** \class DebugString * \brief DebugString represents the output debug section .debug_str */ -class DebugString -{ -public: +class DebugString { + public: DebugString() - : m_pSection(NULL) - {} + : m_pSection(NULL) {} static DebugString* Create(LDSection& pSection); @@ -54,14 +52,14 @@ public: const LDSection* getSection() const { return m_pSection; } LDSection* getSection() { return m_pSection; } -private: + private: /// m_Section - the output LDSection of this .debug_str LDSection* m_pSection; MergedStringTable m_StringTable; }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_LD_DEBUGSTRING_H_ diff --git a/include/mcld/LD/MergedStringTable.h b/include/mcld/LD/MergedStringTable.h index 78b9efad..2d51f079 100644 --- a/include/mcld/LD/MergedStringTable.h +++ b/include/mcld/LD/MergedStringTable.h @@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#ifndef MCLD_LD_MERGEDSTRINGTABLE_H -#define MCLD_LD_MERGEDSTRINGTABLE_H +#ifndef MCLD_LD_MERGEDSTRINGTABLE_H_ +#define MCLD_LD_MERGEDSTRINGTABLE_H_ #include <mcld/Support/MemoryRegion.h> @@ -21,15 +21,13 @@ namespace mcld { * with flag SHF_MERGED and SHF_STRING are mergeable. Every string in * MergedStringTable is unique. */ -class MergedStringTable -{ -public: +class MergedStringTable { + public: typedef llvm::StringMap<size_t> StringMapTy; typedef StringMapTy::MapEntryTy StringMapEntryTy; -public: - MergedStringTable() - {} + public: + MergedStringTable() {} /// getOrCreateString - get or create a string to the string table StringMapEntryTy& getOrCreateString(llvm::StringRef pString); @@ -49,19 +47,18 @@ public: size_t getOutputOffset(llvm::StringRef pStr); -private: + private: typedef StringMapTy::iterator string_map_iterator; typedef StringMapTy::const_iterator const_string_map_iterator; -private: + private: /// m_StringMap - the string pool of this section. It maps the string to the /// output offset. The key of this map is the string, and the value is output /// offset StringMapTy m_StringMap; - }; -} // namespace of mcld +} // namespace mcld -#endif +#endif // MCLD_LD_MERGEDSTRINGTABLE_H_ diff --git a/lib/Core/IRBuilder.cpp b/lib/Core/IRBuilder.cpp index 20ac0350..910d6aa9 100644 --- a/lib/Core/IRBuilder.cpp +++ b/lib/Core/IRBuilder.cpp @@ -6,7 +6,6 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include <mcld/Fragment/FragmentRef.h> #include <mcld/IRBuilder.h> #include <mcld/Fragment/FragmentRef.h> diff --git a/lib/LD/DebugString.cpp b/lib/LD/DebugString.cpp index 37de9fb4..86c66677 100644 --- a/lib/LD/DebugString.cpp +++ b/lib/LD/DebugString.cpp @@ -21,14 +21,13 @@ #include <llvm/Support/Casting.h> #include <llvm/Support/ManagedStatic.h> -using namespace mcld; +namespace mcld { // DebugString represents the output .debug_str section, which is at most on // in each linking static llvm::ManagedStatic<DebugString> g_DebugString; -static inline size_t string_length(const char* pStr) -{ +static inline size_t string_length(const char* pStr) { const char* p = pStr; size_t len = 0; for (; *p != 0; ++p) @@ -38,8 +37,7 @@ static inline size_t string_length(const char* pStr) //========================== // DebugString -void DebugString::merge(LDSection& pSection) -{ +void DebugString::merge(LDSection& pSection) { // get the fragment contents llvm::StringRef strings; SectionData::iterator it, end = pSection.getSectionData()->end(); @@ -60,15 +58,13 @@ void DebugString::merge(LDSection& pSection) } } -size_t DebugString::computeOffsetSize() -{ - size_t size = m_StringTable.finalizeOffset(); - m_pSection->setSize(size); - return size; +size_t DebugString::computeOffsetSize() { + size_t size = m_StringTable.finalizeOffset(); + m_pSection->setSize(size); + return size; } -void DebugString::applyOffset(Relocation& pReloc, TargetLDBackend& pBackend) -{ +void DebugString::applyOffset(Relocation& pReloc, TargetLDBackend& pBackend) { // get the refered string ResolveInfo* info = pReloc.symInfo(); // the symbol should point to the first region fragment in the debug @@ -84,17 +80,16 @@ void DebugString::applyOffset(Relocation& pReloc, TargetLDBackend& pBackend) // apply the relocation pBackend.getRelocator()->applyDebugStringOffset(pReloc, - m_StringTable.getOutputOffset(llvm::StringRef(str, string_length(str)))); + m_StringTable.getOutputOffset(llvm::StringRef(str, string_length(str)))); } -void DebugString::emit(MemoryRegion& pRegion) -{ +void DebugString::emit(MemoryRegion& pRegion) { return m_StringTable.emit(pRegion); } -DebugString* DebugString::Create(LDSection& pSection) -{ +DebugString* DebugString::Create(LDSection& pSection) { g_DebugString->setOutputSection(pSection); return &(*g_DebugString); } +} // namespace mcld diff --git a/lib/LD/MergedStringTable.cpp b/lib/LD/MergedStringTable.cpp index 105fcb26..e53ccc07 100644 --- a/lib/LD/MergedStringTable.cpp +++ b/lib/LD/MergedStringTable.cpp @@ -8,16 +8,14 @@ //===----------------------------------------------------------------------===// #include <mcld/LD/MergedStringTable.h> -using namespace mcld; +namespace mcld { MergedStringTable::StringMapEntryTy& -MergedStringTable::getOrCreateString(llvm::StringRef pString) -{ +MergedStringTable::getOrCreateString(llvm::StringRef pString) { return m_StringMap.GetOrCreateValue(pString); } -uint64_t MergedStringTable::finalizeOffset() -{ +uint64_t MergedStringTable::finalizeOffset() { // trverse the string table and set the offset string_map_iterator it, end = m_StringMap.end(); size_t offset = 0; @@ -28,24 +26,23 @@ uint64_t MergedStringTable::finalizeOffset() return offset; } -void MergedStringTable::emit(MemoryRegion& pRegion) -{ - char* ptr = (char*)pRegion.begin(); +void MergedStringTable::emit(MemoryRegion& pRegion) { + char* ptr = reinterpret_cast<char*>(pRegion.begin()); string_map_iterator it, end = m_StringMap.end(); for (it = m_StringMap.begin(); it != end; ++it) { - strcpy(ptr, it->getKey().data()); + ::memcpy(ptr, it->getKey().data(), it->getKey().size()); ptr += it->getKey().size() + 1; } } -size_t MergedStringTable::getOutputOffset(MergedStringTable::StringMapEntryTy& pEntry) -{ +size_t MergedStringTable::getOutputOffset( + MergedStringTable::StringMapEntryTy& pEntry) { return pEntry.getValue(); } -size_t MergedStringTable::getOutputOffset(llvm::StringRef pStr) -{ +size_t MergedStringTable::getOutputOffset(llvm::StringRef pStr) { assert(m_StringMap.find(pStr) != m_StringMap.end()); return m_StringMap[pStr]; } +} // namespace mcld |