diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 21:20:39 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 21:20:39 +0000 |
commit | a6a6499a904441fc9e82ba9dd4155b8bc33f38f9 (patch) | |
tree | ddbb87227d5f95684ffe8226ca3737b61df4ee21 /bindings/python/clang/cindex.py | |
parent | 12bf15c48a007bc6cc36f3d2e8a0d2e67ccf9886 (diff) |
cindex/Python: Move Cursor.is_ methods to CursorKind, and add test.
Also, add CursorKind.get_all_kinds().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94389 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/clang/cindex.py')
-rw-r--r-- | bindings/python/clang/cindex.py | 112 |
1 files changed, 60 insertions, 52 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 1dda221c9c..54e88f90c5 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -173,6 +173,30 @@ class CursorKind(object): raise ValueError,'Unknown cursor kind' return CursorKind._kinds[id] + @staticmethod + def get_all_kinds(): + return filter(None, CursorKind._kinds) + + def is_declaration(self): + """Test if this is a declaration kind.""" + return CursorKind_is_decl(self) + + def is_reference(self): + """Test if this is a reference kind.""" + return CursorKind_is_ref(self) + + def is_expression(self): + """Test if this is an expression kind.""" + return CursorKind_is_expr(self) + + def is_statement(self): + """Test if this is a statement kind.""" + return CursorKind_is_stmt(self) + + def is_invalid(self): + """Test if this is an invalid kind.""" + return CursorKind_is_inv(self) + def __repr__(self): return 'CursorKind.%s' % (self.name,) @@ -181,6 +205,9 @@ class CursorKind(object): # things we want for sure are (a) simple external access to kinds, (b) a place # to hang a description and name, (c) easy to keep in sync with Index.h. +### +# Declaration Kinds + # A declaration whose specific kind is not exposed via this interface. # # Unexposed declarations have the same operations as any other kind of @@ -244,10 +271,11 @@ CursorKind.OBJC_IMPLEMENTATION_DECL = CursorKind(18) # An Objective-C @implementation for a category. CursorKind.OBJC_CATEGORY_IMPL_DECL = CursorKind(19) -# A typedef +# A typedef. CursorKind.TYPEDEF_DECL = CursorKind(20) -# References. +### +# Reference Kinds CursorKind.OBJC_SUPER_CLASS_REF = CursorKind(40) CursorKind.OBJC_PROTOCOL_REF = CursorKind(41) @@ -265,12 +293,16 @@ CursorKind.OBJC_CLASS_REF = CursorKind(42) # referenced by the type of size is the typedef for size_type. CursorKind.TYPE_REF = CursorKind(43) +### +# Invalid/Error Kinds -# Error conditions. CursorKind.INVALID_FILE = CursorKind(70) CursorKind.NO_DECL_FOUND = CursorKind(71) CursorKind.NOT_IMPLEMENTED = CursorKind(72) +### +# Expression Kinds + # An expression whose specific kind is not exposed via this interface. # # Unexposed expressions have the same operations as any other kind of @@ -299,6 +331,9 @@ CursorKind.OBJC_MESSAGE_EXPR = CursorKind(104) # the specific kind of the statement is not reported. CursorKind.UNEXPOSED_STMT = CursorKind(200) +### +# Other Kinds + # Cursor that represents the translation unit itself. # # The translation unit cursor exists primarily to act as the root cursor for @@ -320,30 +355,6 @@ class Cursor(Structure): def __ne__(self, other): return not Cursor_eq(self, other) - def is_declaration(self): - """Return True if the cursor points to a declaration.""" - return Cursor_is_decl(self.kind) - - def is_reference(self): - """Return True if the cursor points to a reference.""" - return Cursor_is_ref(self.kind) - - def is_expression(self): - """Return True if the cursor points to an expression.""" - return Cursor_is_expr(self.kind) - - def is_statement(self): - """Return True if the cursor points to a statement.""" - return Cursor_is_stmt(self.kind) - - def is_translation_unit(self): - """Return True if the cursor points to a translation unit.""" - return Cursor_is_tu(self.kind) - - def is_invalid(self): - """Return True if the cursor points to an invalid entity.""" - return Cursor_is_inv(self.kind) - def is_definition(self): """ Returns true if the declaration pointed at by the cursor is also a @@ -380,7 +391,7 @@ class Cursor(Structure): @property def spelling(self): """Return the spelling of the entity pointed at by the cursor.""" - if not self.is_declaration(): + if not self.kind.is_declaration(): # FIXME: clang_getCursorSpelling should be fixed to not assert on # this, for consistency with clang_getCursorUSR. return None @@ -554,6 +565,27 @@ SourceRange_end = lib.clang_getRangeEnd SourceRange_end.argtypes = [SourceRange] SourceRange_end.restype = SourceLocation +# CursorKind Functions +CursorKind_is_decl = lib.clang_isDeclaration +CursorKind_is_decl.argtypes = [CursorKind] +CursorKind_is_decl.restype = bool + +CursorKind_is_ref = lib.clang_isReference +CursorKind_is_ref.argtypes = [CursorKind] +CursorKind_is_ref.restype = bool + +CursorKind_is_expr = lib.clang_isExpression +CursorKind_is_expr.argtypes = [CursorKind] +CursorKind_is_expr.restype = bool + +CursorKind_is_stmt = lib.clang_isStatement +CursorKind_is_stmt.argtypes = [CursorKind] +CursorKind_is_stmt.restype = bool + +CursorKind_is_inv = lib.clang_isInvalid +CursorKind_is_inv.argtypes = [CursorKind] +CursorKind_is_inv.restype = bool + # Cursor Functions # TODO: Implement this function Cursor_get = lib.clang_getCursor @@ -568,30 +600,6 @@ Cursor_usr.argtypes = [Cursor] Cursor_usr.restype = _CXString Cursor_usr.errcheck = _CXString.from_result -Cursor_is_decl = lib.clang_isDeclaration -Cursor_is_decl.argtypes = [CursorKind] -Cursor_is_decl.restype = bool - -Cursor_is_ref = lib.clang_isReference -Cursor_is_ref.argtypes = [CursorKind] -Cursor_is_ref.restype = bool - -Cursor_is_expr = lib.clang_isExpression -Cursor_is_expr.argtypes = [CursorKind] -Cursor_is_expr.restype = bool - -Cursor_is_stmt = lib.clang_isStatement -Cursor_is_stmt.argtypes = [CursorKind] -Cursor_is_stmt.restype = bool - -Cursor_is_inv = lib.clang_isInvalid -Cursor_is_inv.argtypes = [CursorKind] -Cursor_is_inv.restype = bool - -Cursor_is_tu = lib.clang_isTranslationUnit -Cursor_is_tu.argtypes = [CursorKind] -Cursor_is_tu.restype = bool - Cursor_is_def = lib.clang_isCursorDefinition Cursor_is_def.argtypes = [Cursor] Cursor_is_def.restype = bool |