xref: /minix3/external/bsd/llvm/dist/clang/lib/Tooling/ArgumentsAdjusters.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===--- ArgumentsAdjusters.cpp - Command line arguments adjuster ---------===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc // This file contains definitions of classes which implement ArgumentsAdjuster
11*f4a2713aSLionel Sambuc // interface.
12*f4a2713aSLionel Sambuc //
13*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc #include "clang/Tooling/ArgumentsAdjusters.h"
16*f4a2713aSLionel Sambuc #include "clang/Basic/LLVM.h"
17*f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h"
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc namespace clang {
20*f4a2713aSLionel Sambuc namespace tooling {
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc void ArgumentsAdjuster::anchor() {
23*f4a2713aSLionel Sambuc }
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc /// Add -fsyntax-only option to the commnand line arguments.
26*f4a2713aSLionel Sambuc CommandLineArguments
27*f4a2713aSLionel Sambuc ClangSyntaxOnlyAdjuster::Adjust(const CommandLineArguments &Args) {
28*f4a2713aSLionel Sambuc   CommandLineArguments AdjustedArgs;
29*f4a2713aSLionel Sambuc   for (size_t i = 0, e = Args.size(); i != e; ++i) {
30*f4a2713aSLionel Sambuc     StringRef Arg = Args[i];
31*f4a2713aSLionel Sambuc     // FIXME: Remove options that generate output.
32*f4a2713aSLionel Sambuc     if (!Arg.startswith("-fcolor-diagnostics") &&
33*f4a2713aSLionel Sambuc         !Arg.startswith("-fdiagnostics-color"))
34*f4a2713aSLionel Sambuc       AdjustedArgs.push_back(Args[i]);
35*f4a2713aSLionel Sambuc   }
36*f4a2713aSLionel Sambuc   AdjustedArgs.push_back("-fsyntax-only");
37*f4a2713aSLionel Sambuc   return AdjustedArgs;
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc CommandLineArguments
41*f4a2713aSLionel Sambuc ClangStripOutputAdjuster::Adjust(const CommandLineArguments &Args) {
42*f4a2713aSLionel Sambuc   CommandLineArguments AdjustedArgs;
43*f4a2713aSLionel Sambuc   for (size_t i = 0, e = Args.size(); i < e; ++i) {
44*f4a2713aSLionel Sambuc     StringRef Arg = Args[i];
45*f4a2713aSLionel Sambuc     if(!Arg.startswith("-o"))
46*f4a2713aSLionel Sambuc       AdjustedArgs.push_back(Args[i]);
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc     if(Arg == "-o") {
49*f4a2713aSLionel Sambuc       // Output is specified as -o foo. Skip the next argument also.
50*f4a2713aSLionel Sambuc       ++i;
51*f4a2713aSLionel Sambuc     }
52*f4a2713aSLionel Sambuc     // Else, the output is specified as -ofoo. Just do nothing.
53*f4a2713aSLionel Sambuc   }
54*f4a2713aSLionel Sambuc   return AdjustedArgs;
55*f4a2713aSLionel Sambuc }
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc } // end namespace tooling
58*f4a2713aSLionel Sambuc } // end namespace clang
59*f4a2713aSLionel Sambuc 
60