Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 1 | //===--- Arg.cpp - Argument Implementations -----------------------------*-===// |
| 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 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 11 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Option.h" |
| 13 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace clang::driver; |
| 16 | |
| 17 | Arg::Arg(ArgClass _Kind, const Option *_Opt, unsigned _Index) |
| 18 | : Kind(_Kind), |
| 19 | Opt(_Opt), |
| 20 | Index(_Index) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | Arg::~Arg() { } |
| 25 | |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 26 | void Arg::dump() const { |
| 27 | llvm::errs() << "<"; |
| 28 | switch (Kind) { |
| 29 | default: |
| 30 | assert(0 && "Invalid kind"); |
| 31 | #define P(N) case N: llvm::errs() << #N; break |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 32 | P(FlagClass); |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 33 | P(PositionalClass); |
| 34 | P(JoinedClass); |
| 35 | P(SeparateClass); |
| 36 | P(CommaJoinedClass); |
| 37 | P(JoinedAndSeparateClass); |
| 38 | #undef P |
| 39 | } |
| 40 | |
| 41 | llvm::errs() << " Opt:"; |
| 42 | Opt->dump(); |
| 43 | |
| 44 | llvm::errs() << " Index:" << Index; |
| 45 | |
Daniel Dunbar | bbf842b | 2009-03-04 23:22:02 +0000 | [diff] [blame] | 46 | if (isa<CommaJoinedArg>(this) || isa<SeparateArg>(this)) |
| 47 | llvm::errs() << " NumValues:" << getNumValues(); |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 48 | |
| 49 | llvm::errs() << ">\n"; |
| 50 | |
| 51 | llvm::errs().flush(); // FIXME |
| 52 | } |
| 53 | |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 54 | FlagArg::FlagArg(const Option *Opt, unsigned Index) |
| 55 | : Arg(FlagClass, Opt, Index) { |
| 56 | } |
| 57 | |
| 58 | void FlagArg::render(const ArgList &Args, ArgStringList &Output) const { |
| 59 | assert(0 && "FIXME: Implement"); |
| 60 | } |
| 61 | |
| 62 | const char *FlagArg::getValue(const ArgList &Args, unsigned N) const { |
| 63 | assert(0 && "Invalid index."); |
| 64 | return 0; |
| 65 | } |
| 66 | |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 67 | PositionalArg::PositionalArg(const Option *Opt, unsigned Index) |
| 68 | : Arg(PositionalClass, Opt, Index) { |
| 69 | } |
| 70 | |
| 71 | void PositionalArg::render(const ArgList &Args, ArgStringList &Output) const { |
| 72 | assert(0 && "FIXME: Implement"); |
| 73 | } |
| 74 | |
| 75 | const char *PositionalArg::getValue(const ArgList &Args, unsigned N) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 76 | assert(N < getNumValues() && "Invalid index."); |
| 77 | return Args.getArgString(getIndex()); |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | JoinedArg::JoinedArg(const Option *Opt, unsigned Index) |
| 81 | : Arg(JoinedClass, Opt, Index) { |
| 82 | } |
| 83 | |
| 84 | void JoinedArg::render(const ArgList &Args, ArgStringList &Output) const { |
| 85 | assert(0 && "FIXME: Implement"); |
| 86 | } |
| 87 | |
| 88 | const char *JoinedArg::getValue(const ArgList &Args, unsigned N) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 89 | assert(N < getNumValues() && "Invalid index."); |
| 90 | // FIXME: Avoid strlen. |
| 91 | return Args.getArgString(getIndex()) + strlen(getOption().getName()); |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | CommaJoinedArg::CommaJoinedArg(const Option *Opt, unsigned Index, |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 95 | const char *Str) |
| 96 | : Arg(CommaJoinedClass, Opt, Index) { |
| 97 | const char *Prev = Str; |
| 98 | for (;; ++Str) { |
| 99 | char c = *Str; |
| 100 | |
| 101 | if (!c) { |
| 102 | if (Prev != Str) |
| 103 | Values.push_back(std::string(Prev, Str)); |
| 104 | break; |
| 105 | } else if (c == ',') { |
| 106 | if (Prev != Str) |
| 107 | Values.push_back(std::string(Prev, Str)); |
| 108 | Prev = Str + 1; |
| 109 | } |
| 110 | } |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void CommaJoinedArg::render(const ArgList &Args, ArgStringList &Output) const { |
| 114 | assert(0 && "FIXME: Implement"); |
| 115 | } |
| 116 | |
| 117 | const char *CommaJoinedArg::getValue(const ArgList &Args, unsigned N) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 118 | assert(N < getNumValues() && "Invalid index."); |
| 119 | return Values[N].c_str(); |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 122 | SeparateArg::SeparateArg(const Option *Opt, unsigned Index, unsigned _NumValues) |
| 123 | : Arg(SeparateClass, Opt, Index), NumValues(_NumValues) { |
| 124 | } |
| 125 | |
| 126 | void SeparateArg::render(const ArgList &Args, ArgStringList &Output) const { |
| 127 | assert(0 && "FIXME: Implement"); |
| 128 | } |
| 129 | |
| 130 | const char *SeparateArg::getValue(const ArgList &Args, unsigned N) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 131 | assert(N < getNumValues() && "Invalid index."); |
| 132 | return Args.getArgString(getIndex() + 1 + N); |
Daniel Dunbar | f781c41 | 2009-03-04 23:02:50 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 135 | JoinedAndSeparateArg::JoinedAndSeparateArg(const Option *Opt, unsigned Index) |
| 136 | : Arg(JoinedAndSeparateClass, Opt, Index) { |
| 137 | } |
| 138 | |
| 139 | void JoinedAndSeparateArg::render(const ArgList &Args, |
| 140 | ArgStringList &Output) const { |
| 141 | assert(0 && "FIXME: Implement"); |
| 142 | } |
| 143 | |
| 144 | const char *JoinedAndSeparateArg::getValue(const ArgList &Args, |
| 145 | unsigned N) const { |
Daniel Dunbar | 0648262 | 2009-03-05 06:38:47 +0000 | [diff] [blame^] | 146 | assert(N < getNumValues() && "Invalid index."); |
Daniel Dunbar | fb36cae | 2009-03-04 22:37:52 +0000 | [diff] [blame] | 147 | assert(0 && "FIXME: Implement"); |
| 148 | } |