[cfe-commits] r94418 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_translation_unit.py
Daniel Dunbar
daniel at zuster.org
Mon Jan 25 01:16:42 PST 2010
Author: ddunbar
Date: Mon Jan 25 03:16:41 2010
New Revision: 94418
URL: http://llvm.org/viewvc/llvm-project?rev=94418&view=rev
Log:
cindex/Python: Support file objects as unsaved_files, albeit inefficiently.
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=94418&r1=94417&r2=94418&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Mon Jan 25 03:16:41 2010
@@ -553,7 +553,6 @@
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 @@
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)
Modified: cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py?rev=94418&r1=94417&r2=94418&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py Mon Jan 25 03:16:41 2010
@@ -41,3 +41,11 @@
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'
More information about the cfe-commits
mailing list