summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorErik Verbruggen <erikjv@me.com>2017-12-06 09:02:52 +0000
committerErik Verbruggen <erikjv@me.com>2017-12-06 09:02:52 +0000
commit0a795a46dcfa5d1e413d5ee1fafda620dedeeee1 (patch)
treeafdea0c7f5dfa777783607f0802add8bb6c3e1f4 /tools
parente792818a7bc14878111ee3145ca030e24109a4f1 (diff)
[libclang] Add function to get the buffer for a file
This can be used by clients in conjunction with an offset returned by e.g. clang_getFileLocation. Now those clients do not need to also open/read the file. Differential Revision: https://reviews.llvm.org/D40643 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319881 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/libclang/CIndex.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index b2edd42cb0..49a1726ac5 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -4162,6 +4162,27 @@ CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
return const_cast<FileEntry *>(FMgr.getFile(file_name));
}
+const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
+ size_t *size) {
+ if (isNotUsableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return nullptr;
+ }
+
+ const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
+ FileID fid = SM.translateFile(static_cast<FileEntry *>(file));
+ bool Invalid = true;
+ llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
+ if (Invalid) {
+ if (size)
+ *size = 0;
+ return nullptr;
+ }
+ if (size)
+ *size = buf->getBufferSize();
+ return buf->getBufferStart();
+}
+
unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
CXFile file) {
if (isNotUsableTU(TU)) {