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