From 297e9c30911cd50b6f378773fc70f5848c593ee9 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Mon, 7 May 2012 05:56:03 +0000 Subject: - 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 --- clang/bindings/python/tests/cindex/util.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'clang/bindings/python/tests/cindex/util.py') 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', ] -- cgit v1.2.3