clang  3.7.0
ArgumentsAdjusters.cpp
Go to the documentation of this file.
1 //===--- ArgumentsAdjusters.cpp - Command line arguments adjuster ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains definitions of classes which implement ArgumentsAdjuster
11 // interface.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/Basic/LLVM.h"
17 #include "llvm/ADT/StringRef.h"
18 
19 namespace clang {
20 namespace tooling {
21 
22 /// Add -fsyntax-only option to the commnand line arguments.
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]);
32  }
33  AdjustedArgs.push_back("-fsyntax-only");
34  return AdjustedArgs;
35  };
36 }
37 
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]);
45 
46  if (Arg == "-o") {
47  // Output is specified as -o foo. Skip the next argument also.
48  ++i;
49  }
50  // Else, the output is specified as -ofoo. Just do nothing.
51  }
52  return AdjustedArgs;
53  };
54 }
55 
58  return [Extra, Pos](const CommandLineArguments &Args) {
59  CommandLineArguments Return(Args);
60 
61  CommandLineArguments::iterator I;
62  if (Pos == ArgumentInsertPosition::END) {
63  I = Return.end();
64  } else {
65  I = Return.begin();
66  ++I; // To leave the program name in place
67  }
68 
69  Return.insert(I, Extra.begin(), Extra.end());
70  return Return;
71  };
72 }
73 
76  return getInsertArgumentAdjuster(CommandLineArguments(1, Extra), Pos);
77 }
78 
80  ArgumentsAdjuster Second) {
81  return [First, Second](const CommandLineArguments &Args) {
82  return Second(First(Args));
83  };
84 }
85 
86 } // end namespace tooling
87 } // end namespace clang
88 
ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra, ArgumentInsertPosition Pos)
Gets an argument adjuster which inserts Extra arguments in the specified position.
ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First, ArgumentsAdjuster Second)
Gets an argument adjuster which adjusts the arguments in sequence with the First adjuster and then wi...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
ArgumentsAdjuster getClangStripOutputAdjuster()
Gets an argument adjuster which removes output-related command line arguments.
std::function< CommandLineArguments(const CommandLineArguments &)> ArgumentsAdjuster
A prototype of a command line adjuster.
std::vector< std::string > CommandLineArguments
A sequence of command line arguments.
ArgumentsAdjuster getClangSyntaxOnlyAdjuster()
Gets an argument adjuster that converts input command line arguments to the "syntax check only" varia...