[cfe-commits] r94936 - /cfe/trunk/bindings/python/examples/cindex/cindex-dump.py

Daniel Dunbar daniel at zuster.org
Sat Jan 30 16:41:15 PST 2010


Author: ddunbar
Date: Sat Jan 30 18:41:15 2010
New Revision: 94936

URL: http://llvm.org/viewvc/llvm-project?rev=94936&view=rev
Log:
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.

Modified:
    cfe/trunk/bindings/python/examples/cindex/cindex-dump.py

Modified: cfe/trunk/bindings/python/examples/cindex/cindex-dump.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/examples/cindex/cindex-dump.py?rev=94936&r1=94935&r2=94936&view=diff

==============================================================================
--- cfe/trunk/bindings/python/examples/cindex/cindex-dump.py (original)
+++ cfe/trunk/bindings/python/examples/cindex/cindex-dump.py Sat Jan 30 18:41:15 2010
@@ -22,6 +22,9 @@
              '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 @@
     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 @@
              '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 @@
         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()





More information about the cfe-commits mailing list