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"
16 #include "clang/Basic/LLVM.h"
17 #include "llvm/ADT/StringRef.h"
22 /// Add -fsyntax-only option to the commnand line arguments.
23 ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
24 return [](const CommandLineArguments &Args) {
25 CommandLineArguments AdjustedArgs;
26 for (size_t i = 0, e = Args.size(); i != e; ++i) {
27 StringRef Arg = Args[i];
28 // FIXME: Remove options that generate output.
29 if (!Arg.startswith("-fcolor-diagnostics") &&
30 !Arg.startswith("-fdiagnostics-color"))
31 AdjustedArgs.push_back(Args[i]);
33 AdjustedArgs.push_back("-fsyntax-only");
38 ArgumentsAdjuster getClangStripOutputAdjuster() {
39 return [](const CommandLineArguments &Args) {
40 CommandLineArguments AdjustedArgs;
41 for (size_t i = 0, e = Args.size(); i < e; ++i) {
42 StringRef Arg = Args[i];
43 if (!Arg.startswith("-o"))
44 AdjustedArgs.push_back(Args[i]);
47 // Output is specified as -o foo. Skip the next argument also.
50 // Else, the output is specified as -ofoo. Just do nothing.
56 ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra,
57 ArgumentInsertPosition Pos) {
58 return [Extra, Pos](const CommandLineArguments &Args) {
59 CommandLineArguments Return(Args);
61 CommandLineArguments::iterator I;
62 if (Pos == ArgumentInsertPosition::END) {
66 ++I; // To leave the program name in place
69 Return.insert(I, Extra.begin(), Extra.end());
74 ArgumentsAdjuster getInsertArgumentAdjuster(const char *Extra,
75 ArgumentInsertPosition Pos) {
76 return getInsertArgumentAdjuster(CommandLineArguments(1, Extra), Pos);
79 ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First,
80 ArgumentsAdjuster Second) {
81 return std::bind(Second, std::bind(First, std::placeholders::_1));
84 } // end namespace tooling
85 } // end namespace clang