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"
16 #include "llvm/Support/Debug.h"
19 using namespace llvm::opt;
21 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
22 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
25 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
27 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
29 Values.push_back(Value0);
32 Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
33 const char *Value1, const Arg *BaseArg)
34 : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(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::print(raw_ostream& O) const {
53 O << " Index:" << Index;
56 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
58 O << "'" << Values[i] << "'";
64 LLVM_DUMP_METHOD void Arg::dump() const { print(dbgs()); }
66 std::string Arg::getAsString(const ArgList &Args) const {
68 llvm::raw_svector_ostream OS(Res);
72 for (ArgStringList::iterator
73 it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
74 if (it != ASL.begin())
82 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
83 if (!getOption().hasNoOptAsInput()) {
88 Output.append(Values.begin(), Values.end());
91 void Arg::render(const ArgList &Args, ArgStringList &Output) const {
92 switch (getOption().getRenderStyle()) {
93 case Option::RenderValuesStyle:
94 Output.append(Values.begin(), Values.end());
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 Output.append(Values.begin() + 1, Values.end());
115 case Option::RenderSeparateStyle:
116 Output.push_back(Args.MakeArgString(getSpelling()));
117 Output.append(Values.begin(), Values.end());