summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-25 09:16:55 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-25 09:16:55 +0000
commit061bae930bbb3e02ccc3d585e29f173b7f76646b (patch)
treec021d521f4a50db96d7dbf3c617d198d057b53e4 /bindings
parentdb59a7700e5e42e8b5f6f8e327067a969540ee14 (diff)
downloadclang-061bae930bbb3e02ccc3d585e29f173b7f76646b.tar.gz
cindex/Python: Move translation unit load functions to Index, there isn't a good reason to have separate static methods for this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94419 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py57
1 files changed, 22 insertions, 35 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index bba7533785..ee996bbf8b 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -506,7 +506,8 @@ class Index(ClangObject):
def read(self, path):
"""Load the translation unit from the given AST file."""
- return TranslationUnit.read(self, path)
+ ptr = TranslationUnit_read(self, path)
+ return TranslationUnit(ptr) if ptr else None
def parse(self, path, args = [], unsaved_files = []):
"""
@@ -519,7 +520,26 @@ class Index(ClangObject):
and the second should be the contents to be substituted for the
file. The contents may be passed as strings or file objects.
"""
- return TranslationUnit.parse(self, path, args, unsaved_files)
+ arg_array = 0
+ if len(args):
+ arg_array = (c_char_p * len(args))(* args)
+ unsaved_files_array = 0
+ if len(unsaved_files):
+ unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
+ for i,(name,value) in enumerate(unsaved_files):
+ 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)
+ ptr = TranslationUnit_parse(self, path, len(args), arg_array,
+ len(unsaved_files), unsaved_files_array)
+ return TranslationUnit(ptr) if ptr else None
class TranslationUnit(ClangObject):
@@ -541,39 +561,6 @@ class TranslationUnit(ClangObject):
"""Get the original translation unit source file name."""
return TranslationUnit_spelling(self)
- @staticmethod
- def read(ix, path):
- """Create a translation unit from the given AST file."""
- ptr = TranslationUnit_read(ix, path)
- return TranslationUnit(ptr) if ptr else None
-
- @staticmethod
- def parse(ix, path, args = [], unsaved_files = []):
- """
- Construct a translation unit from the given source file, using
- the given command line argument.
- """
- arg_array = 0
- if len(args):
- arg_array = (c_char_p * len(args))(* args)
- unsaved_files_array = 0
- if len(unsaved_files):
- unsaved_files_array = (_CXUnsavedFile * len(unsaved_files))()
- for i,(name,value) in enumerate(unsaved_files):
- 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)
- ptr = TranslationUnit_parse(ix, path, len(args), arg_array,
- len(unsaved_files), unsaved_files_array)
- return TranslationUnit(ptr) if ptr else None
-
class File(ClangObject):
"""
The File class represents a particular source file that is part of a