Skip to content
Snippets Groups Projects
Commit db59a770 authored by Daniel Dunbar's avatar Daniel Dunbar
Browse files

cindex/Python: Support file objects as unsaved_files, albeit inefficiently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94418 91177308-0d34-0410-b5e6-96231b3b80d8
parent 326be568
No related branches found
No related tags found
No related merge requests found
...@@ -553,7 +553,6 @@ class TranslationUnit(ClangObject): ...@@ -553,7 +553,6 @@ class TranslationUnit(ClangObject):
Construct a translation unit from the given source file, using Construct a translation unit from the given source file, using
the given command line argument. the given command line argument.
""" """
# TODO: Support unsaved files.
arg_array = 0 arg_array = 0
if len(args): if len(args):
arg_array = (c_char_p * len(args))(* args) arg_array = (c_char_p * len(args))(* args)
...@@ -561,7 +560,13 @@ class TranslationUnit(ClangObject): ...@@ -561,7 +560,13 @@ class TranslationUnit(ClangObject):
if len(unsaved_files): if len(unsaved_files):
unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))() unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
for i,(name,value) in enumerate(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].name = name
unsaved_files_array[i].contents = value unsaved_files_array[i].contents = value
unsaved_files_array[i].length = len(value) unsaved_files_array[i].length = len(value)
......
...@@ -41,3 +41,11 @@ int SOME_DEFINE; ...@@ -41,3 +41,11 @@ int SOME_DEFINE;
spellings = [c.spelling for c in tu.cursor.get_children()] spellings = [c.spelling for c in tu.cursor.get_children()]
assert spellings[-2] == 'x' assert spellings[-2] == 'x'
assert spellings[-1] == 'y' 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'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment