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/ADT/SmallString.h"
11 #include "llvm/Config/llvm-config.h"
12 #include "llvm/Option/Arg.h"
13 #include "llvm/Option/ArgList.h"
14 #include "llvm/Option/Option.h"
15 #include "llvm/Support/Compiler.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm::opt
;
22 Arg::Arg(const Option Opt
, StringRef S
, unsigned Index
, const Arg
*BaseArg
)
23 : Opt(Opt
), BaseArg(BaseArg
), Spelling(S
), Index(Index
), Claimed(false),
26 Arg::Arg(const Option Opt
, StringRef S
, unsigned Index
, const char *Value0
,
28 : Opt(Opt
), BaseArg(BaseArg
), Spelling(S
), Index(Index
), Claimed(false),
30 Values
.push_back(Value0
);
33 Arg::Arg(const Option Opt
, StringRef S
, unsigned Index
, const char *Value0
,
34 const char *Value1
, const Arg
*BaseArg
)
35 : Opt(Opt
), BaseArg(BaseArg
), Spelling(S
), Index(Index
), Claimed(false),
37 Values
.push_back(Value0
);
38 Values
.push_back(Value1
);
43 for (unsigned i
= 0, e
= Values
.size(); i
!= e
; ++i
)
48 void Arg::print(raw_ostream
& O
) const {
54 O
<< " Index:" << Index
;
57 for (unsigned i
= 0, e
= Values
.size(); i
!= e
; ++i
) {
59 O
<< "'" << Values
[i
] << "'";
65 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66 LLVM_DUMP_METHOD
void Arg::dump() const { print(dbgs()); }
69 std::string
Arg::getAsString(const ArgList
&Args
) const {
71 raw_svector_ostream
OS(Res
);
75 for (ArgStringList::iterator
76 it
= ASL
.begin(), ie
= ASL
.end(); it
!= ie
; ++it
) {
77 if (it
!= ASL
.begin())
85 void Arg::renderAsInput(const ArgList
&Args
, ArgStringList
&Output
) const {
86 if (!getOption().hasNoOptAsInput()) {
91 Output
.append(Values
.begin(), Values
.end());
94 void Arg::render(const ArgList
&Args
, ArgStringList
&Output
) const {
95 switch (getOption().getRenderStyle()) {
96 case Option::RenderValuesStyle
:
97 Output
.append(Values
.begin(), Values
.end());
100 case Option::RenderCommaJoinedStyle
: {
101 SmallString
<256> Res
;
102 raw_svector_ostream
OS(Res
);
104 for (unsigned i
= 0, e
= getNumValues(); i
!= e
; ++i
) {
108 Output
.push_back(Args
.MakeArgString(OS
.str()));
112 case Option::RenderJoinedStyle
:
113 Output
.push_back(Args
.GetOrMakeJoinedArgString(
114 getIndex(), getSpelling(), getValue(0)));
115 Output
.append(Values
.begin() + 1, Values
.end());
118 case Option::RenderSeparateStyle
:
119 Output
.push_back(Args
.MakeArgString(getSpelling()));
120 Output
.append(Values
.begin(), Values
.end());