1 //===--- ArgumentsAdjusters.cpp - Command line arguments adjuster ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains definitions of classes which implement ArgumentsAdjuster
13 //===----------------------------------------------------------------------===//
15 #include "clang/Tooling/ArgumentsAdjusters.h"
20 /// Add -fsyntax-only option to the command line arguments.
21 ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
22 return [](const CommandLineArguments &Args, StringRef /*unused*/) {
23 CommandLineArguments AdjustedArgs;
24 for (size_t i = 0, e = Args.size(); i != e; ++i) {
25 StringRef Arg = Args[i];
26 // FIXME: Remove options that generate output.
27 if (!Arg.startswith("-fcolor-diagnostics") &&
28 !Arg.startswith("-fdiagnostics-color"))
29 AdjustedArgs.push_back(Args[i]);
31 AdjustedArgs.push_back("-fsyntax-only");
36 ArgumentsAdjuster getClangStripOutputAdjuster() {
37 return [](const CommandLineArguments &Args, StringRef /*unused*/) {
38 CommandLineArguments AdjustedArgs;
39 for (size_t i = 0, e = Args.size(); i < e; ++i) {
40 StringRef Arg = Args[i];
41 if (!Arg.startswith("-o"))
42 AdjustedArgs.push_back(Args[i]);
45 // Output is specified as -o foo. Skip the next argument also.
48 // Else, the output is specified as -ofoo. Just do nothing.
54 ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra,
55 ArgumentInsertPosition Pos) {
56 return [Extra, Pos](const CommandLineArguments &Args, StringRef /*unused*/) {
57 CommandLineArguments Return(Args);
59 CommandLineArguments::iterator I;
60 if (Pos == ArgumentInsertPosition::END) {
64 ++I; // To leave the program name in place
67 Return.insert(I, Extra.begin(), Extra.end());
72 ArgumentsAdjuster getInsertArgumentAdjuster(const char *Extra,
73 ArgumentInsertPosition Pos) {
74 return getInsertArgumentAdjuster(CommandLineArguments(1, Extra), Pos);
77 ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First,
78 ArgumentsAdjuster Second) {
79 return [First, Second](const CommandLineArguments &Args, StringRef File) {
80 return Second(First(Args, File), File);
84 } // end namespace tooling
85 } // end namespace clang