[cfe-commits] r143321 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_file.py
Tobias Grosser
grosser at fim.uni-passau.de
Sun Oct 30 17:07:19 PDT 2011
Author: grosser
Date: Sun Oct 30 19:07:19 2011
New Revision: 143321
URL: http://llvm.org/viewvc/llvm-project?rev=143321&view=rev
Log:
cindex.py: Add File.create_from_name()
Added:
cfe/trunk/bindings/python/tests/cindex/test_file.py
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=143321&r1=143320&r2=143321&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Oct 30 19:07:19 2011
@@ -1523,6 +1523,11 @@
translation unit.
"""
+ @staticmethod
+ def from_name(translation_unit, file_name):
+ """Retrieve a file handle within the given translation unit."""
+ return File(File_getFile(translation_unit, file_name))
+
@property
def name(self):
"""Return the complete file and path name of the file."""
@@ -1533,6 +1538,12 @@
"""Return the last modification time of the file."""
return File_time(self)
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return "<File: %s>" % (self.name)
+
class FileInclusion(object):
"""
The FileInclusion class represents the inclusion of one source file by
@@ -1759,6 +1770,10 @@
py_object]
# File Functions
+File_getFile = lib.clang_getFile
+File_getFile.argtypes = [TranslationUnit, c_char_p]
+File_getFile.restype = c_object_p
+
File_name = lib.clang_getFileName
File_name.argtypes = [File]
File_name.restype = _CXString
Added: cfe/trunk/bindings/python/tests/cindex/test_file.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_file.py?rev=143321&view=auto
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_file.py (added)
+++ cfe/trunk/bindings/python/tests/cindex/test_file.py Sun Oct 30 19:07:19 2011
@@ -0,0 +1,9 @@
+from clang.cindex import Index, File
+
+def test_file():
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files = [('t.c', "")])
+ file = File.from_name(tu, "t.c")
+ assert str(file) == "t.c"
+ assert file.name == "t.c"
+ assert repr(file) == "<File: t.c>"
More information about the cfe-commits
mailing list