From: Daniel Dunbar Date: Fri, 13 Nov 2009 01:02:10 +0000 (+0000) Subject: Move code completion options to clang-cc X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=914474ca51d202369241a81013208833a6bb3f12;p=clang Move code completion options to clang-cc git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87050 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 27897a240f..0ccb242796 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -19,14 +19,23 @@ namespace clang { /// FrontendOptions - Options for controlling the behavior of the frontend. class FrontendOptions { public: - unsigned DisableFree : 1; ///< Disable freeing of memory on exit. - unsigned EmptyInputOnly : 1; ///< Force input files to be treated as if they - /// were empty, for timing the frontend startup. - unsigned FixItAll : 1; ///< Apply FIX-IT advice to the input source files. - unsigned RelocatablePCH : 1; ///< When generating PCH files, instruct the - /// PCH writer to create relocatable PCH files. - unsigned ShowStats : 1; ///< Show frontend performance metrics and statistics. - unsigned ShowTimers : 1; ///< Show timers for individual actions. + unsigned DebugCodeCompletionPrinter : 1; ///< Use the debug printer for code + /// completion results. + unsigned DisableFree : 1; ///< Disable memory freeing on exit. + unsigned EmptyInputOnly : 1; ///< Force input files to be treated + /// as if they were empty, for timing + /// the frontend startup. + unsigned FixItAll : 1; ///< Apply FIX-IT advice to the input + /// source files. + unsigned RelocatablePCH : 1; ///< When generating PCH files, + /// instruct the PCH writer to create + /// relocatable PCH files. + unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion + /// results. + unsigned ShowStats : 1; ///< Show frontend performance + /// metrics and statistics. + unsigned ShowTimers : 1; ///< Show timers for individual + /// actions. /// The input files. std::vector InputFilenames; @@ -40,12 +49,17 @@ public: /// A list of locations to apply fix-its at. std::vector FixItLocations; + /// If given, enable code completion at the provided location. + ParsedSourceLocation CodeCompletionAt; + public: FrontendOptions() { + DebugCodeCompletionPrinter = 0; DisableFree = 0; EmptyInputOnly = 0; FixItAll = 0; RelocatablePCH = 0; + ShowMacrosInCodeCompletion = 0; ShowStats = 0; ShowTimers = 0; } diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 69cb52b485..cf33d7d8cd 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1202,7 +1202,7 @@ void clang_codeComplete(CXIndex CIdx, argv.push_back("-Xclang"); argv.push_back(code_complete_at.c_str()); argv.push_back("-Xclang"); - argv.push_back("-code-completion-printer=cindex"); + argv.push_back("-code-completion-debug-printer=0"); // Add the source file name (FIXME: later, we'll want to build temporary // file from the buffer, or just feed the source text via standard input). diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp index 7181b7c89a..bedf852811 100644 --- a/tools/clang-cc/Options.cpp +++ b/tools/clang-cc/Options.cpp @@ -293,6 +293,20 @@ VerifyDiagnostics("verify", namespace frontendoptions { +static llvm::cl::opt +CodeCompletionAt("code-completion-at", + llvm::cl::value_desc("file:line:column"), + llvm::cl::desc("Dump code-completion information at a location")); + +static llvm::cl::opt +CodeCompletionDebugPrinter("code-completion-debug-printer", + llvm::cl::desc("Use the \"debug\" code-completion print"), + llvm::cl::init(true)); + +static llvm::cl::opt +CodeCompletionWantsMacros("code-completion-macros", + llvm::cl::desc("Include macros in code-completion results")); + static llvm::cl::opt DisableFree("disable-free", llvm::cl::desc("Disable freeing of memory on exit"), @@ -758,15 +772,18 @@ void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) { void clang::InitializeFrontendOptions(FrontendOptions &Opts) { using namespace frontendoptions; + Opts.CodeCompletionAt = CodeCompletionAt; + Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter; Opts.DisableFree = DisableFree; Opts.EmptyInputOnly = EmptyInputOnly; Opts.FixItAll = FixItAll; Opts.FixItLocations = FixItAtLocations; + Opts.InputFilenames = InputFilenames; + Opts.OutputFile = OutputFile; Opts.RelocatablePCH = RelocatablePCH; + Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros; Opts.ShowStats = Stats; Opts.ShowTimers = TimeReport; - Opts.InputFilenames = InputFilenames; - Opts.OutputFile = OutputFile; Opts.ViewClassInheritance = InheritanceViewCls; // '-' is the default input if none is given. diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 1b9578c743..8081ceec35 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -75,51 +75,6 @@ using namespace clang; -//===----------------------------------------------------------------------===// -// Code Completion Options -//===----------------------------------------------------------------------===// - -enum CodeCompletionPrinter { - CCP_Debug, - CCP_CIndex -}; - -static llvm::cl::opt -CodeCompletionAt("code-completion-at", - llvm::cl::value_desc("file:line:column"), - llvm::cl::desc("Dump code-completion information at a location")); - -static llvm::cl::opt -CodeCompletionPrinter("code-completion-printer", - llvm::cl::desc("Choose output type:"), - llvm::cl::init(CCP_Debug), - llvm::cl::values( - clEnumValN(CCP_Debug, "debug", - "Debug code-completion results"), - clEnumValN(CCP_CIndex, "cindex", - "Code-completion results for the CIndex library"), - clEnumValEnd)); - -static llvm::cl::opt -CodeCompletionWantsMacros("code-completion-macros", - llvm::cl::desc("Include macros in code-completion results")); - -/// \brief Buld a new code-completion consumer that prints the results of -/// code completion to standard output. -static CodeCompleteConsumer *BuildPrintingCodeCompleter(Sema &S, void *) { - switch (CodeCompletionPrinter.getValue()) { - case CCP_Debug: - return new PrintingCodeCompleteConsumer(S, CodeCompletionWantsMacros, - llvm::outs()); - - case CCP_CIndex: - return new CIndexCodeCompleteConsumer(S, CodeCompletionWantsMacros, - llvm::outs()); - }; - - return 0; -} - //===----------------------------------------------------------------------===// // Frontend Actions //===----------------------------------------------------------------------===// @@ -253,7 +208,7 @@ TargetABI("target-abi", llvm::cl::desc("Target a particular ABI type")); //===----------------------------------------------------------------------===// -// SourceManager initialization. +// Utility Methods //===----------------------------------------------------------------------===// static bool InitializeSourceManager(Preprocessor &PP, @@ -287,10 +242,6 @@ static bool InitializeSourceManager(Preprocessor &PP, return false; } -//===----------------------------------------------------------------------===// -// Preprocessor construction -//===----------------------------------------------------------------------===// - std::string GetBuiltinIncludePath(const char *Argv0) { llvm::sys::Path P = llvm::sys::Path::GetMainExecutable(Argv0, @@ -349,6 +300,19 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, return PP; } +/// \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 //===----------------------------------------------------------------------===// @@ -696,22 +660,23 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts, return; CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *) = 0; - void *CreateCodeCompleterData = 0; + void *CreateCodeCompleterData = (void*) &FEOpts; - if (!CodeCompletionAt.FileName.empty()) { + if (!FEOpts.CodeCompletionAt.FileName.empty()) { // Tell the source manager to chop off the given file at a specific // line and column. if (const FileEntry *Entry - = PP.getFileManager().getFile(CodeCompletionAt.FileName)) { + = PP.getFileManager().getFile(FEOpts.CodeCompletionAt.FileName)) { // Truncate the named file at the given line/column. - PP.getSourceManager().truncateFileAt(Entry, CodeCompletionAt.Line, - CodeCompletionAt.Column); + PP.getSourceManager().truncateFileAt(Entry, + FEOpts.CodeCompletionAt.Line, + FEOpts.CodeCompletionAt.Column); // Set up the creation routine for code-completion. CreateCodeCompleter = BuildPrintingCodeCompleter; } else { PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file) - << CodeCompletionAt.FileName; + << FEOpts.CodeCompletionAt.FileName; } }