[cfe-commits] r96107 - in /cfe/trunk/bindings/python/examples/cindex: cindex-dump.py cindex-includes.py

Daniel Dunbar daniel at zuster.org
Sat Feb 13 10:33:28 PST 2010


Author: ddunbar
Date: Sat Feb 13 12:33:28 2010
New Revision: 96107

URL: http://llvm.org/viewvc/llvm-project?rev=96107&view=rev
Log:
cindex/Python: Fix cindex-{dump,includes} examples to just pass all args
directly to Index, instead of requiring the input file to be first. This makes
the examples behave more like 'clang'.

For example,
  ddunbar at giles:tmp$ echo '#include <string>' | python ~/llvm/tools/clang/bindings/python/examples/cindex/cindex-includes.py -- -x c++ - | wc -l
     114
  ddunbar at giles:tmp$ echo '#include <stdio.h>' | python ~/llvm/tools/clang/bindings/python/examples/cindex/cindex-includes.py -- -x c - | wc -l
      10

Modified:
    cfe/trunk/bindings/python/examples/cindex/cindex-dump.py
    cfe/trunk/bindings/python/examples/cindex/cindex-includes.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=96107&r1=96106&r2=96107&view=diff

==============================================================================
--- cfe/trunk/bindings/python/examples/cindex/cindex-dump.py (original)
+++ cfe/trunk/bindings/python/examples/cindex/cindex-dump.py Sat Feb 13 12:33:28 2010
@@ -74,10 +74,8 @@
     if len(args) == 0:
         parser.error('invalid number arguments')
 
-    input_path = args.pop(0)
-
     index = Index.create()
-    tu = index.parse(input_path, args)
+    tu = index.parse(None, args)
     if not tu:
         parser.error("unable to load input")
 

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

==============================================================================
--- cfe/trunk/bindings/python/examples/cindex/cindex-includes.py (original)
+++ cfe/trunk/bindings/python/examples/cindex/cindex-includes.py Sat Feb 13 12:33:28 2010
@@ -18,8 +18,6 @@
     import sys
     from clang.cindex import Index
 
-    # FIXME: Allow the user to pass command line options to clang so that
-    # we can use -D and -U.
     from optparse import OptionParser, OptionGroup
 
     parser = OptionParser("usage: %prog [options] {filename} [clang-args*]")
@@ -31,17 +29,15 @@
     # FIXME: Add an output file option
     out = sys.stdout
 
-    input_path = args.pop(0)
-
-
     index = Index.create()
-    tu = index.parse(input_path, args)
+    tu = index.parse(None, args)
     if not tu:
         parser.error("unable to load input")
 
     # A helper function for generating the node name.
     def name(f):
-        return "\"" + f.name + "\""
+        if f:
+            return "\"" + f.name + "\""
 
     # Generate the include graph
     out.write("digraph G {\n")
@@ -52,7 +48,7 @@
             # actually include anything. This would generate a 1 node graph.
             line += name(i.include)
         else:
-            line += name(i.source) + "->" + name(i.include)
+            line += '%s->%s' % (name(i.source), name(i.include))
         line += "\n";
         out.write(line)
     out.write("}\n")





More information about the cfe-commits mailing list