diff options
| author | Erik Verbruggen <erikjv@me.com> | 2017-05-30 14:25:54 +0000 |
|---|---|---|
| committer | Erik Verbruggen <erikjv@me.com> | 2017-05-30 14:25:54 +0000 |
| commit | 346066b68cacc3aea124b9765bd8723ae73c66dd (patch) | |
| tree | 375b1417b9446edbb6d2d4c7c9d0182e26e18332 /clang/tools | |
| parent | 6d5ac7af4a66ede67807268fd9ee9b2793532c1f (diff) | |
| download | bcm5719-llvm-346066b68cacc3aea124b9765bd8723ae73c66dd.tar.gz bcm5719-llvm-346066b68cacc3aea124b9765bd8723ae73c66dd.zip | |
[libclang] Allow to suspend a translation unit.
A suspended translation unit uses significantly less memory but on the
other side does not support any other calls than
clang_reparseTranslationUnit to resume it or
clang_disposeTranslationUnit to dispose it completely.
This helps IDEs to reduce the memory footprint. The data that is freed
by a call to clang_suspendTranslationUnit will be re-generated on the
next (re)parse anyway. Used with a preamble, this allows pretty fast
resumption of the translation unit for further use (compared to disposal
of the translation unit and a parse from scratch).
Patch by Nikolai Kosjar!
llvm-svn: 304212
Diffstat (limited to 'clang/tools')
| -rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 2 | ||||
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 14 | ||||
| -rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 1f5d6044319..31ad828a2f1 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1742,6 +1742,8 @@ int perform_test_load_source(int argc, const char **argv, return -1; if (Repeats > 1) { + clang_suspendTranslationUnit(TU); + Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files, clang_defaultReparseOptions(TU)); if (Err != CXError_Success) { diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 394ee0ec439..2d92de19d99 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3918,6 +3918,20 @@ void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) { } } +unsigned clang_suspendTranslationUnit(CXTranslationUnit CTUnit) { + if (CTUnit) { + ASTUnit *Unit = cxtu::getASTUnit(CTUnit); + + if (Unit && Unit->isUnsafeToFree()) + return false; + + Unit->ResetForParse(); + return true; + } + + return false; +} + unsigned clang_defaultReparseOptions(CXTranslationUnit TU) { return CXReparse_None; } diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index d9a406e5741..f3758469cb6 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -305,6 +305,7 @@ clang_remap_getFilenames clang_remap_getNumFiles clang_reparseTranslationUnit clang_saveTranslationUnit +clang_suspendTranslationUnit clang_sortCodeCompletionResults clang_toggleCrashRecovery clang_tokenize |

