summaryrefslogtreecommitdiffstats
path: root/clang/bindings/python/tests/cindex/util.py
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-05-07 05:56:03 +0000
committerManuel Klimek <klimek@google.com>2012-05-07 05:56:03 +0000
commit297e9c30911cd50b6f378773fc70f5848c593ee9 (patch)
tree40bc36f1a868fd4c6f305494ab82850081dd7943 /clang/bindings/python/tests/cindex/util.py
parent470578a91b40a4391170a0bbd1ba3f8303386675 (diff)
downloadbcm5719-llvm-297e9c30911cd50b6f378773fc70f5848c593ee9.tar.gz
bcm5719-llvm-297e9c30911cd50b6f378773fc70f5848c593ee9.zip
- Adding lexical_parent and semantic_parent properties to clang.cindex.Cursor
- Two new tests (one for each property), require libclang built from r155858 or later to pass - New test utility function (get_cursors) that gets all the nodes with a specific spelling. Patch by Evan Pipho. llvm-svn: 156286
Diffstat (limited to 'clang/bindings/python/tests/cindex/util.py')
-rw-r--r--clang/bindings/python/tests/cindex/util.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/bindings/python/tests/cindex/util.py b/clang/bindings/python/tests/cindex/util.py
index f924094b211..e945aeacf79 100644
--- a/clang/bindings/python/tests/cindex/util.py
+++ b/clang/bindings/python/tests/cindex/util.py
@@ -58,9 +58,38 @@ def get_cursor(source, spelling):
return result
return None
+
+def get_cursors(source, spelling):
+ """Obtain all cursors from a source object with a specific spelling.
+ This provides a convenient search mechanism to find all cursors with specific
+ spelling within a source. The first argument can be either a
+ TranslationUnit or Cursor instance.
+
+ If no cursors are found, an empty list is returned.
+ """
+ cursors = []
+ children = []
+ if isinstance(source, Cursor):
+ children = source.get_children()
+ else:
+ # Assume TU
+ children = source.cursor.get_children()
+
+ for cursor in children:
+ if cursor.spelling == spelling:
+ cursors.append(cursor)
+
+ # Recurse into children.
+ cursors.extend(get_cursors(cursor, spelling))
+
+ return cursors
+
+
+
__all__ = [
'get_cursor',
+ 'get_cursors',
'get_tu',
]
OpenPOWER on IntegriCloud