29 #include "llvm/Support/CommandLine.h" 36 "-p <build-path> is used to read a compile command database.\n" 38 "\tFor example, it can be a CMake build directory in which a file named\n" 39 "\tcompile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\n" 40 "\tCMake option to get this output). When no build path is specified,\n" 41 "\ta search for compile_commands.json will be attempted through all\n" 42 "\tparent paths of the first input file . See:\n" 43 "\thttp://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an\n" 44 "\texample of setting up Clang Tooling on a source tree.\n" 46 "<source0> ... specify the paths of source files. These paths are\n" 47 "\tlooked up in the compile command database. If the path of a file is\n" 48 "\tabsolute, it needs to point into CMake's source tree. If the path is\n" 49 "\trelative, the current working directory needs to be in the CMake\n" 50 "\tsource tree and the file must be in a subdirectory of the current\n" 51 "\tworking directory. \"./\" prefixes in the relative files will be\n" 52 "\tautomatically removed, but the rest of a relative path must be a\n" 53 "\tsuffix of a path in the compile command database.\n" 58 Adjusters.push_back(std::move(Adjuster));
62 StringRef FilePath)
const {
63 return adjustCommands(Compilations->getCompileCommands(FilePath));
66 std::vector<std::string>
68 return Compilations->getAllFiles();
71 std::vector<CompileCommand>
73 return adjustCommands(Compilations->getAllCompileCommands());
76 std::vector<CompileCommand> ArgumentsAdjustingCompilations::adjustCommands(
77 std::vector<CompileCommand> Commands)
const {
79 for (
const auto &Adjuster : Adjusters)
80 Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename);
85 int &argc,
const char **argv, cl::OptionCategory &
Category,
86 llvm::cl::NumOccurrencesFlag OccurrencesFlag,
const char *Overview) {
87 static cl::opt<bool> Help(
"h", cl::desc(
"Alias for -help"), cl::Hidden,
88 cl::sub(*cl::AllSubCommands));
90 static cl::opt<std::string> BuildPath(
"p", cl::desc(
"Build path"),
92 cl::sub(*cl::AllSubCommands));
94 static cl::list<std::string> SourcePaths(
95 cl::Positional, cl::desc(
"<source0> [... <sourceN>]"), OccurrencesFlag,
96 cl::cat(
Category), cl::sub(*cl::AllSubCommands));
98 static cl::list<std::string> ArgsAfter(
100 cl::desc(
"Additional argument to append to the compiler command line"),
101 cl::cat(
Category), cl::sub(*cl::AllSubCommands));
103 static cl::list<std::string> ArgsBefore(
105 cl::desc(
"Additional argument to prepend to the compiler command line"),
106 cl::cat(
Category), cl::sub(*cl::AllSubCommands));
108 cl::ResetAllOptionOccurrences();
112 std::string ErrorMessage;
115 if (!ErrorMessage.empty())
116 ErrorMessage.append(
"\n");
117 llvm::raw_string_ostream OS(ErrorMessage);
119 if (!cl::ParseCommandLineOptions(argc, argv, Overview, &OS)) {
121 return llvm::make_error<llvm::StringError>(
"[CommonOptionsParser]: " +
123 llvm::inconvertibleErrorCode());
126 cl::PrintOptionValues();
128 SourcePathList = SourcePaths;
129 if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) &&
130 SourcePathList.empty())
131 return llvm::Error::success();
133 if (!BuildPath.empty()) {
141 llvm::errs() <<
"Error while trying to load a compilation database:\n" 142 << ErrorMessage <<
"Running without flags.\n";
147 auto AdjustingCompilations =
148 llvm::make_unique<ArgumentsAdjustingCompilations>(
149 std::move(Compilations));
155 AdjustingCompilations->appendArgumentsAdjuster(Adjuster);
156 Compilations = std::move(AdjustingCompilations);
157 return llvm::Error::success();
161 int &argc,
const char **argv, llvm::cl::OptionCategory &
Category,
162 llvm::cl::NumOccurrencesFlag OccurrencesFlag,
const char *Overview) {
165 Parser.init(argc, argv, Category, OccurrencesFlag, Overview);
167 return std::move(Err);
168 return std::move(Parser);
171 CommonOptionsParser::CommonOptionsParser(
172 int &argc,
const char **argv, cl::OptionCategory &
Category,
173 llvm::cl::NumOccurrencesFlag OccurrencesFlag,
const char *Overview) {
176 llvm::report_fatal_error(
177 "CommonOptionsParser: failed to parse command-line arguments. " +
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Parser - This implements a parser for the C family of languages.
std::string toString(const til::SExpr *E)