Skip to content

Commit 016fa1b

Browse files
committed
[libclang/python] Add a few "cursor kinds" that were missing in the python binding for libclang.
Patch by Mathieu Baudet! llvm-svn: 183760
1 parent 46ed353 commit 016fa1b

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def name(self):
508508
@staticmethod
509509
def from_id(id):
510510
if id >= len(CursorKind._kinds) or CursorKind._kinds[id] is None:
511-
raise ValueError,'Unknown cursor kind'
511+
raise ValueError,'Unknown cursor kind %d' % id
512512
return CursorKind._kinds[id]
513513

514514
@staticmethod
@@ -721,10 +721,14 @@ def __repr__(self):
721721
# A reference to a labeled statement.
722722
CursorKind.LABEL_REF = CursorKind(48)
723723

724-
# A reference toa a set of overloaded functions or function templates
724+
# A reference to a set of overloaded functions or function templates
725725
# that has not yet been resolved to a specific function or function template.
726726
CursorKind.OVERLOADED_DECL_REF = CursorKind(49)
727727

728+
# A reference to a variable that occurs in some non-expression
729+
# context, e.g., a C++ lambda capture list.
730+
CursorKind.VARIABLE_REF = CursorKind(50)
731+
728732
###
729733
# Invalid/Error Kinds
730734

@@ -908,6 +912,26 @@ def __repr__(self):
908912
# pack.
909913
CursorKind.SIZE_OF_PACK_EXPR = CursorKind(143)
910914

915+
# Represents a C++ lambda expression that produces a local function
916+
# object.
917+
#
918+
# \code
919+
# void abssort(float *x, unsigned N) {
920+
# std::sort(x, x + N,
921+
# [](float a, float b) {
922+
# return std::abs(a) < std::abs(b);
923+
# });
924+
# }
925+
# \endcode
926+
CursorKind.LAMBDA_EXPR = CursorKind(144)
927+
928+
# Objective-c Boolean Literal.
929+
CursorKind.OBJ_BOOL_LITERAL_EXPR = CursorKind(145)
930+
931+
# Represents the "self" expression in a ObjC method.
932+
CursorKind.OBJ_SELF_EXPR = CursorKind(146)
933+
934+
911935
# A statement whose specific kind is not exposed via this interface.
912936
#
913937
# Unexposed statements have the same operations as any other kind of statement;
@@ -999,6 +1023,9 @@ def __repr__(self):
9991023
# Windows Structured Exception Handling's finally statement.
10001024
CursorKind.SEH_FINALLY_STMT = CursorKind(228)
10011025

1026+
# A MS inline assembly statement extension.
1027+
CursorKind.MS_ASM_STMT = CursorKind(229)
1028+
10021029
# The null statement.
10031030
CursorKind.NULL_STMT = CursorKind(230)
10041031

@@ -1036,6 +1063,12 @@ def __repr__(self):
10361063
CursorKind.MACRO_INSTANTIATION = CursorKind(502)
10371064
CursorKind.INCLUSION_DIRECTIVE = CursorKind(503)
10381065

1066+
###
1067+
# Extra declaration
1068+
1069+
# A module import declaration.
1070+
CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
1071+
10391072
### Cursors ###
10401073

10411074
class Cursor(Structure):
@@ -1918,7 +1951,7 @@ def __del__(self):
19181951

19191952
def read(self, path):
19201953
"""Load a TranslationUnit from the given AST file."""
1921-
return TranslationUnit.from_ast(path, self)
1954+
return TranslationUnit.from_ast_file(path, self)
19221955

19231956
def parse(self, path, args=None, unsaved_files=None, options = 0):
19241957
"""Load the translation unit from the given source code file by running

clang/bindings/python/tests/cindex/test_cursor_kind.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ def test_name():
44
assert CursorKind.UNEXPOSED_DECL.name is 'UNEXPOSED_DECL'
55

66
def test_get_all_kinds():
7-
assert CursorKind.UNEXPOSED_DECL in CursorKind.get_all_kinds()
8-
assert CursorKind.TRANSLATION_UNIT in CursorKind.get_all_kinds()
7+
kinds = CursorKind.get_all_kinds()
8+
assert CursorKind.UNEXPOSED_DECL in kinds
9+
assert CursorKind.TRANSLATION_UNIT in kinds
10+
assert CursorKind.VARIABLE_REF in kinds
11+
assert CursorKind.LAMBDA_EXPR in kinds
12+
assert CursorKind.OBJ_BOOL_LITERAL_EXPR in kinds
13+
assert CursorKind.OBJ_SELF_EXPR in kinds
14+
assert CursorKind.MS_ASM_STMT in kinds
15+
assert CursorKind.MODULE_IMPORT_DECL in kinds
916

1017
def test_kind_groups():
1118
"""Check that every kind classifies to exactly one group."""

0 commit comments

Comments
 (0)