aboutsummaryrefslogtreecommitdiff
path: root/tools/clang-cc
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-11-13 08:58:20 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-11-13 08:58:20 +0000
commit3a2838d14251427089c39caec90c8abbc27f7a14 (patch)
treecfa0899c839011c5e79e08a39c7f2f45d16afe43 /tools/clang-cc
parent0f800391ffbfe3820e1c60246a09a97e5f065179 (diff)
Rework Sema code completion interface.
- Provide Sema in callbacks, instead of requiring it in constructor. This eliminates the need for a factory function. Clients now just pass the object to consume the results in directly. - CodeCompleteConsumer is cheap to construct, so building it whenever we are doing code completion is reasonable. Doug, please review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87099 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-cc')
-rw-r--r--tools/clang-cc/clang-cc.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index b186f20ed5..5092e1ab32 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -210,19 +210,6 @@ std::string GetBuiltinIncludePath(const char *Argv0) {
return P.str();
}
-/// \brief Buld a new code-completion consumer that prints the results of
-/// code completion to standard output.
-static CodeCompleteConsumer *BuildPrintingCodeCompleter(Sema &S,
- void *UserData) {
- const FrontendOptions &Opts = *(FrontendOptions*)UserData;
- if (Opts.DebugCodeCompletionPrinter)
- return new PrintingCodeCompleteConsumer(S, Opts.ShowMacrosInCodeCompletion,
- llvm::outs());
-
- return new CIndexCodeCompleteConsumer(S, Opts.ShowMacrosInCodeCompletion,
- llvm::outs());
-}
-
//===----------------------------------------------------------------------===//
// Basic Parser driver
//===----------------------------------------------------------------------===//
@@ -494,9 +481,7 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
if (InitializeSourceManager(PP, CI.getFrontendOpts(), InFile))
return;
- CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *) = 0;
- void *CreateCodeCompleterData = (void*) &FEOpts;
-
+ llvm::OwningPtr<CodeCompleteConsumer> CCConsumer;
if (!FEOpts.CodeCompletionAt.FileName.empty()) {
// Tell the source manager to chop off the given file at a specific
// line and column.
@@ -508,7 +493,14 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
FEOpts.CodeCompletionAt.Column);
// Set up the creation routine for code-completion.
- CreateCodeCompleter = BuildPrintingCodeCompleter;
+ if (FEOpts.DebugCodeCompletionPrinter)
+ CCConsumer.reset(
+ new PrintingCodeCompleteConsumer(FEOpts.ShowMacrosInCodeCompletion,
+ llvm::outs()));
+ else
+ CCConsumer.reset(
+ new CIndexCodeCompleteConsumer(FEOpts.ShowMacrosInCodeCompletion,
+ llvm::outs()));
} else {
PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
<< FEOpts.CodeCompletionAt.FileName;
@@ -518,7 +510,7 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
// Run the AST consumer action.
ParseAST(PP, Consumer.get(), CI.getASTContext(), FEOpts.ShowStats,
CompleteTranslationUnit,
- CreateCodeCompleter, CreateCodeCompleterData);
+ CCConsumer.get());
} else {
// Initialize builtin info.
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),