]> granicus.if.org Git - clang/commitdiff
cindex/Python: Turn off showing IDs by default, they are really slow to compute
authorDaniel Dunbar <daniel@zuster.org>
Sun, 31 Jan 2010 00:41:15 +0000 (00:41 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 31 Jan 2010 00:41:15 +0000 (00:41 +0000)
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

bindings/python/examples/cindex/cindex-dump.py

index 2357f0506e0747d32d59245c828dc24be37670e1..ace4ae82761e474c2b3463a5f10903ebb1c41756 100644 (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()