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), Claimed(false),
24 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
26 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
28 Values.push_back(Value0);
31 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
32 const char *Value1, const Arg *BaseArg)
33 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
35 Values.push_back(Value0);
36 Values.push_back(Value1);
41 for (unsigned i = 0, e = Values.size(); i != e; ++i)
46 void Arg::dump() const {
49 llvm::errs() << " Opt:";
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 {
65 llvm::raw_svector_ostream OS(Res);
69 for (ArgStringList::iterator
70 it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
71 if (it != ASL.begin())
79 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
80 if (!getOption().hasNoOptAsInput()) {
85 Output.append(Values.begin(), Values.end());
88 void Arg::render(const ArgList &Args, ArgStringList &Output) const {
89 switch (getOption().getRenderStyle()) {
90 case Option::RenderValuesStyle:
91 Output.append(Values.begin(), Values.end());
94 case Option::RenderCommaJoinedStyle: {
96 llvm::raw_svector_ostream OS(Res);
98 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
102 Output.push_back(Args.MakeArgString(OS.str()));
106 case Option::RenderJoinedStyle:
107 Output.push_back(Args.GetOrMakeJoinedArgString(
108 getIndex(), getSpelling(), getValue(0)));
109 Output.append(Values.begin() + 1, Values.end());
112 case Option::RenderSeparateStyle:
113 Output.push_back(Args.MakeArgString(getSpelling()));
114 Output.append(Values.begin(), Values.end());