clang  3.9.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 
17 namespace clang {
18 namespace tooling {
19 
20 /// Add -fsyntax-only option to the commnand line arguments.
22  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
23  CommandLineArguments AdjustedArgs;
24  for (size_t i = 0, e = Args.size(); i != e; ++i) {
25  StringRef Arg = Args[i];
26  // FIXME: Remove options that generate output.
27  if (!Arg.startswith("-fcolor-diagnostics") &&
28  !Arg.startswith("-fdiagnostics-color"))
29  AdjustedArgs.push_back(Args[i]);
30  }
31  AdjustedArgs.push_back("-fsyntax-only");
32  return AdjustedArgs;
33  };
34 }
35 
37  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
38  CommandLineArguments AdjustedArgs;
39  for (size_t i = 0, e = Args.size(); i < e; ++i) {
40  StringRef Arg = Args[i];
41  if (!Arg.startswith("-o"))
42  AdjustedArgs.push_back(Args[i]);
43 
44  if (Arg == "-o") {
45  // Output is specified as -o foo. Skip the next argument also.
46  ++i;
47  }
48  // Else, the output is specified as -ofoo. Just do nothing.
49  }
50  return AdjustedArgs;
51  };
52 }
53 
56  return [Extra, Pos](const CommandLineArguments &Args, StringRef /*unused*/) {
57  CommandLineArguments Return(Args);
58 
60  if (Pos == ArgumentInsertPosition::END) {
61  I = Return.end();
62  } else {
63  I = Return.begin();
64  ++I; // To leave the program name in place
65  }
66 
67  Return.insert(I, Extra.begin(), Extra.end());
68  return Return;
69  };
70 }
71 
74  return getInsertArgumentAdjuster(CommandLineArguments(1, Extra), Pos);
75 }
76 
78  ArgumentsAdjuster Second) {
79  return [First, Second](const CommandLineArguments &Args, StringRef File) {
80  return Second(First(Args, File), File);
81  };
82 }
83 
84 } // end namespace tooling
85 } // end namespace clang
86 
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...
detail::InMemoryDirectory::const_iterator I
ArgumentsAdjuster getClangStripOutputAdjuster()
Gets an argument adjuster which removes output-related command line arguments.
std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)> ArgumentsAdjuster
A prototype of a command line adjuster.
const TemplateArgument * iterator
Definition: Type.h:4233
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...