diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2014-02-12 19:12:37 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2014-02-12 19:12:37 +0000 |
commit | ea4d1c32fb9681b093461e03fc098f8f29f71b5b (patch) | |
tree | ffc026456ec5ef9cd5fd464247a7528d967074f6 /clang/tools/libclang/Indexing.cpp | |
parent | 2039d446034b332c2ce9238924f74a1c2304014f (diff) | |
download | bcm5719-llvm-ea4d1c32fb9681b093461e03fc098f8f29f71b5b.tar.gz bcm5719-llvm-ea4d1c32fb9681b093461e03fc098f8f29f71b5b.zip |
libclang: report error code for bad PCH files
This commit improves libclang to report the error condition when
CXTranslationUnit can not be created because of a stale PCH file. This allows
the caller, for example, to rebuild the PCH file and retry the request.
There two are APIs in libclang that return a CXTranslationUnit and don't
support reporting detailed errors (the only error condition is a NULL result).
For these APIs, a second, superior, version is introduced --
clang_createTranslationUnit2 and clang_parseTranslationUnit2. These functions
return a CXTranslationUnit indirectly and also return an error code. Old
functions are still supported and are nothing more than convenience wrappers
that ignore extended error codes.
As a cleanup, this commit also categorizes some libclang errors in the
functions I had to modify anyway.
llvm-svn: 201249
Diffstat (limited to 'clang/tools/libclang/Indexing.cpp')
-rw-r--r-- | clang/tools/libclang/Indexing.cpp | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index dc7a0c0714b..9b83aa00e9f 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -514,16 +514,22 @@ static void clang_indexSourceFile_Impl(void *UserData) { unsigned num_unsaved_files = ITUI->num_unsaved_files; CXTranslationUnit *out_TU = ITUI->out_TU; unsigned TU_options = ITUI->TU_options; - ITUI->result = 1; // init as error. - + + // Set up the initial return value. + ITUI->result = CXError_Failure; + if (out_TU) *out_TU = 0; - bool requestedToGetTU = (out_TU != 0); + bool requestedToGetTU = (out_TU != 0); - if (!cxIdxAction) + if (!cxIdxAction) { + ITUI->result = CXError_InvalidArguments; return; - if (!client_index_callbacks || index_callbacks_size == 0) + } + if (!client_index_callbacks || index_callbacks_size == 0) { + ITUI->result = CXError_InvalidArguments; return; + } IndexerCallbacks CB; memset(&CB, 0, sizeof(CB)); @@ -671,13 +677,18 @@ static void clang_indexSourceFile_Impl(void *UserData) { if (DiagTrap.hasErrorOccurred() && CXXIdx->getDisplayDiagnostics()) printDiagsToStderr(Unit); + if (isASTReadError(Unit)) { + ITUI->result = CXError_ASTReadError; + return; + } + if (!Success) return; if (out_TU) *out_TU = CXTU->takeTU(); - ITUI->result = 0; // success. + ITUI->result = CXError_Success; } //===----------------------------------------------------------------------===// @@ -754,14 +765,20 @@ static void clang_indexTranslationUnit_Impl(void *UserData) { IndexerCallbacks *client_index_callbacks = ITUI->index_callbacks; unsigned index_callbacks_size = ITUI->index_callbacks_size; unsigned index_options = ITUI->index_options; - ITUI->result = 1; // init as error. + // Set up the initial return value. + ITUI->result = CXError_Failure; + + // Check arguments. if (isNotUsableTU(TU)) { LOG_BAD_TU(TU); + ITUI->result = CXError_InvalidArguments; return; } - if (!client_index_callbacks || index_callbacks_size == 0) + if (!client_index_callbacks || index_callbacks_size == 0) { + ITUI->result = CXError_InvalidArguments; return; + } CIndexer *CXXIdx = TU->CIdx; if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) @@ -809,7 +826,7 @@ static void clang_indexTranslationUnit_Impl(void *UserData) { indexTranslationUnit(*Unit, *IndexCtx); indexDiagnostics(TU, *IndexCtx); - ITUI->result = 0; + ITUI->result = CXError_Success; } //===----------------------------------------------------------------------===// @@ -981,7 +998,8 @@ int clang_indexSourceFile(CXIndexAction idxAction, index_callbacks_size, index_options, source_filename, command_line_args, num_command_line_args, unsaved_files, - num_unsaved_files, out_TU, TU_options, 0 }; + num_unsaved_files, out_TU, TU_options, + CXError_Failure }; if (getenv("LIBCLANG_NOTHREADS")) { clang_indexSourceFile_Impl(&ITUI); |