1*e5dd7070Spatrick //===- ArgumentsAdjusters.h - Command line arguments adjuster ---*- C++ -*-===// 2*e5dd7070Spatrick // 3*e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information. 5*e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*e5dd7070Spatrick // 7*e5dd7070Spatrick //===----------------------------------------------------------------------===// 8*e5dd7070Spatrick // 9*e5dd7070Spatrick // This file declares type ArgumentsAdjuster and functions to create several 10*e5dd7070Spatrick // useful argument adjusters. 11*e5dd7070Spatrick // ArgumentsAdjusters modify command line arguments obtained from a compilation 12*e5dd7070Spatrick // database before they are used to run a frontend action. 13*e5dd7070Spatrick // 14*e5dd7070Spatrick //===----------------------------------------------------------------------===// 15*e5dd7070Spatrick 16*e5dd7070Spatrick #ifndef LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H 17*e5dd7070Spatrick #define LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H 18*e5dd7070Spatrick 19*e5dd7070Spatrick #include "clang/Basic/LLVM.h" 20*e5dd7070Spatrick #include "llvm/ADT/StringRef.h" 21*e5dd7070Spatrick #include <functional> 22*e5dd7070Spatrick #include <string> 23*e5dd7070Spatrick #include <vector> 24*e5dd7070Spatrick 25*e5dd7070Spatrick namespace clang { 26*e5dd7070Spatrick namespace tooling { 27*e5dd7070Spatrick 28*e5dd7070Spatrick /// A sequence of command line arguments. 29*e5dd7070Spatrick using CommandLineArguments = std::vector<std::string>; 30*e5dd7070Spatrick 31*e5dd7070Spatrick /// A prototype of a command line adjuster. 32*e5dd7070Spatrick /// 33*e5dd7070Spatrick /// Command line argument adjuster is responsible for command line arguments 34*e5dd7070Spatrick /// modification before the arguments are used to run a frontend action. 35*e5dd7070Spatrick using ArgumentsAdjuster = std::function<CommandLineArguments( 36*e5dd7070Spatrick const CommandLineArguments &, StringRef Filename)>; 37*e5dd7070Spatrick 38*e5dd7070Spatrick /// Gets an argument adjuster that converts input command line arguments 39*e5dd7070Spatrick /// to the "syntax check only" variant. 40*e5dd7070Spatrick ArgumentsAdjuster getClangSyntaxOnlyAdjuster(); 41*e5dd7070Spatrick 42*e5dd7070Spatrick /// Gets an argument adjuster which removes output-related command line 43*e5dd7070Spatrick /// arguments. 44*e5dd7070Spatrick ArgumentsAdjuster getClangStripOutputAdjuster(); 45*e5dd7070Spatrick 46*e5dd7070Spatrick /// Gets an argument adjuster which removes dependency-file 47*e5dd7070Spatrick /// related command line arguments. 48*e5dd7070Spatrick ArgumentsAdjuster getClangStripDependencyFileAdjuster(); 49*e5dd7070Spatrick 50*e5dd7070Spatrick enum class ArgumentInsertPosition { BEGIN, END }; 51*e5dd7070Spatrick 52*e5dd7070Spatrick /// Gets an argument adjuster which inserts \p Extra arguments in the 53*e5dd7070Spatrick /// specified position. 54*e5dd7070Spatrick ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra, 55*e5dd7070Spatrick ArgumentInsertPosition Pos); 56*e5dd7070Spatrick 57*e5dd7070Spatrick /// Gets an argument adjuster which inserts an \p Extra argument in the 58*e5dd7070Spatrick /// specified position. 59*e5dd7070Spatrick ArgumentsAdjuster getInsertArgumentAdjuster( 60*e5dd7070Spatrick const char *Extra, 61*e5dd7070Spatrick ArgumentInsertPosition Pos = ArgumentInsertPosition::END); 62*e5dd7070Spatrick 63*e5dd7070Spatrick /// Gets an argument adjuster which strips plugin related command line 64*e5dd7070Spatrick /// arguments. 65*e5dd7070Spatrick ArgumentsAdjuster getStripPluginsAdjuster(); 66*e5dd7070Spatrick 67*e5dd7070Spatrick /// Gets an argument adjuster which adjusts the arguments in sequence 68*e5dd7070Spatrick /// with the \p First adjuster and then with the \p Second one. 69*e5dd7070Spatrick ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First, 70*e5dd7070Spatrick ArgumentsAdjuster Second); 71*e5dd7070Spatrick 72*e5dd7070Spatrick } // namespace tooling 73*e5dd7070Spatrick } // namespace clang 74*e5dd7070Spatrick 75*e5dd7070Spatrick #endif // LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H 76