Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Option/Arg.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Arg.cpp - Argument Implementations ---------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/ADT/SmallString.h"
10
#include "llvm/Config/llvm-config.h"
11
#include "llvm/Option/Arg.h"
12
#include "llvm/Option/ArgList.h"
13
#include "llvm/Option/Option.h"
14
#include "llvm/Support/Compiler.h"
15
#include "llvm/Support/Debug.h"
16
#include "llvm/Support/raw_ostream.h"
17
18
using namespace llvm;
19
using namespace llvm::opt;
20
21
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const Arg *BaseArg)
22
    : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
23
734k
      OwnsValues(false) {}
24
25
Arg::Arg(const Option Opt, StringRef S, unsigned Index, const char *Value0,
26
         const Arg *BaseArg)
27
    : Opt(Opt), BaseArg(BaseArg), Spelling(S), Index(Index), Claimed(false),
28
2.39M
      OwnsValues(false) {
29
2.39M
  Values.push_back(Value0);
30
2.39M
}
31
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),
35
25
      OwnsValues(false) {
36
25
  Values.push_back(Value0);
37
25
  Values.push_back(Value1);
38
25
}
39
40
3.13M
Arg::~Arg() {
41
3.13M
  if (OwnsValues) {
42
35.6k
    for (unsigned i = 0, e = Values.size(); i != e; 
++i18.3k
)
43
18.3k
      delete[] Values[i];
44
17.2k
  }
45
3.13M
}
46
47
0
void Arg::print(raw_ostream& O) const {
48
0
  O << "<";
49
0
50
0
  O << " Opt:";
51
0
  Opt.print(O);
52
0
53
0
  O << " Index:" << Index;
54
0
55
0
  O << " Values: [";
56
0
  for (unsigned i = 0, e = Values.size(); i != e; ++i) {
57
0
    if (i) O << ", ";
58
0
    O << "'" << Values[i] << "'";
59
0
  }
60
0
61
0
  O << "]>\n";
62
0
}
63
64
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
65
LLVM_DUMP_METHOD void Arg::dump() const { print(dbgs()); }
66
#endif
67
68
17.1k
std::string Arg::getAsString(const ArgList &Args) const {
69
17.1k
  if (Alias)
70
28
    return Alias->getAsString(Args);
71
17.1k
72
17.1k
  SmallString<256> Res;
73
17.1k
  raw_svector_ostream OS(Res);
74
17.1k
75
17.1k
  ArgStringList ASL;
76
17.1k
  render(Args, ASL);
77
17.1k
  for (ArgStringList::iterator
78
46.6k
         it = ASL.begin(), ie = ASL.end(); it != ie; 
++it29.4k
) {
79
29.4k
    if (it != ASL.begin())
80
12.2k
      OS << ' ';
81
29.4k
    OS << *it;
82
29.4k
  }
83
17.1k
84
17.1k
  return OS.str();
85
17.1k
}
86
87
5.32k
void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
88
5.32k
  if (!getOption().hasNoOptAsInput()) {
89
581
    render(Args, Output);
90
581
    return;
91
581
  }
92
4.74k
93
4.74k
  Output.append(Values.begin(), Values.end());
94
4.74k
}
95
96
452k
void Arg::render(const ArgList &Args, ArgStringList &Output) const {
97
452k
  switch (getOption().getRenderStyle()) {
98
452k
  case Option::RenderValuesStyle:
99
415
    Output.append(Values.begin(), Values.end());
100
415
    break;
101
452k
102
452k
  case Option::RenderCommaJoinedStyle: {
103
18
    SmallString<256> Res;
104
18
    raw_svector_ostream OS(Res);
105
18
    OS << getSpelling();
106
38
    for (unsigned i = 0, e = getNumValues(); i != e; 
++i20
) {
107
20
      if (i) 
OS << ','3
;
108
20
      OS << getValue(i);
109
20
    }
110
18
    Output.push_back(Args.MakeArgString(OS.str()));
111
18
    break;
112
452k
  }
113
452k
114
452k
 case Option::RenderJoinedStyle:
115
52.8k
    Output.push_back(Args.GetOrMakeJoinedArgString(
116
52.8k
                       getIndex(), getSpelling(), getValue(0)));
117
52.8k
    Output.append(Values.begin() + 1, Values.end());
118
52.8k
    break;
119
452k
120
452k
  case Option::RenderSeparateStyle:
121
399k
    Output.push_back(Args.MakeArgString(getSpelling()));
122
399k
    Output.append(Values.begin(), Values.end());
123
399k
    break;
124
452k
  }
125
452k
}