summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-02-13 18:33:28 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-02-13 18:33:28 +0000
commit8bb44d5c86eda99c68acffacbe3ab5ca89453c9a (patch)
tree15c222841aea9e8e7b162481b0e480424aa933c6 /bindings
parentef7f798c0921cde7e665935a5630578cc1065e0f (diff)
downloadclang-8bb44d5c86eda99c68acffacbe3ab5ca89453c9a.tar.gz
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@giles:tmp$ echo '#include <string>' | python ~/llvm/tools/clang/bindings/python/examples/cindex/cindex-includes.py -- -x c++ - | wc -l 114 ddunbar@giles:tmp$ echo '#include <stdio.h>' | python ~/llvm/tools/clang/bindings/python/examples/cindex/cindex-includes.py -- -x c - | wc -l 10 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/examples/cindex/cindex-dump.py4
-rw-r--r--bindings/python/examples/cindex/cindex-includes.py12
2 files changed, 5 insertions, 11 deletions
diff --git a/bindings/python/examples/cindex/cindex-dump.py b/bindings/python/examples/cindex/cindex-dump.py
index ace4ae8276..af7ddab6ea 100644
--- a/bindings/python/examples/cindex/cindex-dump.py
+++ b/bindings/python/examples/cindex/cindex-dump.py
@@ -74,10 +74,8 @@ def main():
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")
diff --git a/bindings/python/examples/cindex/cindex-includes.py b/bindings/python/examples/cindex/cindex-includes.py
index 2220552d08..17500227a3 100644
--- a/bindings/python/examples/cindex/cindex-includes.py
+++ b/bindings/python/examples/cindex/cindex-includes.py
@@ -18,8 +18,6 @@ def main():
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 @@ def main():
# 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 @@ def main():
# 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")