/// 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;
/// 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;
}
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"),
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.
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
//===----------------------------------------------------------------------===//
llvm::cl::desc("Target a particular ABI type"));
//===----------------------------------------------------------------------===//
-// SourceManager initialization.
+// Utility Methods
//===----------------------------------------------------------------------===//
static bool InitializeSourceManager(Preprocessor &PP,
return false;
}
-//===----------------------------------------------------------------------===//
-// Preprocessor construction
-//===----------------------------------------------------------------------===//
-
std::string GetBuiltinIncludePath(const char *Argv0) {
llvm::sys::Path P =
llvm::sys::Path::GetMainExecutable(Argv0,
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
//===----------------------------------------------------------------------===//
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;
}
}