forked from OSchip/llvm-project
Add Diagnostic to Indexer, and have it keep its own FileManager instead of taking an external reference (which was leaked in the case of the CIndex library).
llvm-svn: 82429
This commit is contained in:
parent
9858859fd6
commit
948062a592
|
@ -14,6 +14,7 @@
|
||||||
#ifndef LLVM_CLANG_INDEX_INDEXER_H
|
#ifndef LLVM_CLANG_INDEX_INDEXER_H
|
||||||
#define LLVM_CLANG_INDEX_INDEXER_H
|
#define LLVM_CLANG_INDEX_INDEXER_H
|
||||||
|
|
||||||
|
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
||||||
#include "clang/Index/IndexProvider.h"
|
#include "clang/Index/IndexProvider.h"
|
||||||
#include "clang/Index/Entity.h"
|
#include "clang/Index/Entity.h"
|
||||||
#include "clang/Index/GlobalSelector.h"
|
#include "clang/Index/GlobalSelector.h"
|
||||||
|
@ -37,12 +38,16 @@ public:
|
||||||
typedef std::map<Entity, TUSetTy> MapTy;
|
typedef std::map<Entity, TUSetTy> MapTy;
|
||||||
typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
|
typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
|
||||||
|
|
||||||
explicit Indexer(Program &prog, FileManager &FM) :
|
explicit Indexer(Program &prog) :
|
||||||
Prog(prog), FileMgr(FM) { }
|
Prog(prog), Diags(&DiagClient) { }
|
||||||
|
|
||||||
Program &getProgram() const { return Prog; }
|
Program &getProgram() const { return Prog; }
|
||||||
|
|
||||||
FileManager &getFileManager() const { return FileMgr; }
|
Diagnostic &getDiagnostics() { return Diags; }
|
||||||
|
const Diagnostic &getDiagnostics() const { return Diags; }
|
||||||
|
|
||||||
|
FileManager &getFileManager() { return FileMgr; }
|
||||||
|
const FileManager &getFileManager() const { return FileMgr; }
|
||||||
|
|
||||||
/// \brief Find all Entities and map them to the given translation unit.
|
/// \brief Find all Entities and map them to the given translation unit.
|
||||||
void IndexAST(TranslationUnit *TU);
|
void IndexAST(TranslationUnit *TU);
|
||||||
|
@ -54,7 +59,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Program &Prog;
|
Program &Prog;
|
||||||
FileManager &FileMgr;
|
TextDiagnosticBuffer DiagClient;
|
||||||
|
Diagnostic Diags;
|
||||||
|
FileManager FileMgr;
|
||||||
|
|
||||||
MapTy Map;
|
MapTy Map;
|
||||||
CtxTUMapTy CtxTUMap;
|
CtxTUMapTy CtxTUMap;
|
||||||
|
|
|
@ -187,7 +187,8 @@ extern "C" {
|
||||||
|
|
||||||
CXIndex clang_createIndex()
|
CXIndex clang_createIndex()
|
||||||
{
|
{
|
||||||
return new Indexer(*new Program(), *new FileManager());
|
// FIXME: Program is leaked.
|
||||||
|
return new Indexer(*new Program());
|
||||||
}
|
}
|
||||||
|
|
||||||
void clang_disposeIndex(CXIndex CIdx)
|
void clang_disposeIndex(CXIndex CIdx)
|
||||||
|
|
|
@ -211,10 +211,8 @@ int main(int argc, char **argv) {
|
||||||
llvm::cl::ParseCommandLineOptions(argc, argv,
|
llvm::cl::ParseCommandLineOptions(argc, argv,
|
||||||
"LLVM 'Clang' Indexing Test Bed: http://clang.llvm.org\n");
|
"LLVM 'Clang' Indexing Test Bed: http://clang.llvm.org\n");
|
||||||
|
|
||||||
FileManager FileMgr;
|
|
||||||
|
|
||||||
Program Prog;
|
Program Prog;
|
||||||
Indexer Idxer(Prog, FileMgr);
|
Indexer Idxer(Prog);
|
||||||
llvm::SmallVector<TUnit*, 4> TUnits;
|
llvm::SmallVector<TUnit*, 4> TUnits;
|
||||||
|
|
||||||
// If no input was specified, read from stdin.
|
// If no input was specified, read from stdin.
|
||||||
|
@ -227,7 +225,8 @@ int main(int argc, char **argv) {
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
llvm::OwningPtr<ASTUnit> AST;
|
llvm::OwningPtr<ASTUnit> AST;
|
||||||
|
|
||||||
AST.reset(ASTUnit::LoadFromPCHFile(InFile, FileMgr, &ErrMsg));
|
AST.reset(ASTUnit::LoadFromPCHFile(InFile, Idxer.getFileManager(),
|
||||||
|
&ErrMsg));
|
||||||
if (!AST) {
|
if (!AST) {
|
||||||
llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
|
llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -245,7 +244,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (!PointAtLocation.empty()) {
|
if (!PointAtLocation.empty()) {
|
||||||
const std::string &Filename = PointAtLocation[0].FileName;
|
const std::string &Filename = PointAtLocation[0].FileName;
|
||||||
const FileEntry *File = FileMgr.getFile(Filename);
|
const FileEntry *File = Idxer.getFileManager().getFile(Filename);
|
||||||
if (File == 0) {
|
if (File == 0) {
|
||||||
llvm::errs() << "File '" << Filename << "' does not exist\n";
|
llvm::errs() << "File '" << Filename << "' does not exist\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -254,7 +253,7 @@ int main(int argc, char **argv) {
|
||||||
// Safety check. Using an out-of-date AST file will only lead to crashes
|
// Safety check. Using an out-of-date AST file will only lead to crashes
|
||||||
// or incorrect results.
|
// or incorrect results.
|
||||||
// FIXME: Check all the source files that make up the AST file.
|
// FIXME: Check all the source files that make up the AST file.
|
||||||
const FileEntry *ASTFile = FileMgr.getFile(FirstFile);
|
const FileEntry *ASTFile = Idxer.getFileManager().getFile(FirstFile);
|
||||||
if (File->getModificationTime() > ASTFile->getModificationTime()) {
|
if (File->getModificationTime() > ASTFile->getModificationTime()) {
|
||||||
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
llvm::errs() << "[" << FirstFile << "] Error: " <<
|
||||||
"Pointing at a source file which was modified after creating "
|
"Pointing at a source file which was modified after creating "
|
||||||
|
|
Loading…
Reference in New Issue