diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-13 09:36:05 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-13 09:36:05 +0000 |
commit | f7093b5ae812fc5122b0c1c60cfc61de2a17a048 (patch) | |
tree | 884097b4725f494c6729a08034702a583bccf455 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | 242ea9a05af8d5635e5c47697dd533ed9da2bfeb (diff) | |
download | bcm5719-llvm-f7093b5ae812fc5122b0c1c60cfc61de2a17a048.tar.gz bcm5719-llvm-f7093b5ae812fc5122b0c1c60cfc61de2a17a048.zip |
Add CodeCompletion consumer to CompilerInvocation.
llvm-svn: 87100
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index e7c3611f0fd..ce7c54f3986 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -18,9 +18,11 @@ #include "clang/Lex/PTHManager.h" #include "clang/Frontend/ChainedDiagnosticClient.h" #include "clang/Frontend/PCHReader.h" +#include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" +#include "clang/Sema/CodeCompleteConsumer.h" #include "llvm/LLVMContext.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -29,7 +31,7 @@ CompilerInstance::CompilerInstance(llvm::LLVMContext *_LLVMContext, bool _OwnsLLVMContext) : LLVMContext(_LLVMContext), OwnsLLVMContext(_OwnsLLVMContext) { -} + } CompilerInstance::~CompilerInstance() { if (OwnsLLVMContext) @@ -202,3 +204,42 @@ CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path, return 0; } + +// Code Completion + +void CompilerInstance::createCodeCompletionConsumer() { + const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt; + CompletionConsumer.reset( + createCodeCompletionConsumer(getPreprocessor(), + Loc.FileName, Loc.Line, Loc.Column, + getFrontendOpts().DebugCodeCompletionPrinter, + getFrontendOpts().ShowMacrosInCodeCompletion, + llvm::outs())); +} + +CodeCompleteConsumer * +CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP, + const std::string &Filename, + unsigned Line, + unsigned Column, + bool UseDebugPrinter, + bool ShowMacros, + llvm::raw_ostream &OS) { + // Tell the source manager to chop off the given file at a specific + // line and column. + const FileEntry *Entry = PP.getFileManager().getFile(Filename); + if (!Entry) { + PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file) + << Filename; + return 0; + } + + // Truncate the named file at the given line/column. + PP.getSourceManager().truncateFileAt(Entry, Line, Column); + + // Set up the creation routine for code-completion. + if (UseDebugPrinter) + return new PrintingCodeCompleteConsumer(ShowMacros, OS); + else + return new CIndexCodeCompleteConsumer(ShowMacros, OS); +} |