diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-01-31 00:41:15 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-31 00:41:15 +0000 |
commit | 8958dc9bf38ddaa820425cf3a2fec346d3820f28 (patch) | |
tree | 67251b87feefc7db39d445f089e313daba25fa5f /bindings/python/examples/cindex/cindex-dump.py | |
parent | a9f696da69e6b7ad50f527ab33be396edf7d1424 (diff) |
cindex/Python: Turn off showing IDs by default, they are really slow to compute
pending a hash function. Also added a --max-depth argument, handy for timing and
limiting the volume of output.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94936 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/examples/cindex/cindex-dump.py')
-rw-r--r-- | bindings/python/examples/cindex/cindex-dump.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/bindings/python/examples/cindex/cindex-dump.py b/bindings/python/examples/cindex/cindex-dump.py index 2357f0506e..ace4ae8276 100644 --- a/bindings/python/examples/cindex/cindex-dump.py +++ b/bindings/python/examples/cindex/cindex-dump.py @@ -22,6 +22,9 @@ def get_diag_info(diag): 'fixits' : diag.fixits } def get_cursor_id(cursor, cursor_list = []): + if not opts.showIDs: + return None + if cursor is None: return None @@ -33,7 +36,12 @@ def get_cursor_id(cursor, cursor_list = []): cursor_list.append(cursor) return len(cursor_list) - 1 -def get_info(node): +def get_info(node, depth=0): + if opts.maxDepth is not None and depth >= opts.maxDepth: + children = None + else: + children = [get_info(c, depth+1) + for c in node.get_children()] return { 'id' : get_cursor_id(node), 'kind' : node.kind, 'usr' : node.get_usr(), @@ -43,14 +51,23 @@ def get_info(node): 'extent.end' : node.extent.end, 'is_definition' : node.is_definition(), 'definition id' : get_cursor_id(node.get_definition()), - 'children' : map(get_info, node.get_children()) } + 'children' : children } def main(): from clang.cindex import Index from pprint import pprint from optparse import OptionParser, OptionGroup + + global opts + parser = OptionParser("usage: %prog [options] {filename} [clang-args*]") + parser.add_option("", "--show-ids", dest="showIDs", + help="Don't compute cursor IDs (very slow)", + default=False) + parser.add_option("", "--max-depth", dest="maxDepth", + help="Limit cursor expansion to depth N", + metavar="N", type=int, default=None) parser.disable_interspersed_args() (opts, args) = parser.parse_args() @@ -65,7 +82,7 @@ def main(): parser.error("unable to load input") pprint(('diags', map(get_diag_info, tu.diagnostics))) - pprint(('nodes', map(get_info, tu.cursor.get_children()))) + pprint(('nodes', get_info(tu.cursor))) if __name__ == '__main__': main() |