2012-05-10 00:18:30 +08:00
|
|
|
//===--- ArgumentsAdjusters.cpp - Command line arguments adjuster ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains definitions of classes which implement ArgumentsAdjuster
|
|
|
|
// interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Tooling/ArgumentsAdjusters.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tooling {
|
|
|
|
|
2016-11-26 04:15:57 +08:00
|
|
|
/// Add -fsyntax-only option to the command line arguments.
|
2014-12-04 01:53:02 +08:00
|
|
|
ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
|
2015-11-05 10:19:53 +08:00
|
|
|
return [](const CommandLineArguments &Args, StringRef /*unused*/) {
|
2014-12-04 01:53:02 +08:00
|
|
|
CommandLineArguments AdjustedArgs;
|
|
|
|
for (size_t i = 0, e = Args.size(); i != e; ++i) {
|
|
|
|
StringRef Arg = Args[i];
|
|
|
|
// FIXME: Remove options that generate output.
|
|
|
|
if (!Arg.startswith("-fcolor-diagnostics") &&
|
|
|
|
!Arg.startswith("-fdiagnostics-color"))
|
|
|
|
AdjustedArgs.push_back(Args[i]);
|
|
|
|
}
|
|
|
|
AdjustedArgs.push_back("-fsyntax-only");
|
|
|
|
return AdjustedArgs;
|
|
|
|
};
|
2012-05-10 00:18:30 +08:00
|
|
|
}
|
|
|
|
|
2014-12-04 01:53:02 +08:00
|
|
|
ArgumentsAdjuster getClangStripOutputAdjuster() {
|
2015-11-05 10:19:53 +08:00
|
|
|
return [](const CommandLineArguments &Args, StringRef /*unused*/) {
|
2014-12-04 01:53:02 +08:00
|
|
|
CommandLineArguments AdjustedArgs;
|
|
|
|
for (size_t i = 0, e = Args.size(); i < e; ++i) {
|
|
|
|
StringRef Arg = Args[i];
|
|
|
|
if (!Arg.startswith("-o"))
|
|
|
|
AdjustedArgs.push_back(Args[i]);
|
2013-06-06 19:52:19 +08:00
|
|
|
|
2014-12-04 01:53:02 +08:00
|
|
|
if (Arg == "-o") {
|
2017-07-07 05:02:52 +08:00
|
|
|
// Output is specified as -o foo. Skip the next argument too.
|
2014-12-04 01:53:02 +08:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
// Else, the output is specified as -ofoo. Just do nothing.
|
2013-06-06 19:52:19 +08:00
|
|
|
}
|
2014-12-04 01:53:02 +08:00
|
|
|
return AdjustedArgs;
|
|
|
|
};
|
2013-06-06 19:52:19 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 05:02:52 +08:00
|
|
|
ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
|
|
|
|
return [](const CommandLineArguments &Args, StringRef /*unused*/) {
|
|
|
|
CommandLineArguments AdjustedArgs;
|
|
|
|
for (size_t i = 0, e = Args.size(); i < e; ++i) {
|
|
|
|
StringRef Arg = Args[i];
|
|
|
|
// All dependency-file options begin with -M. These include -MM,
|
|
|
|
// -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
|
|
|
|
if (!Arg.startswith("-M"))
|
|
|
|
AdjustedArgs.push_back(Args[i]);
|
|
|
|
|
|
|
|
if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
|
|
|
|
(Arg == "-MD") || (Arg == "-MMD")) {
|
|
|
|
// Output is specified as -MX foo. Skip the next argument also.
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AdjustedArgs;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-12-04 01:53:02 +08:00
|
|
|
ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra,
|
|
|
|
ArgumentInsertPosition Pos) {
|
2015-11-05 10:19:53 +08:00
|
|
|
return [Extra, Pos](const CommandLineArguments &Args, StringRef /*unused*/) {
|
2014-12-04 01:53:02 +08:00
|
|
|
CommandLineArguments Return(Args);
|
|
|
|
|
|
|
|
CommandLineArguments::iterator I;
|
|
|
|
if (Pos == ArgumentInsertPosition::END) {
|
|
|
|
I = Return.end();
|
|
|
|
} else {
|
|
|
|
I = Return.begin();
|
|
|
|
++I; // To leave the program name in place
|
|
|
|
}
|
|
|
|
|
|
|
|
Return.insert(I, Extra.begin(), Extra.end());
|
|
|
|
return Return;
|
|
|
|
};
|
|
|
|
}
|
2014-11-04 16:51:24 +08:00
|
|
|
|
2014-12-04 01:53:02 +08:00
|
|
|
ArgumentsAdjuster getInsertArgumentAdjuster(const char *Extra,
|
|
|
|
ArgumentInsertPosition Pos) {
|
|
|
|
return getInsertArgumentAdjuster(CommandLineArguments(1, Extra), Pos);
|
|
|
|
}
|
2014-11-04 16:51:24 +08:00
|
|
|
|
2014-12-04 01:53:02 +08:00
|
|
|
ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First,
|
|
|
|
ArgumentsAdjuster Second) {
|
2015-11-05 10:19:53 +08:00
|
|
|
return [First, Second](const CommandLineArguments &Args, StringRef File) {
|
|
|
|
return Second(First(Args, File), File);
|
2015-01-16 23:57:15 +08:00
|
|
|
};
|
2014-11-04 16:51:24 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 00:18:30 +08:00
|
|
|
} // end namespace tooling
|
|
|
|
} // end namespace clang
|