]> granicus.if.org Git - clang/commitdiff
Move code completion options to clang-cc
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Nov 2009 01:02:10 +0000 (01:02 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Nov 2009 01:02:10 +0000 (01:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87050 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/FrontendOptions.h
tools/CIndex/CIndex.cpp
tools/clang-cc/Options.cpp
tools/clang-cc/clang-cc.cpp

index 27897a240f7ed61b5840b9aa854bec262ba1fbd6..0ccb242796ce60db41ebf43ce78486129b5fb1a3 100644 (file)
@@ -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<std::string> InputFilenames;
@@ -40,12 +49,17 @@ public:
   /// A list of locations to apply fix-its at.
   std::vector<ParsedSourceLocation> 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;
   }
index 69cb52b485074f0d5625c0a76207e3ef9d22206e..cf33d7d8cdc6ccd5264471adad9fd200f56e4a4d 100644 (file)
@@ -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).
index 7181b7c89a8bc8887bd54603ec1dca54fed07245..bedf852811e9f58f0821c989c488f31b5e9396c9 100644 (file)
@@ -293,6 +293,20 @@ VerifyDiagnostics("verify",
 
 namespace frontendoptions {
 
+static llvm::cl::opt<ParsedSourceLocation>
+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<bool>
+CodeCompletionDebugPrinter("code-completion-debug-printer",
+                      llvm::cl::desc("Use the \"debug\" code-completion print"),
+                           llvm::cl::init(true));
+
+static llvm::cl::opt<bool>
+CodeCompletionWantsMacros("code-completion-macros",
+                 llvm::cl::desc("Include macros in code-completion results"));
+
 static llvm::cl::opt<bool>
 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.
index 1b9578c743bcad6ec9c97d87722d9c78681f00d0..8081ceec3502f72aa542ee29243836d531506570 100644 (file)
 
 using namespace clang;
 
-//===----------------------------------------------------------------------===//
-// Code Completion Options
-//===----------------------------------------------------------------------===//
-
-enum CodeCompletionPrinter {
-  CCP_Debug,
-  CCP_CIndex
-};
-
-static llvm::cl::opt<ParsedSourceLocation>
-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>
-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<bool>
-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;
       }
     }