1 //===--- Arg.cpp - Argument Implementations -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Option/Arg.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/Twine.h"
13 #include "llvm/Option/ArgList.h"
14 #include "llvm/Option/Option.h"
15 #include "llvm/Support/raw_ostream.h"
18 using namespace llvm::opt;
20 Arg::Arg(const Option _Opt, StringRef S, unsigned _Index, const Arg *_BaseArg)
21 : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index),
22 Claimed(false), OwnsValues(false) {
25 Arg::Arg(const Option _Opt, StringRef S, unsigned _Index,
26 const char *Value0, const Arg *_BaseArg)
27 : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index),
28 Claimed(false), OwnsValues(false) {
29 Values.push_back(Value0);
32 Arg::Arg(const Option _Opt, StringRef S, unsigned _Index,
33 const char *Value0, const char *Value1, const Arg *_BaseArg)
34 : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index),
35 Claimed(false), OwnsValues(false) {
36 Values.push_back(Value0);
37 Values.push_back(Value1);
42 for (unsigned i = 0, e = Values.size(); i != e; ++i)
47 void Arg::dump() const {
50 llvm::errs() << " Opt:";
53 llvm::errs() << " Index:" << Index;
55 llvm::errs() << " Values: [";
56 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
57 if (i) llvm::errs() << ", ";
58 llvm::errs() << "'" << Values[i] << "'";
61 llvm::errs() << "]>\n";
64 std::string Arg::getAsString(const ArgList &Args) const {
66 llvm::raw_svector_ostream OS(Res);
70 for (ArgStringList::iterator
71 it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
72 if (it != ASL.begin())
80 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
81 if (!getOption().hasNoOptAsInput()) {
86 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
87 Output.push_back(getValue(i));
90 void Arg::render(const ArgList &Args, ArgStringList &Output) const {
91 switch (getOption().getRenderStyle()) {
92 case Option::RenderValuesStyle:
93 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
94 Output.push_back(getValue(i));
97 case Option::RenderCommaJoinedStyle: {
99 llvm::raw_svector_ostream OS(Res);
101 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
105 Output.push_back(Args.MakeArgString(OS.str()));
109 case Option::RenderJoinedStyle:
110 Output.push_back(Args.GetOrMakeJoinedArgString(
111 getIndex(), getSpelling(), getValue(0)));
112 for (unsigned i = 1, e = getNumValues(); i != e; ++i)
113 Output.push_back(getValue(i));
116 case Option::RenderSeparateStyle:
117 Output.push_back(Args.MakeArgString(getSpelling()));
118 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
119 Output.push_back(getValue(i));