clang API Documentation

ArgumentsAdjusters.h
Go to the documentation of this file.
00001 //===--- ArgumentsAdjusters.h - Command line arguments adjuster -*- C++ -*-===//
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 declares base abstract class ArgumentsAdjuster and its descendants.
00011 // These classes are intended to modify command line arguments obtained from
00012 // a compilation database before they are used to run a frontend action.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
00017 #define LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
00018 
00019 #include <string>
00020 #include <vector>
00021 
00022 namespace clang {
00023 
00024 namespace tooling {
00025 
00026 /// \brief A sequence of command line arguments.
00027 typedef std::vector<std::string> CommandLineArguments;
00028 
00029 /// \brief Abstract interface for a command line adjusters.
00030 ///
00031 /// This abstract interface describes a command line argument adjuster,
00032 /// which is responsible for command line arguments modification before
00033 /// the arguments are used to run a frontend action.
00034 class ArgumentsAdjuster {
00035   virtual void anchor();
00036 public:
00037   /// \brief Returns adjusted command line arguments.
00038   ///
00039   /// \param Args Input sequence of command line arguments.
00040   ///
00041   /// \returns Modified sequence of command line arguments.
00042   virtual CommandLineArguments Adjust(const CommandLineArguments &Args) = 0;
00043   virtual ~ArgumentsAdjuster() {}
00044 };
00045 
00046 /// \brief Syntax check only command line adjuster.
00047 ///
00048 /// This class implements ArgumentsAdjuster interface and converts input
00049 /// command line arguments to the "syntax check only" variant.
00050 class ClangSyntaxOnlyAdjuster : public ArgumentsAdjuster {
00051   CommandLineArguments Adjust(const CommandLineArguments &Args) override;
00052 };
00053 
00054 /// \brief An argument adjuster which removes output-related command line
00055 /// arguments.
00056 class ClangStripOutputAdjuster : public ArgumentsAdjuster {
00057   CommandLineArguments Adjust(const CommandLineArguments &Args) override;
00058 };
00059 
00060 class InsertArgumentAdjuster : public ArgumentsAdjuster {
00061 public:
00062   enum Position { BEGIN, END };
00063 
00064   InsertArgumentAdjuster(const CommandLineArguments &Extra, Position Pos)
00065       : Extra(Extra), Pos(Pos) {}
00066 
00067   InsertArgumentAdjuster(const char *Extra, Position Pos)
00068       : Extra(1, std::string(Extra)), Pos(Pos) {}
00069 
00070   CommandLineArguments Adjust(const CommandLineArguments &Args) override;
00071 
00072 private:
00073   const CommandLineArguments Extra;
00074   const Position Pos;
00075 };
00076 } // end namespace tooling
00077 } // end namespace clang
00078 
00079 #endif // LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
00080