Remove a fixme which was fixed in a previous commit.
[clang.git] / lib / Driver / Arg.cpp
blob83d0d26c256da4f75bff3b56f55ee51d558b257c
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 //===----------------------------------------------------------------------===//
10 #include "clang/Driver/Arg.h"
11 #include "clang/Driver/ArgList.h"
12 #include "clang/Driver/Option.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/raw_ostream.h"
17 using namespace clang::driver;
19 Arg::Arg(const Option *_Opt, unsigned _Index, const Arg *_BaseArg)
20 : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
21 Claimed(false), OwnsValues(false) {
24 Arg::Arg(const Option *_Opt, unsigned _Index,
25 const char *Value0, const Arg *_BaseArg)
26 : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
27 Claimed(false), OwnsValues(false) {
28 Values.push_back(Value0);
31 Arg::Arg(const Option *_Opt, unsigned _Index,
32 const char *Value0, const char *Value1, const Arg *_BaseArg)
33 : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
34 Claimed(false), OwnsValues(false) {
35 Values.push_back(Value0);
36 Values.push_back(Value1);
39 Arg::~Arg() {
40 if (OwnsValues) {
41 for (unsigned i = 0, e = Values.size(); i != e; ++i)
42 delete[] Values[i];
46 void Arg::dump() const {
47 llvm::errs() << "<";
49 llvm::errs() << " Opt:";
50 Opt->dump();
52 llvm::errs() << " Index:" << Index;
54 llvm::errs() << " Values: [";
55 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
56 if (i) llvm::errs() << ", ";
57 llvm::errs() << "'" << Values[i] << "'";
60 llvm::errs() << "]>\n";
63 std::string Arg::getAsString(const ArgList &Args) const {
64 llvm::SmallString<256> Res;
65 llvm::raw_svector_ostream OS(Res);
67 ArgStringList ASL;
68 render(Args, ASL);
69 for (ArgStringList::iterator
70 it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
71 if (it != ASL.begin())
72 OS << ' ';
73 OS << *it;
76 return OS.str();
79 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
80 if (!getOption().hasNoOptAsInput()) {
81 render(Args, Output);
82 return;
85 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
86 Output.push_back(getValue(Args, i));
89 void Arg::render(const ArgList &Args, ArgStringList &Output) const {
90 switch (getOption().getRenderStyle()) {
91 case Option::RenderValuesStyle:
92 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
93 Output.push_back(getValue(Args, i));
94 break;
96 case Option::RenderCommaJoinedStyle: {
97 llvm::SmallString<256> Res;
98 llvm::raw_svector_ostream OS(Res);
99 OS << getOption().getName();
100 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
101 if (i) OS << ',';
102 OS << getValue(Args, i);
104 Output.push_back(Args.MakeArgString(OS.str()));
105 break;
108 case Option::RenderJoinedStyle:
109 Output.push_back(Args.GetOrMakeJoinedArgString(
110 getIndex(), getOption().getName(), getValue(Args, 0)));
111 for (unsigned i = 1, e = getNumValues(); i != e; ++i)
112 Output.push_back(getValue(Args, i));
113 break;
115 case Option::RenderSeparateStyle:
116 Output.push_back(getOption().getName());
117 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
118 Output.push_back(getValue(Args, i));
119 break;