Move code completion options to clang-cc

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87050 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-11-13 01:02:10 +00:00
Родитель efc18e41f1
Коммит 914474ca51
4 изменённых файлов: 64 добавлений и 68 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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).

Просмотреть файл

@ -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.RelocatablePCH = RelocatablePCH;
Opts.ShowStats = Stats;
Opts.ShowTimers = TimeReport;
Opts.InputFilenames = InputFilenames;
Opts.OutputFile = OutputFile;
Opts.RelocatablePCH = RelocatablePCH;
Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
Opts.ShowStats = Stats;
Opts.ShowTimers = TimeReport;
Opts.ViewClassInheritance = InheritanceViewCls;
// '-' is the default input if none is given.

Просмотреть файл

@ -75,51 +75,6 @@
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;
}
}