forked from OSchip/llvm-project
[libclang] Create a diagnostic set to pass at the end of indexing.
llvm-svn: 145557
This commit is contained in:
parent
e659b8459e
commit
f2d99b0d38
|
@ -1702,21 +1702,27 @@ static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo,
|
|||
}
|
||||
|
||||
static void index_diagnostic(CXClientData client_data,
|
||||
CXDiagnostic diag, void *reserved) {
|
||||
CXDiagnosticSet diagSet, void *reserved) {
|
||||
CXString str;
|
||||
const char *cstr;
|
||||
unsigned numDiags, i;
|
||||
CXDiagnostic diag;
|
||||
IndexData *index_data;
|
||||
index_data = (IndexData *)client_data;
|
||||
printCheck(index_data);
|
||||
|
||||
str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
|
||||
cstr = clang_getCString(str);
|
||||
printf("[diagnostic]: %s\n", cstr);
|
||||
clang_disposeString(str);
|
||||
|
||||
if (getenv("CINDEXTEST_FAILONERROR") &&
|
||||
clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) {
|
||||
index_data->fail_for_error = 1;
|
||||
numDiags = clang_getNumDiagnosticsInSet(diagSet);
|
||||
for (i = 0; i != numDiags; ++i) {
|
||||
diag = clang_getDiagnosticInSet(diagSet, i);
|
||||
str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
|
||||
cstr = clang_getCString(str);
|
||||
printf("[diagnostic]: %s\n", cstr);
|
||||
clang_disposeString(str);
|
||||
|
||||
if (getenv("CINDEXTEST_FAILONERROR") &&
|
||||
clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) {
|
||||
index_data->fail_for_error = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
using namespace clang;
|
||||
using namespace clang::cxloc;
|
||||
using namespace clang::cxstring;
|
||||
using namespace clang::cxdiag;
|
||||
using namespace llvm;
|
||||
|
||||
|
||||
|
@ -39,8 +40,8 @@ CXDiagnosticSetImpl::~CXDiagnosticSetImpl() {
|
|||
|
||||
CXDiagnosticImpl::~CXDiagnosticImpl() {}
|
||||
|
||||
static CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU,
|
||||
bool checkIfChanged = false) {
|
||||
CXDiagnosticSetImpl *cxdiag::lazyCreateDiags(CXTranslationUnit TU,
|
||||
bool checkIfChanged) {
|
||||
ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData);
|
||||
|
||||
if (TU->Diagnostics && checkIfChanged) {
|
||||
|
|
|
@ -149,6 +149,11 @@ struct CXStoredDiagnostic : public CXDiagnosticImpl {
|
|||
}
|
||||
};
|
||||
|
||||
namespace cxdiag {
|
||||
CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU,
|
||||
bool checkIfChanged = false);
|
||||
} // end namespace cxdiag
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "CXSourceLocation.h"
|
||||
#include "CXTranslationUnit.h"
|
||||
#include "CXString.h"
|
||||
#include "CIndexDiagnostic.h"
|
||||
#include "CIndexer.h"
|
||||
|
||||
#include "clang/Frontend/ASTUnit.h"
|
||||
|
@ -31,6 +32,8 @@ using namespace cxstring;
|
|||
using namespace cxtu;
|
||||
using namespace cxindex;
|
||||
|
||||
static void indexDiagnostics(CXTranslationUnit TU, IndexingContext &IdxCtx);
|
||||
|
||||
namespace {
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -158,13 +161,15 @@ public:
|
|||
|
||||
class IndexingFrontendAction : public ASTFrontendAction {
|
||||
IndexingContext IndexCtx;
|
||||
CXTranslationUnit CXTU;
|
||||
|
||||
public:
|
||||
IndexingFrontendAction(CXClientData clientData,
|
||||
IndexerCallbacks &indexCallbacks,
|
||||
unsigned indexOptions,
|
||||
CXTranslationUnit cxTU)
|
||||
: IndexCtx(clientData, indexCallbacks, indexOptions, cxTU) { }
|
||||
: IndexCtx(clientData, indexCallbacks, indexOptions, cxTU),
|
||||
CXTU(cxTU) { }
|
||||
|
||||
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
|
||||
StringRef InFile) {
|
||||
|
@ -174,6 +179,10 @@ public:
|
|||
return new IndexingConsumer(IndexCtx);
|
||||
}
|
||||
|
||||
virtual void EndSourceFileAction() {
|
||||
indexDiagnostics(CXTU, IndexCtx);
|
||||
}
|
||||
|
||||
virtual TranslationUnitKind getTranslationUnitKind() { return TU_Prefix; }
|
||||
virtual bool hasCodeCompletionSupport() const { return false; }
|
||||
};
|
||||
|
@ -334,7 +343,6 @@ static void clang_indexSourceFile_Impl(void *UserData) {
|
|||
bool Persistent = requestedToGetTU;
|
||||
StringRef ResourceFilesPath = CXXIdx->getClangResourcesPath();
|
||||
bool OnlyLocalDecls = false;
|
||||
bool CaptureDiagnostics = true;
|
||||
bool PrecompilePreamble = false;
|
||||
bool CacheCodeCompletionResults = false;
|
||||
PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
|
||||
|
@ -360,13 +368,12 @@ static void clang_indexSourceFile_Impl(void *UserData) {
|
|||
Persistent,
|
||||
ResourceFilesPath,
|
||||
OnlyLocalDecls,
|
||||
CaptureDiagnostics,
|
||||
/*CaptureDiagnostics=*/true,
|
||||
PrecompilePreamble,
|
||||
CacheCodeCompletionResults);
|
||||
if (!Unit)
|
||||
return;
|
||||
|
||||
// FIXME: Set state of the ASTUnit according to the TU_options.
|
||||
if (out_TU)
|
||||
*out_TU = CXTU->takeTU();
|
||||
|
||||
|
@ -450,8 +457,11 @@ static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IdxCtx) {
|
|||
}
|
||||
|
||||
static void indexDiagnostics(CXTranslationUnit TU, IndexingContext &IdxCtx) {
|
||||
// FIXME: Create a CXDiagnosticSet from TU;
|
||||
// IdxCtx.handleDiagnosticSet(Set);
|
||||
if (!IdxCtx.hasDiagnosticCallback())
|
||||
return;
|
||||
|
||||
CXDiagnosticSetImpl *DiagSet = cxdiag::lazyCreateDiags(TU);
|
||||
IdxCtx.handleDiagnosticSet(DiagSet);
|
||||
}
|
||||
|
||||
static void clang_indexTranslationUnit_Impl(void *UserData) {
|
||||
|
|
|
@ -312,6 +312,8 @@ public:
|
|||
|
||||
bool shouldAbort();
|
||||
|
||||
bool hasDiagnosticCallback() const { return CB.diagnostic; }
|
||||
|
||||
void enteredMainFile(const FileEntry *File);
|
||||
|
||||
void ppIncludedFile(SourceLocation hashLoc,
|
||||
|
|
Loading…
Reference in New Issue