summaryrefslogtreecommitdiffstats
path: root/clang/bindings/python
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-25 09:16:41 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-25 09:16:41 +0000
commitdacede83495d904f82f946cc126500d5a423eda4 (patch)
tree872b564555b2b6c0eb8c3249a36021de147a88ad /clang/bindings/python
parent866a539f5f9fff350b8b8ff0652cca5af5a25e11 (diff)
downloadbcm5719-llvm-dacede83495d904f82f946cc126500d5a423eda4.tar.gz
bcm5719-llvm-dacede83495d904f82f946cc126500d5a423eda4.zip
cindex/Python: Support file objects as unsaved_files, albeit inefficiently.
llvm-svn: 94418
Diffstat (limited to 'clang/bindings/python')
-rw-r--r--clang/bindings/python/clang/cindex.py9
-rw-r--r--clang/bindings/python/tests/cindex/test_translation_unit.py8
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 7eab09cf39b..bba7533785e 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -553,7 +553,6 @@ class TranslationUnit(ClangObject):
Construct a translation unit from the given source file, using
the given command line argument.
"""
- # TODO: Support unsaved files.
arg_array = 0
if len(args):
arg_array = (c_char_p * len(args))(* args)
@@ -561,7 +560,13 @@ class TranslationUnit(ClangObject):
if len(unsaved_files):
unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
for i,(name,value) in enumerate(unsaved_files):
- # FIXME: Support file objects.
+ if not isinstance(value, str):
+ # FIXME: It would be great to support an efficient version
+ # of this, one day.
+ value = value.read()
+ print value
+ if not isinstance(value, str):
+ raise TypeError,'Unexpected unsaved file contents.'
unsaved_files_array[i].name = name
unsaved_files_array[i].contents = value
unsaved_files_array[i].length = len(value)
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index 9cf7aba3bbf..ec12e689d9f 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -41,3 +41,11 @@ int SOME_DEFINE;
spellings = [c.spelling for c in tu.cursor.get_children()]
assert spellings[-2] == 'x'
assert spellings[-1] == 'y'
+
+def test_unsaved_files_2():
+ import StringIO
+ index = Index.create()
+ tu = index.parse('fake.c', unsaved_files = [
+ ('fake.c', StringIO.StringIO('int x;'))])
+ spellings = [c.spelling for c in tu.cursor.get_children()]
+ assert spellings[-1] == 'x'
OpenPOWER on IntegriCloud