summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-04 16:47:14 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-04 16:47:14 +0000
commit8e984da800594aefdeaf33da2f75cb66782f328e (patch)
treeeacc759e6cb7e0cf847782e7e7aa2bdfbcb569ed /clang/lib/Frontend/CompilerInstance.cpp
parent988bfce174f5debeb5f79e5050b933a418f53477 (diff)
downloadbcm5719-llvm-8e984da800594aefdeaf33da2f75cb66782f328e.tar.gz
bcm5719-llvm-8e984da800594aefdeaf33da2f75cb66782f328e.zip
Add code-completion support directly to ASTUnit, which performs code
completion within the translation unit using the same command-line arguments for parsing the translation unit. Eventually, we'll reuse the precompiled preamble to improve code-completion performance, and this also gives us a place to cache results. Expose this function via the new libclang function clang_codeCompleteAt(), which performs the code completion within a CXTranslationUnit. The completion occurs in-process (clang_codeCompletion() runs code completion out-of-process). llvm-svn: 110210
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp49
1 files changed, 32 insertions, 17 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 84e51837bc8..76773e40d38 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -296,17 +296,41 @@ CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
// Code Completion
+static bool EnableCodeCompletion(Preprocessor &PP,
+ const std::string &Filename,
+ unsigned Line,
+ unsigned Column) {
+ // 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 true;
+ }
+
+ // Truncate the named file at the given line/column.
+ PP.SetCodeCompletionPoint(Entry, Line, Column);
+ return false;
+}
+
void CompilerInstance::createCodeCompletionConsumer() {
const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt;
- CompletionConsumer.reset(
- createCodeCompletionConsumer(getPreprocessor(),
- Loc.FileName, Loc.Line, Loc.Column,
- getFrontendOpts().DebugCodeCompletionPrinter,
- getFrontendOpts().ShowMacrosInCodeCompletion,
+ if (!CompletionConsumer) {
+ CompletionConsumer.reset(
+ createCodeCompletionConsumer(getPreprocessor(),
+ Loc.FileName, Loc.Line, Loc.Column,
+ getFrontendOpts().DebugCodeCompletionPrinter,
+ getFrontendOpts().ShowMacrosInCodeCompletion,
getFrontendOpts().ShowCodePatternsInCodeCompletion,
- llvm::outs()));
- if (!CompletionConsumer)
+ llvm::outs()));
+ if (!CompletionConsumer)
+ return;
+ } else if (EnableCodeCompletion(getPreprocessor(), Loc.FileName,
+ Loc.Line, Loc.Column)) {
+ CompletionConsumer.reset();
return;
+ }
if (CompletionConsumer->isOutputBinary() &&
llvm::sys::Program::ChangeStdoutToBinary()) {
@@ -328,17 +352,8 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
bool ShowMacros,
bool ShowCodePatterns,
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;
+ if (EnableCodeCompletion(PP, Filename, Line, Column))
return 0;
- }
-
- // Truncate the named file at the given line/column.
- PP.SetCodeCompletionPoint(Entry, Line, Column);
// Set up the creation routine for code-completion.
if (UseDebugPrinter)
OpenPOWER on IntegriCloud