[llvm-commits] [llvm] r66593 - in /llvm/trunk/include/llvm: OperandTraits.h User.h

Gabor Greif ggreif at gmail.com
Tue Mar 10 16:02:14 PDT 2009


Author: ggreif
Date: Tue Mar 10 18:02:13 2009
New Revision: 66593

URL: http://llvm.org/viewvc/llvm-project?rev=66593&view=rev
Log:
Give Op<N>() AppleScript-like semantics, i.e. for negative N it indexes relative to op_end.
This is a preliminary to changes to come. No intended functionality change.

Modified:
    llvm/trunk/include/llvm/OperandTraits.h
    llvm/trunk/include/llvm/User.h

Modified: llvm/trunk/include/llvm/OperandTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/OperandTraits.h?rev=66593&r1=66592&r2=66593&view=diff

==============================================================================
--- llvm/trunk/include/llvm/OperandTraits.h (original)
+++ llvm/trunk/include/llvm/OperandTraits.h Tue Mar 10 18:02:13 2009
@@ -124,8 +124,8 @@
   inline op_iterator op_end(); \
   inline const_op_iterator op_end() const; \
   protected: \
-  template <unsigned> inline Use &Op(); \
-  template <unsigned> inline const Use &Op() const; \
+  template <int> inline Use &Op(); \
+  template <int> inline const Use &Op() const; \
   public: \
   inline unsigned getNumOperands() const
 
@@ -157,12 +157,11 @@
 unsigned CLASS::getNumOperands() const { \
   return OperandTraits<CLASS>::operands(this);  \
 } \
-template <unsigned Idx_nocapture> Use &CLASS::Op() { \
-  return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \
+template <int Idx_nocapture> Use &CLASS::Op() { \
+  return this->OpFrom<Idx_nocapture>(this); \
 } \
-template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \
-  return OperandTraits<CLASS>::op_begin( \
-    const_cast<CLASS*>(this))[Idx_nocapture]; \
+template <int Idx_nocapture> const Use &CLASS::Op() const { \
+  return this->OpFrom<Idx_nocapture>(this); \
 }
 
 
@@ -195,12 +194,11 @@
 unsigned CLASS::getNumOperands() const { \
   return OperandTraits<CLASS>::operands(this); \
 } \
-template <unsigned Idx_nocapture> Use &CLASS::Op() { \
-  return OperandTraits<CLASS>::op_begin(this)[Idx_nocapture]; \
+template <int Idx_nocapture> Use &CLASS::Op() { \
+  return this->OpFrom<Idx_nocapture>(this); \
 } \
-template <unsigned Idx_nocapture> const Use &CLASS::Op() const { \
-  return OperandTraits<CLASS>::op_begin( \
-    const_cast<CLASS*>(this))[Idx_nocapture]; \
+template <int Idx_nocapture> const Use &CLASS::Op() const { \
+  return this->OpFrom<Idx_nocapture>(this); \
 }
 
 

Modified: llvm/trunk/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/User.h?rev=66593&r1=66592&r2=66593&view=diff

==============================================================================
--- llvm/trunk/include/llvm/User.h (original)
+++ llvm/trunk/include/llvm/User.h Tue Mar 10 18:02:13 2009
@@ -83,11 +83,16 @@
     assert(0 && "Constructor throws?");
   }
 protected:
-  template <unsigned Idx> Use &Op() {
-    return OperandTraits<User>::op_begin(this)[Idx];
+  template <int Idx, typename U> static Use &OpFrom(const U *that) {
+    return Idx < 0
+      ? OperandTraits<U>::op_end(const_cast<U*>(that))[Idx]
+      : OperandTraits<U>::op_begin(const_cast<U*>(that))[Idx];
   }
-  template <unsigned Idx> const Use &Op() const {
-    return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx];
+  template <int Idx> Use &Op() {
+    return OpFrom<Idx>(this);
+  }
+  template <int Idx> const Use &Op() const {
+    return OpFrom<Idx>(this);
   }
 public:
   Value *getOperand(unsigned i) const {





More information about the llvm-commits mailing list