summaryrefslogtreecommitdiff
path: root/include/llvm/User.h
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2009-03-10 23:02:13 +0000
committerGabor Greif <ggreif@gmail.com>2009-03-10 23:02:13 +0000
commit20cb46287cf5deb49cb484c9770e73f7cf246e7b (patch)
treec119fbf99a067fbcd94cb7ea2528dba9870d2f79 /include/llvm/User.h
parent68edf5f68a9e25120f06ab30e064a869eb83018e (diff)
downloadllvm-20cb46287cf5deb49cb484c9770e73f7cf246e7b.tar.gz
llvm-20cb46287cf5deb49cb484c9770e73f7cf246e7b.tar.bz2
llvm-20cb46287cf5deb49cb484c9770e73f7cf246e7b.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/User.h')
-rw-r--r--include/llvm/User.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/llvm/User.h b/include/llvm/User.h
index f2df23e341..1a88ce0cce 100644
--- a/include/llvm/User.h
+++ b/include/llvm/User.h
@@ -83,11 +83,16 @@ public:
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 {