clang API Documentation
00001 //===--- Arg.h - Parsed Argument Classes ------------------------*- 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 #ifndef CLANG_DRIVER_ARG_H_ 00011 #define CLANG_DRIVER_ARG_H_ 00012 00013 #include "Util.h" 00014 #include "llvm/ADT/SmallVector.h" 00015 #include "llvm/ADT/StringRef.h" 00016 #include <string> 00017 00018 namespace clang { 00019 namespace driver { 00020 class ArgList; 00021 class Option; 00022 00023 /// Arg - A concrete instance of a particular driver option. 00024 /// 00025 /// The Arg class encodes just enough information to be able to 00026 /// derive the argument values efficiently. In addition, Arg 00027 /// instances have an intrusive double linked list which is used by 00028 /// ArgList to provide efficient iteration over all instances of a 00029 /// particular option. 00030 class Arg { 00031 Arg(const Arg &); // DO NOT IMPLEMENT 00032 void operator=(const Arg &); // DO NOT IMPLEMENT 00033 00034 private: 00035 /// The option this argument is an instance of. 00036 const Option *Opt; 00037 00038 /// The argument this argument was derived from (during tool chain 00039 /// argument translation), if any. 00040 const Arg *BaseArg; 00041 00042 /// The index at which this argument appears in the containing 00043 /// ArgList. 00044 unsigned Index; 00045 00046 /// Was this argument used to effect compilation; used for generating 00047 /// "argument unused" diagnostics. 00048 mutable unsigned Claimed : 1; 00049 00050 /// Does this argument own its values. 00051 mutable unsigned OwnsValues : 1; 00052 00053 /// The argument values, as C strings. 00054 SmallVector<const char *, 2> Values; 00055 00056 public: 00057 Arg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0); 00058 Arg(const Option *Opt, unsigned Index, 00059 const char *Value0, const Arg *BaseArg = 0); 00060 Arg(const Option *Opt, unsigned Index, 00061 const char *Value0, const char *Value1, const Arg *BaseArg = 0); 00062 ~Arg(); 00063 00064 const Option &getOption() const { return *Opt; } 00065 unsigned getIndex() const { return Index; } 00066 00067 /// getBaseArg - Return the base argument which generated this 00068 /// arg; this is either the argument itself or the argument it was 00069 /// derived from during tool chain specific argument translation. 00070 const Arg &getBaseArg() const { 00071 return BaseArg ? *BaseArg : *this; 00072 } 00073 void setBaseArg(const Arg *_BaseArg) { 00074 BaseArg = _BaseArg; 00075 } 00076 00077 bool getOwnsValues() const { return OwnsValues; } 00078 void setOwnsValues(bool Value) const { OwnsValues = Value; } 00079 00080 bool isClaimed() const { return getBaseArg().Claimed; } 00081 00082 /// claim - Set the Arg claimed bit. 00083 void claim() const { getBaseArg().Claimed = true; } 00084 00085 unsigned getNumValues() const { return Values.size(); } 00086 const char *getValue(const ArgList &Args, unsigned N=0) const { 00087 return Values[N]; 00088 } 00089 00090 SmallVectorImpl<const char*> &getValues() { 00091 return Values; 00092 } 00093 00094 bool containsValue(StringRef Value) const { 00095 for (unsigned i = 0, e = getNumValues(); i != e; ++i) 00096 if (Values[i] == Value) 00097 return true; 00098 return false; 00099 } 00100 00101 /// render - Append the argument onto the given array as strings. 00102 void render(const ArgList &Args, ArgStringList &Output) const; 00103 00104 /// renderAsInput - Append the argument, render as an input, onto 00105 /// the given array as strings. The distinction is that some 00106 /// options only render their values when rendered as a input 00107 /// (e.g., Xlinker). 00108 void renderAsInput(const ArgList &Args, ArgStringList &Output) const; 00109 00110 static bool classof(const Arg *) { return true; } 00111 00112 void dump() const; 00113 00114 /// getAsString - Return a formatted version of the argument and 00115 /// its values, for debugging and diagnostics. 00116 std::string getAsString(const ArgList &Args) const; 00117 }; 00118 00119 } // end namespace driver 00120 } // end namespace clang 00121 00122 #endif