[cfe-commits] r124958 - /cfe/trunk/bindings/python/clang/cindex.py

Tobias Grosser grosser at fim.uni-passau.de
Sat Feb 5 09:54:07 PST 2011


Author: grosser
Date: Sat Feb  5 11:54:07 2011
New Revision: 124958

URL: http://llvm.org/viewvc/llvm-project?rev=124958&view=rev
Log:
python bindings: Get the string representation of a CompletionChunk

Modified:
    cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=124958&r1=124957&r2=124958&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Feb  5 11:54:07 2011
@@ -720,13 +720,78 @@
 
 ###
 
+class CodeCompletionChunk:
+    def __init__(self, completionString, key):
+        self.cs = completionString
+        self.key = key
+
+    def __repr__(self):
+        return self.spelling
+
+    @property
+    def spelling(self):
+        return _clang_getCompletionChunkText(self.cs, self.key).spelling
+
+    @property
+    def kind(self):
+        return _clang_getCompletionChunkKind(self.cs, self.key)
+
+    @property
+    def string(self):
+        res = _clang_getCompletionChunkCompletionString(self.cs, self.key)
+
+        if (res):
+          return CompletionString(res)
+        else:
+          None
+
+class CompletionString(ClangObject):
+    def __len__(self):
+        return _clang_getNumCompletionChunks(self.obj)
+
+    def __getitem__(self, key):
+        if len(self) <= key:
+            raise IndexError
+        return CodeCompletionChunk(self.obj, key)
+
+    @property
+    def priority(self):
+        return _clang_getCompletionPriority(self.obj)
+
+    @property
+    def availability(self):
+        return _clang_getCompletionAvailability(self.obj)
+
+    def __repr__(self):
+        return "".join([str(a) for a in self])
+
 class CodeCompletionResult(Structure):
-    _fields_ = [('cursorKind', c_int), ('completionString', c_void_p)]
+    _fields_ = [('cursorKind', c_int), ('completionString', c_object_p)]
+
+    def __repr__(self):
+        return str(CompletionString(self.completionString))
+
+    @property
+    def kind(self):
+        return CursorKind.from_id(self.cursorKind)
+
+    @property
+    def string(self):
+        return CompletionString(self.completionString)
 
 class CCRStructure(Structure):
     _fields_ = [('results', POINTER(CodeCompletionResult)),
                 ('numResults', c_int)]
 
+    def __len__(self):
+        return self.numResults
+
+    def __getitem__(self, key):
+        if len(self) <= key:
+            raise IndexError
+
+        return self.results[key]
+
 class CodeCompletionResults(ClangObject):
     def __init__(self, ptr):
         assert isinstance(ptr, POINTER(CCRStructure)) and ptr
@@ -740,14 +805,7 @@
 
     @property
     def results(self):
-        class ResultsItr:
-            def __init__(self, ccr):
-                self.ccr = ccr
-
-            def __len__(self):
-                return self.ccr.ptr.contents.numResults
-
-        return ResultsItr(self)
+        return self.ptr.contents
 
     @property
     def diagnostics(self):
@@ -1147,6 +1205,23 @@
 _clang_codeCompleteGetDiagnostic.argtypes = [CodeCompletionResults, c_int]
 _clang_codeCompleteGetDiagnostic.restype = Diagnostic
 
+_clang_getCompletionChunkText = lib.clang_getCompletionChunkText
+_clang_getCompletionChunkText.argtypes = [c_void_p, c_int]
+_clang_getCompletionChunkText.restype = _CXString
+
+_clang_getNumCompletionChunks = lib.clang_getNumCompletionChunks
+_clang_getNumCompletionChunks.argtypes = [c_void_p]
+_clang_getNumCompletionChunks.restype = c_int
+
+_clang_getCompletionAvailability = lib.clang_getCompletionAvailability
+_clang_getCompletionAvailability.argtypes = [c_void_p]
+_clang_getCompletionAvailability.restype = c_int
+
+_clang_getCompletionPriority = lib.clang_getCompletionPriority
+_clang_getCompletionPriority.argtypes = [c_void_p]
+_clang_getCompletionPriority.restype = c_int
+
+
 ###
 
 __all__ = ['Index', 'TranslationUnit', 'Cursor', 'CursorKind',





More information about the cfe-commits mailing list