clang API Documentation

ArgumentsAdjusters.cpp
Go to the documentation of this file.
00001 //===--- ArgumentsAdjusters.cpp - Command line arguments adjuster ---------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains definitions of classes which implement ArgumentsAdjuster
00011 // interface.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "clang/Tooling/ArgumentsAdjusters.h"
00016 #include "clang/Basic/LLVM.h"
00017 #include "llvm/ADT/StringRef.h"
00018 
00019 namespace clang {
00020 namespace tooling {
00021 
00022 void ArgumentsAdjuster::anchor() {
00023 }
00024 
00025 /// Add -fsyntax-only option to the commnand line arguments.
00026 CommandLineArguments
00027 ClangSyntaxOnlyAdjuster::Adjust(const CommandLineArguments &Args) {
00028   CommandLineArguments AdjustedArgs;
00029   for (size_t i = 0, e = Args.size(); i != e; ++i) {
00030     StringRef Arg = Args[i];
00031     // FIXME: Remove options that generate output.
00032     if (!Arg.startswith("-fcolor-diagnostics") &&
00033         !Arg.startswith("-fdiagnostics-color"))
00034       AdjustedArgs.push_back(Args[i]);
00035   }
00036   AdjustedArgs.push_back("-fsyntax-only");
00037   return AdjustedArgs;
00038 }
00039 
00040 CommandLineArguments
00041 ClangStripOutputAdjuster::Adjust(const CommandLineArguments &Args) {
00042   CommandLineArguments AdjustedArgs;
00043   for (size_t i = 0, e = Args.size(); i < e; ++i) {
00044     StringRef Arg = Args[i];
00045     if(!Arg.startswith("-o"))
00046       AdjustedArgs.push_back(Args[i]);
00047 
00048     if(Arg == "-o") {
00049       // Output is specified as -o foo. Skip the next argument also.
00050       ++i;
00051     }
00052     // Else, the output is specified as -ofoo. Just do nothing.
00053   }
00054   return AdjustedArgs;
00055 }
00056 
00057 CommandLineArguments
00058 InsertArgumentAdjuster::Adjust(const CommandLineArguments &Args) {
00059   CommandLineArguments Return(Args);
00060 
00061   CommandLineArguments::iterator I;
00062   if (Pos == END) {
00063     I = Return.end();
00064   } else {
00065     I = Return.begin();
00066     ++I; // To leave the program name in place
00067   }
00068 
00069   Return.insert(I, Extra.begin(), Extra.end());
00070   return Return;
00071 }
00072 
00073 } // end namespace tooling
00074 } // end namespace clang
00075