Added a new class to the lldb python module:

lldb.value()

It it designed to be given a lldb.SBValue object and it allows natural
use of a variable value:

    pt = lldb.value(lldb.frame.FindVariable("pt"))
    print pt
    print pt.x
    print pt.y

    pt = lldb.frame.FindVariable("rectangle_array")
    print rectangle_array[12]
    print rectangle_array[5].origin.x

Note that array access works just fine and works on arrays or pointers:

pt = lldb.frame.FindVariable("point_ptr")
print point_ptr[5].y

Also note that pointer child accesses are done using a "." instead of "->":

print point_ptr.x




git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@149464 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/scripts/Python/python-extensions.swig b/scripts/Python/python-extensions.swig
index c50e43d..e0ddbeb 100644
--- a/scripts/Python/python-extensions.swig
+++ b/scripts/Python/python-extensions.swig
@@ -182,3 +182,187 @@
         }
 }
 
+%pythoncode %{
+
+class value(object):
+    '''A class designed to wrap lldb.SBValue() objects so the resulting object
+    can be used as a variable would be in code. So if you have a Point structure
+    variable in your code in the current frame named "pt", you can initialize an instance
+    of this class with it:
+    
+    pt = lldb.value(lldb.frame.FindVariable("pt"))
+    print pt
+    print pt.x
+    print pt.y
+
+    pt = lldb.value(lldb.frame.FindVariable("rectangle_array"))
+    print rectangle_array[12]
+    print rectangle_array[5].origin.x'''
+    def __init__(self, sbvalue):
+        self.sbvalue = sbvalue
+
+    def __nonzero__(self):
+        return self.sbvalue.__nonzero__()
+
+    def __repr__(self):
+        return self.sbvalue.__repr__()
+
+    def __str__(self):
+        return self.sbvalue.__str__()
+
+    def __getitem__(self, key):
+        # Allow array access if this value has children...
+        if type(key) is int:
+            return value(self.sbvalue.GetValueForExpressionPath("[%i]" % key))
+        raise TypeError
+
+    def __getattr__(self, name):
+        child_sbvalue = self.sbvalue.GetChildMemberWithName (name)
+        if child_sbvalue:
+            return value(child_sbvalue)
+        raise AttributeError
+
+    def __add__(self, other):
+        return int(self) + int(other)
+        
+    def __sub__(self, other):
+        return int(self) - int(other)
+        
+    def __mul__(self, other):
+        return int(self) * int(other)
+        
+    def __floordiv__(self, other):
+        return int(self) // int(other)
+        
+    def __mod__(self, other):
+        return int(self) % int(other)
+        
+    def __divmod__(self, other):
+        return int(self) % int(other)
+        
+    def __pow__(self, other):
+        return int(self) ** int(other)
+        
+    def __lshift__(self, other):
+        return int(self) << int(other)
+        
+    def __rshift__(self, other):
+        return int(self) >> int(other)
+        
+    def __and__(self, other):
+        return int(self) & int(other)
+        
+    def __xor__(self, other):
+        return int(self) ^ int(other)
+        
+    def __or__(self, other):
+        return int(self) | int(other)
+        
+    def __div__(self, other):
+        return int(self) / int(other)
+        
+    def __truediv__(self, other):
+        return int(self) / int(other)
+        
+    def __iadd__(self, other):
+        result = self.__add__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __isub__(self, other):
+        result = self.__sub__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __imul__(self, other):
+        result = self.__mul__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __idiv__(self, other):
+        result = self.__div__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __itruediv__(self, other):
+        result = self.__truediv__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ifloordiv__(self, other):
+        result =  self.__floordiv__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __imod__(self, other):
+        result =  self.__and__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ipow__(self, other):
+        result = self.__pow__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ipow__(self, other, modulo):
+        result = self.__pow__(self, other, modulo)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ilshift__(self, other):
+        result = self.__lshift__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __irshift__(self, other):
+        result =  self.__rshift__(other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __iand__(self, other):
+        result =  self.__and__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ixor__(self, other):
+        result =  self.__xor__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __ior__(self, other):
+        result =  self.__ior__(self, other)
+        self.sbvalue.SetValueFromCString (str(result))
+        return result
+        
+    def __neg__(self):
+        return -int(self)
+        
+    def __pos__(self):
+        return +int(self)
+        
+    def __abs__(self):
+        return abs(int(self))
+        
+    def __invert__(self):
+        return ~int(self)
+        
+    def __complex__(self):
+        return complex (int(self))
+        
+    def __int__(self):
+        return self.sbvalue.GetValueAsSigned()
+        
+    def __long__(self):
+        return self.sbvalue.GetValueAsSigned()
+        
+    def __float__(self):
+        return float (self.sbvalue.GetValueAsSigned())
+        
+    def __oct__(self):
+        return '0%o' % self.sbvalue.GetValueAsSigned()
+        
+    def __hex__(self):
+        return '0x%x' % self.sbvalue.GetValueAsSigned()
+
+%}
+