summaryrefslogtreecommitdiffstats
path: root/clang/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
commit3afa3ce88075043bcc84ecc4815e5c9076cc0c46 (patch)
treeaed24e7d9e2ea1499fea182a6a169e8e17504529 /clang/tools
parent1c66ae630395dd2b7f11f8a7836f087d0c2691fc (diff)
downloadbcm5719-llvm-3afa3ce88075043bcc84ecc4815e5c9076cc0c46.tar.gz
bcm5719-llvm-3afa3ce88075043bcc84ecc4815e5c9076cc0c46.zip
[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 llvm-svn: 319881
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/libclang/CIndex.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index b2edd42cb0d..49a1726ac5a 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/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)) {
OpenPOWER on IntegriCloud