No DeclCollector in interface; much more efficient OnlyLex path.

This commit is contained in:
Axel Naumann 2015-01-21 13:28:30 +01:00 committed by sftnight
parent ae0290a4fb
commit 276ff16454
2 changed files with 38 additions and 25 deletions

View File

@ -24,21 +24,21 @@ namespace clang {
} }
namespace cling { namespace cling {
class DeclCollector;
class CIFactory { class CIFactory {
public: public:
typedef std::unique_ptr<llvm::MemoryBuffer> MemBufPtr_t;
// TODO: Add overload that takes file not MemoryBuffer // TODO: Add overload that takes file not MemoryBuffer
static clang::CompilerInstance* createCI(llvm::StringRef code, static clang::CompilerInstance* createCI(llvm::StringRef code,
int argc, int argc,
const char* const *argv, const char* const *argv,
const char* llvmdir); const char* llvmdir);
static clang::CompilerInstance* createCI( static clang::CompilerInstance* createCI(MemBufPtr_t buffer,
std::unique_ptr<llvm::MemoryBuffer> buffer,
int argc, int argc,
const char* const *argv, const char* const *argv,
const char* llvmdir, const char* llvmdir,
std::unique_ptr<DeclCollector> stateCollector); bool OnlyLex = false);
private: private:
//--------------------------------------------------------------------- //---------------------------------------------------------------------
//! Constructor //! Constructor

View File

@ -450,9 +450,8 @@ namespace {
I = HostCXXI.begin(), E = HostCXXI.end(); I != E; ++I) I = HostCXXI.begin(), E = HostCXXI.end(); I != E; ++I)
args.push_back(I->c_str()); args.push_back(I->c_str());
} }
} // unnamed namespace
namespace cling {
// //
// Dummy function so we can use dladdr to find the executable path. // Dummy function so we can use dladdr to find the executable path.
// //
@ -484,20 +483,12 @@ namespace cling {
return &Cmd->getArguments(); return &Cmd->getArguments();
} }
CompilerInstance* CIFactory::createCI(llvm::StringRef code, static CompilerInstance* createCIImpl(
int argc,
const char* const *argv,
const char* llvmdir) {
return createCI(llvm::MemoryBuffer::getMemBuffer(code), argc, argv, llvmdir,
std::unique_ptr<DeclCollector>(new DeclCollector()));
}
CompilerInstance* CIFactory::createCI(
std::unique_ptr<llvm::MemoryBuffer> buffer, std::unique_ptr<llvm::MemoryBuffer> buffer,
int argc, int argc,
const char* const *argv, const char* const *argv,
const char* llvmdir, const char* llvmdir,
std::unique_ptr<DeclCollector> stateCollector) { bool OnlyLex) {
// Create an instance builder, passing the llvmdir and arguments. // Create an instance builder, passing the llvmdir and arguments.
// //
@ -712,18 +703,21 @@ namespace cling {
// Set up the ASTContext // Set up the ASTContext
CI->createASTContext(); CI->createASTContext();
//FIXME: This is bad workaround for use-cases which need only a CI to parse if (OnlyLex) {
//things, like pragmas. In that case we cannot controll the interpreter's class IgnoreConsumer: public clang::ASTConsumer {
// state collector thus detach from whatever possible. };
if (stateCollector) { std::unique_ptr<clang::ASTConsumer> ignoreConsumer(new IgnoreConsumer());
CI->setASTConsumer(std::move(ignoreConsumer));
} else {
std::unique_ptr<cling::DeclCollector>
stateCollector(new cling::DeclCollector());
// Set up the ASTConsumers
CI->getASTContext().setASTMutationListener(stateCollector.get());
// Add the callback keeping track of the macro definitions // Add the callback keeping track of the macro definitions
PP.addPPCallbacks(std::move(stateCollector->MakePPAdapter())); PP.addPPCallbacks(std::move(stateCollector->MakePPAdapter()));
CI->setASTConsumer(std::move(stateCollector));
} }
else
stateCollector.reset(new DeclCollector());
// Set up the ASTConsumers
CI->getASTContext().setASTMutationListener(stateCollector.get());
CI->setASTConsumer(std::move(stateCollector));
// Set up Sema // Set up Sema
CodeCompleteConsumer* CCC = 0; CodeCompleteConsumer* CCC = 0;
@ -740,4 +734,23 @@ namespace cling {
return CI.release(); // Passes over the ownership to the caller. return CI.release(); // Passes over the ownership to the caller.
} }
} // unnamed namespace
namespace cling {
CompilerInstance* CIFactory::createCI(llvm::StringRef code,
int argc,
const char* const *argv,
const char* llvmdir) {
return createCIImpl(llvm::MemoryBuffer::getMemBuffer(code), argc, argv, llvmdir, false /*OnlyLex*/);
}
CompilerInstance* CIFactory::createCI(MemBufPtr_t buffer,
int argc,
const char* const *argv,
const char* llvmdir,
bool OnlyLex) {
return createCIImpl(std::move(buffer), argc, argv, llvmdir, OnlyLex);
}
} // end namespace } // end namespace