[cfe-commits] r94419 - /cfe/trunk/bindings/python/clang/cindex.py

Daniel Dunbar daniel at zuster.org
Mon Jan 25 01:16:55 PST 2010


Author: ddunbar
Date: Mon Jan 25 03:16:55 2010
New Revision: 94419

URL: http://llvm.org/viewvc/llvm-project?rev=94419&view=rev
Log:
cindex/Python: Move translation unit load functions to Index, there isn't a good reason to have separate static methods for this.

Modified:
    cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=94419&r1=94418&r2=94419&view=diff

==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Mon Jan 25 03:16:55 2010
@@ -506,7 +506,8 @@
 
     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 @@
         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 @@
         """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





More information about the cfe-commits mailing list