r183760 - [libclang/python] Add a few "cursor kinds" that were missing in the python binding for libclang.

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Jun 11 11:05:43 PDT 2013


Author: akirtzidis
Date: Tue Jun 11 13:05:42 2013
New Revision: 183760

URL: http://llvm.org/viewvc/llvm-project?rev=183760&view=rev
Log:
[libclang/python] Add a few "cursor kinds" that were missing in the python binding for libclang.

Patch by Mathieu Baudet!

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

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=183760&r1=183759&r2=183760&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Tue Jun 11 13:05:42 2013
@@ -508,7 +508,7 @@ class CursorKind(object):
     @staticmethod
     def from_id(id):
         if id >= len(CursorKind._kinds) or CursorKind._kinds[id] is None:
-            raise ValueError,'Unknown cursor kind'
+            raise ValueError,'Unknown cursor kind %d' % id
         return CursorKind._kinds[id]
 
     @staticmethod
@@ -721,10 +721,14 @@ CursorKind.MEMBER_REF = CursorKind(47)
 # A reference to a labeled statement.
 CursorKind.LABEL_REF = CursorKind(48)
 
-# A reference toa a set of overloaded functions or function templates
+# A reference to a set of overloaded functions or function templates
 # that has not yet been resolved to a specific function or function template.
 CursorKind.OVERLOADED_DECL_REF = CursorKind(49)
 
+# A reference to a variable that occurs in some non-expression 
+# context, e.g., a C++ lambda capture list.
+CursorKind.VARIABLE_REF = CursorKind(50)
+
 ###
 # Invalid/Error Kinds
 
@@ -908,6 +912,26 @@ CursorKind.PACK_EXPANSION_EXPR = CursorK
 # pack.
 CursorKind.SIZE_OF_PACK_EXPR = CursorKind(143)
 
+# Represents a C++ lambda expression that produces a local function
+# object.
+# 
+#  \code
+#  void abssort(float *x, unsigned N) {
+#    std::sort(x, x + N,
+#              [](float a, float b) {
+#                return std::abs(a) < std::abs(b);
+#              });
+#  }
+#  \endcode
+CursorKind.LAMBDA_EXPR = CursorKind(144)
+  
+# Objective-c Boolean Literal.
+CursorKind.OBJ_BOOL_LITERAL_EXPR = CursorKind(145)
+
+# Represents the "self" expression in a ObjC method.
+CursorKind.OBJ_SELF_EXPR = CursorKind(146)
+
+
 # A statement whose specific kind is not exposed via this interface.
 #
 # Unexposed statements have the same operations as any other kind of statement;
@@ -999,6 +1023,9 @@ CursorKind.SEH_EXCEPT_STMT = CursorKind(
 # Windows Structured Exception Handling's finally statement.
 CursorKind.SEH_FINALLY_STMT = CursorKind(228)
 
+# A MS inline assembly statement extension.
+CursorKind.MS_ASM_STMT = CursorKind(229)
+
 # The null statement.
 CursorKind.NULL_STMT = CursorKind(230)
 
@@ -1036,6 +1063,12 @@ CursorKind.MACRO_DEFINITION = CursorKind
 CursorKind.MACRO_INSTANTIATION = CursorKind(502)
 CursorKind.INCLUSION_DIRECTIVE = CursorKind(503)
 
+###
+# Extra declaration
+
+# A module import declaration.
+CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
+
 ### Cursors ###
 
 class Cursor(Structure):
@@ -1918,7 +1951,7 @@ class Index(ClangObject):
 
     def read(self, path):
         """Load a TranslationUnit from the given AST file."""
-        return TranslationUnit.from_ast(path, self)
+        return TranslationUnit.from_ast_file(path, self)
 
     def parse(self, path, args=None, unsaved_files=None, options = 0):
         """Load the translation unit from the given source code file by running

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py?rev=183760&r1=183759&r2=183760&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py Tue Jun 11 13:05:42 2013
@@ -4,8 +4,15 @@ def test_name():
     assert CursorKind.UNEXPOSED_DECL.name is 'UNEXPOSED_DECL'
 
 def test_get_all_kinds():
-    assert CursorKind.UNEXPOSED_DECL in CursorKind.get_all_kinds()
-    assert CursorKind.TRANSLATION_UNIT in CursorKind.get_all_kinds()
+    kinds = CursorKind.get_all_kinds()
+    assert CursorKind.UNEXPOSED_DECL in kinds
+    assert CursorKind.TRANSLATION_UNIT in kinds
+    assert CursorKind.VARIABLE_REF in kinds
+    assert CursorKind.LAMBDA_EXPR in kinds
+    assert CursorKind.OBJ_BOOL_LITERAL_EXPR in kinds
+    assert CursorKind.OBJ_SELF_EXPR in kinds
+    assert CursorKind.MS_ASM_STMT in kinds
+    assert CursorKind.MODULE_IMPORT_DECL in kinds
 
 def test_kind_groups():
     """Check that every kind classifies to exactly one group."""





More information about the cfe-commits mailing list