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.

llvm-svn: 94936
This commit is contained in:
Daniel Dunbar
2010-01-31 00:41:15 +00:00
parent baf33fc56f
commit 288edb5bda

View File

@@ -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()