mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
Reduce duplication in MCSymbol Name handling. NFC>
Based on feedback to r239428 by David Blaikie, use const_cast to reduce duplication of the const and non-const versions of getNameEntryPtr. Also have that method return the pointer to the name directly instead of users having to then get the name from the union. Finally, add a FIXME that we should use a static_assert once available in the new operator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239429 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -136,7 +136,7 @@ protected: // MCContext creates and uniques these.
|
||||
Kind(Kind) {
|
||||
Offset = 0;
|
||||
if (Name)
|
||||
getNameEntryPtr().NameEntry = Name;
|
||||
getNameEntryPtr() = Name;
|
||||
}
|
||||
|
||||
// Provide custom new/delete as we will only allocate space for a name
|
||||
@@ -169,15 +169,13 @@ private:
|
||||
}
|
||||
|
||||
/// \brief Get a reference to the name field. Requires that we have a name
|
||||
NameEntryStorageTy &getNameEntryPtr() {
|
||||
const StringMapEntry<bool> *&getNameEntryPtr() {
|
||||
assert(HasName && "Name is required");
|
||||
NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
|
||||
return *(Name - 1);
|
||||
return (*(Name - 1)).NameEntry;
|
||||
}
|
||||
const NameEntryStorageTy &getNameEntryPtr() const {
|
||||
assert(HasName && "Name is required");
|
||||
const auto *Name = reinterpret_cast<const NameEntryStorageTy *>(this);
|
||||
return *(Name - 1);
|
||||
const StringMapEntry<bool> *&getNameEntryPtr() const {
|
||||
return const_cast<MCSymbol*>(this)->getNameEntryPtr();
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -186,7 +184,7 @@ public:
|
||||
if (!HasName)
|
||||
return StringRef();
|
||||
|
||||
return getNameEntryPtr().NameEntry->first();
|
||||
return getNameEntryPtr()->first();
|
||||
}
|
||||
|
||||
bool isRegistered() const { return IsRegistered; }
|
||||
|
||||
Reference in New Issue
Block a user