[llvm-commits] [llvm] r143563 - /llvm/trunk/include/llvm/Object/ObjectFile.h

Michael J. Spencer bigcheesegs at gmail.com
Wed Nov 2 12:33:42 PDT 2011


Author: mspencer
Date: Wed Nov  2 14:33:41 2011
New Revision: 143563

URL: http://llvm.org/viewvc/llvm-project?rev=143563&view=rev
Log:
object: Add operator < for SymbolRef and SectionRef.

Modified:
    llvm/trunk/include/llvm/Object/ObjectFile.h

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=143563&r1=143562&r2=143563&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Wed Nov  2 14:33:41 2011
@@ -78,6 +78,12 @@
   return std::memcmp(&a, &b, sizeof(DataRefImpl)) == 0;
 }
 
+static bool operator <(const DataRefImpl &a, const DataRefImpl &b) {
+  // Check bitwise identical. This is the only legal way to compare a union w/o
+  // knowing which member is in use.
+  return std::memcmp(&a, &b, sizeof(DataRefImpl)) < 0;
+}
+
 class SymbolRef;
 
 /// RelocationRef - This is a value type class that represents a single
@@ -135,6 +141,7 @@
   SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
 
   bool operator==(const SectionRef &Other) const;
+  bool operator <(const SectionRef &Other) const;
 
   error_code getNext(SectionRef &Result) const;
 
@@ -182,6 +189,7 @@
   SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
 
   bool operator==(const SymbolRef &Other) const;
+  bool operator <(const SymbolRef &Other) const;
 
   error_code getNext(SymbolRef &Result) const;
 
@@ -339,6 +347,10 @@
   return SymbolPimpl == Other.SymbolPimpl;
 }
 
+inline bool SymbolRef::operator <(const SymbolRef &Other) const {
+  return SymbolPimpl < Other.SymbolPimpl;
+}
+
 inline error_code SymbolRef::getNext(SymbolRef &Result) const {
   return OwningObject->getSymbolNext(SymbolPimpl, Result);
 }
@@ -402,6 +414,10 @@
   return SectionPimpl == Other.SectionPimpl;
 }
 
+inline bool SectionRef::operator <(const SectionRef &Other) const {
+  return SectionPimpl < Other.SectionPimpl;
+}
+
 inline error_code SectionRef::getNext(SectionRef &Result) const {
   return OwningObject->getSectionNext(SectionPimpl, Result);
 }





More information about the llvm-commits mailing list