Coverage Report

Created: 2021-01-26 06:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Transformer/Stencil.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Stencil.cpp - Stencil implementation -------------------*- C++ -*-===//
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 "clang/Tooling/Transformer/Stencil.h"
10
#include "clang/AST/ASTContext.h"
11
#include "clang/AST/ASTTypeTraits.h"
12
#include "clang/AST/Expr.h"
13
#include "clang/ASTMatchers/ASTMatchFinder.h"
14
#include "clang/ASTMatchers/ASTMatchers.h"
15
#include "clang/Basic/SourceLocation.h"
16
#include "clang/Lex/Lexer.h"
17
#include "clang/Tooling/Transformer/SourceCode.h"
18
#include "clang/Tooling/Transformer/SourceCodeBuilders.h"
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/ADT/Twine.h"
21
#include "llvm/Support/Errc.h"
22
#include "llvm/Support/Error.h"
23
#include <atomic>
24
#include <memory>
25
#include <string>
26
27
using namespace clang;
28
using namespace transformer;
29
30
using ast_matchers::MatchFinder;
31
using llvm::errc;
32
using llvm::Error;
33
using llvm::Expected;
34
using llvm::StringError;
35
36
static llvm::Expected<DynTypedNode>
37
6
getNode(const ast_matchers::BoundNodes &Nodes, StringRef Id) {
38
6
  auto &NodesMap = Nodes.getMap();
39
6
  auto It = NodesMap.find(Id);
40
6
  if (It == NodesMap.end())
41
0
    return llvm::make_error<llvm::StringError>(llvm::errc::invalid_argument,
42
0
                                               "Id not bound: " + Id);
43
6
  return It->second;
44
6
}
45
46
namespace {
47
// An arbitrary fragment of code within a stencil.
48
struct RawTextData {
49
126
  explicit RawTextData(std::string T) : Text(std::move(T)) {}
50
  std::string Text;
51
};
52
53
// A debugging operation to dump the AST for a particular (bound) AST node.
54
struct DebugPrintNodeData {
55
1
  explicit DebugPrintNodeData(std::string S) : Id(std::move(S)) {}
56
  std::string Id;
57
};
58
59
// Operators that take a single node Id as an argument.
60
enum class UnaryNodeOperator {
61
  Parens,
62
  Deref,
63
  MaybeDeref,
64
  AddressOf,
65
  MaybeAddressOf,
66
  Describe,
67
};
68
69
// Generic container for stencil operations with a (single) node-id argument.
70
struct UnaryOperationData {
71
  UnaryOperationData(UnaryNodeOperator Op, std::string Id)
72
33
      : Op(Op), Id(std::move(Id)) {}
73
  UnaryNodeOperator Op;
74
  std::string Id;
75
};
76
77
// The fragment of code corresponding to the selected range.
78
struct SelectorData {
79
19
  explicit SelectorData(RangeSelector S) : Selector(std::move(S)) {}
80
  RangeSelector Selector;
81
};
82
83
// A stencil operation to build a member access `e.m` or `e->m`, as appropriate.
84
struct AccessData {
85
  AccessData(StringRef BaseId, Stencil Member)
86
15
      : BaseId(std::string(BaseId)), Member(std::move(Member)) {}
87
  std::string BaseId;
88
  Stencil Member;
89
};
90
91
struct IfBoundData {
92
  IfBoundData(StringRef Id, Stencil TrueStencil, Stencil FalseStencil)
93
      : Id(std::string(Id)), TrueStencil(std::move(TrueStencil)),
94
5
        FalseStencil(std::move(FalseStencil)) {}
95
  std::string Id;
96
  Stencil TrueStencil;
97
  Stencil FalseStencil;
98
};
99
100
struct SequenceData {
101
11
  SequenceData(std::vector<Stencil> Stencils) : Stencils(std::move(Stencils)) {}
102
  std::vector<Stencil> Stencils;
103
};
104
105
18
std::string toStringData(const RawTextData &Data) {
106
18
  std::string Result;
107
18
  llvm::raw_string_ostream OS(Result);
108
18
  OS << "\"";
109
18
  OS.write_escaped(Data.Text);
110
18
  OS << "\"";
111
18
  OS.flush();
112
18
  return Result;
113
18
}
114
115
1
std::string toStringData(const DebugPrintNodeData &Data) {
116
1
  return (llvm::Twine("dPrint(\"") + Data.Id + "\")").str();
117
1
}
118
119
4
std::string toStringData(const UnaryOperationData &Data) {
120
4
  StringRef OpName;
121
4
  switch (Data.Op) {
122
1
  case UnaryNodeOperator::Parens:
123
1
    OpName = "expression";
124
1
    break;
125
1
  case UnaryNodeOperator::Deref:
126
1
    OpName = "deref";
127
1
    break;
128
0
  case UnaryNodeOperator::MaybeDeref:
129
0
    OpName = "maybeDeref";
130
0
    break;
131
1
  case UnaryNodeOperator::AddressOf:
132
1
    OpName = "addressOf";
133
1
    break;
134
0
  case UnaryNodeOperator::MaybeAddressOf:
135
0
    OpName = "maybeAddressOf";
136
0
    break;
137
1
  case UnaryNodeOperator::Describe:
138
1
    OpName = "describe";
139
1
    break;
140
4
  }
141
4
  return (OpName + "(\"" + Data.Id + "\")").str();
142
4
}
143
144
2
std::string toStringData(const SelectorData &) { return "selection(...)"; }
145
146
8
std::string toStringData(const AccessData &Data) {
147
8
  return (llvm::Twine("access(\"") + Data.BaseId + "\", " +
148
8
          Data.Member->toString() + ")")
149
8
      .str();
150
8
}
151
152
3
std::string toStringData(const IfBoundData &Data) {
153
3
  return (llvm::Twine("ifBound(\"") + Data.Id + "\", " +
154
3
          Data.TrueStencil->toString() + ", " + Data.FalseStencil->toString() +
155
3
          ")")
156
3
      .str();
157
3
}
158
159
1
std::string toStringData(const MatchConsumer<std::string> &) {
160
1
  return "run(...)";
161
1
}
162
163
4
std::string toStringData(const SequenceData &Data) {
164
4
  llvm::SmallVector<std::string, 2> Parts;
165
4
  Parts.reserve(Data.Stencils.size());
166
4
  for (const auto &S : Data.Stencils)
167
10
    Parts.push_back(S->toString());
168
4
  return (llvm::Twine("seq(") + llvm::join(Parts, ", ") + ")").str();
169
4
}
170
171
// The `evalData()` overloads evaluate the given stencil data to a string, given
172
// the match result, and append it to `Result`. We define an overload for each
173
// type of stencil data.
174
175
Error evalData(const RawTextData &Data, const MatchFinder::MatchResult &,
176
156
               std::string *Result) {
177
156
  Result->append(Data.Text);
178
156
  return Error::success();
179
156
}
180
181
static Error printNode(StringRef Id, const MatchFinder::MatchResult &Match,
182
6
                       std::string *Result) {
183
6
  std::string Output;
184
6
  llvm::raw_string_ostream Os(Output);
185
6
  auto NodeOrErr = getNode(Match.Nodes, Id);
186
6
  if (auto Err = NodeOrErr.takeError())
187
0
    return Err;
188
6
  NodeOrErr->print(Os, PrintingPolicy(Match.Context->getLangOpts()));
189
6
  *Result += Os.str();
190
6
  return Error::success();
191
6
}
192
193
Error evalData(const DebugPrintNodeData &Data,
194
0
               const MatchFinder::MatchResult &Match, std::string *Result) {
195
0
  return printNode(Data.Id, Match, Result);
196
0
}
197
198
// FIXME: Consider memoizing this function using the `ASTContext`.
199
6
static bool isSmartPointerType(QualType Ty, ASTContext &Context) {
200
6
  using namespace ::clang::ast_matchers;
201
202
  // Optimization: hard-code common smart-pointer types. This can/should be
203
  // removed if we start caching the results of this function.
204
6
  auto KnownSmartPointer =
205
6
      cxxRecordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
206
6
  const auto QuacksLikeASmartPointer = cxxRecordDecl(
207
6
      hasMethod(cxxMethodDecl(hasOverloadedOperatorName("->"),
208
6
                              returns(qualType(pointsTo(type()))))),
209
6
      hasMethod(cxxMethodDecl(hasOverloadedOperatorName("*"),
210
6
                              returns(qualType(references(type()))))));
211
6
  const auto SmartPointer = qualType(hasDeclaration(
212
6
      cxxRecordDecl(anyOf(KnownSmartPointer, QuacksLikeASmartPointer))));
213
6
  return match(SmartPointer, Ty, Context).size() > 0;
214
6
}
215
216
Error evalData(const UnaryOperationData &Data,
217
29
               const MatchFinder::MatchResult &Match, std::string *Result) {
218
  // The `Describe` operation can be applied to any node, not just expressions,
219
  // so it is handled here, separately.
220
29
  if (Data.Op == UnaryNodeOperator::Describe)
221
6
    return printNode(Data.Id, Match, Result);
222
223
23
  const auto *E = Match.Nodes.getNodeAs<Expr>(Data.Id);
224
23
  if (E == nullptr)
225
1
    return llvm::make_error<StringError>(
226
1
        errc::invalid_argument, "Id not bound or not Expr: " + Data.Id);
227
22
  llvm::Optional<std::string> Source;
228
22
  switch (Data.Op) {
229
3
  case UnaryNodeOperator::Parens:
230
3
    Source = tooling::buildParens(*E, *Match.Context);
231
3
    break;
232
3
  case UnaryNodeOperator::Deref:
233
3
    Source = tooling::buildDereference(*E, *Match.Context);
234
3
    break;
235
7
  case UnaryNodeOperator::MaybeDeref:
236
7
    if (E->getType()->isAnyPointerType() ||
237
6
        
isSmartPointerType(E->getType(), *Match.Context)3
) {
238
      // Strip off any operator->. This can only occur inside an actual arrow
239
      // member access, so we treat it as equivalent to an actual object
240
      // expression.
241
6
      if (const auto *OpCall = dyn_cast<clang::CXXOperatorCallExpr>(E)) {
242
1
        if (OpCall->getOperator() == clang::OO_Arrow &&
243
1
            OpCall->getNumArgs() == 1) {
244
1
          E = OpCall->getArg(0);
245
1
        }
246
1
      }
247
6
      Source = tooling::buildDereference(*E, *Match.Context);
248
6
      break;
249
6
    }
250
1
    *Result += tooling::getText(*E, *Match.Context);
251
1
    return Error::success();
252
4
  case UnaryNodeOperator::AddressOf:
253
4
    Source = tooling::buildAddressOf(*E, *Match.Context);
254
4
    break;
255
5
  case UnaryNodeOperator::MaybeAddressOf:
256
5
    if (E->getType()->isAnyPointerType() ||
257
3
        isSmartPointerType(E->getType(), *Match.Context)) {
258
      // Strip off any operator->. This can only occur inside an actual arrow
259
      // member access, so we treat it as equivalent to an actual object
260
      // expression.
261
3
      if (const auto *OpCall = dyn_cast<clang::CXXOperatorCallExpr>(E)) {
262
1
        if (OpCall->getOperator() == clang::OO_Arrow &&
263
1
            OpCall->getNumArgs() == 1) {
264
1
          E = OpCall->getArg(0);
265
1
        }
266
1
      }
267
3
      *Result += tooling::getText(*E, *Match.Context);
268
3
      return Error::success();
269
3
    }
270
2
    Source = tooling::buildAddressOf(*E, *Match.Context);
271
2
    break;
272
0
  case UnaryNodeOperator::Describe:
273
0
    llvm_unreachable("This case is handled at the start of the function");
274
18
  }
275
18
  if (!Source)
276
0
    return llvm::make_error<StringError>(
277
0
        errc::invalid_argument,
278
0
        "Could not construct expression source from ID: " + Data.Id);
279
18
  *Result += *Source;
280
18
  return Error::success();
281
18
}
282
283
Error evalData(const SelectorData &Data, const MatchFinder::MatchResult &Match,
284
44
               std::string *Result) {
285
44
  auto RawRange = Data.Selector(Match);
286
44
  if (!RawRange)
287
1
    return RawRange.takeError();
288
43
  CharSourceRange Range = Lexer::makeFileCharRange(
289
43
      *RawRange, *Match.SourceManager, Match.Context->getLangOpts());
290
43
  if (Range.isInvalid()) {
291
    // Validate the original range to attempt to get a meaningful error message.
292
    // If it's valid, then something else is the cause and we just return the
293
    // generic failure message.
294
3
    if (auto Err = tooling::validateEditRange(*RawRange, *Match.SourceManager))
295
3
      return handleErrors(std::move(Err), [](std::unique_ptr<StringError> E) {
296
3
        assert(E->convertToErrorCode() ==
297
3
                   llvm::make_error_code(errc::invalid_argument) &&
298
3
               "Validation errors must carry the invalid_argument code");
299
3
        return llvm::createStringError(
300
3
            errc::invalid_argument,
301
3
            "selected range could not be resolved to a valid source range; " +
302
3
                E->getMessage());
303
3
      });
304
0
    return llvm::createStringError(
305
0
        errc::invalid_argument,
306
0
        "selected range could not be resolved to a valid source range");
307
0
  }
308
  // Validate `Range`, because `makeFileCharRange` accepts some ranges that
309
  // `validateEditRange` rejects.
310
40
  if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
311
0
    return joinErrors(
312
0
        llvm::createStringError(errc::invalid_argument,
313
0
                                "selected range is not valid for editing"),
314
0
        std::move(Err));
315
40
  *Result += tooling::getText(Range, *Match.Context);
316
40
  return Error::success();
317
40
}
318
319
Error evalData(const AccessData &Data, const MatchFinder::MatchResult &Match,
320
7
               std::string *Result) {
321
7
  const auto *E = Match.Nodes.getNodeAs<Expr>(Data.BaseId);
322
7
  if (E == nullptr)
323
0
    return llvm::make_error<StringError>(errc::invalid_argument,
324
0
                                         "Id not bound: " + Data.BaseId);
325
7
  if (!E->isImplicitCXXThis()) {
326
6
    if (llvm::Optional<std::string> S =
327
6
            E->getType()->isAnyPointerType()
328
6
                ? tooling::buildArrow(*E, *Match.Context)
329
6
                : tooling::buildDot(*E, *Match.Context))
330
6
      *Result += *S;
331
0
    else
332
0
      return llvm::make_error<StringError>(
333
0
          errc::invalid_argument,
334
0
          "Could not construct object text from ID: " + Data.BaseId);
335
7
  }
336
7
  return Data.Member->eval(Match, Result);
337
7
}
338
339
Error evalData(const IfBoundData &Data, const MatchFinder::MatchResult &Match,
340
2
               std::string *Result) {
341
2
  auto &M = Match.Nodes.getMap();
342
1
  return (M.find(Data.Id) != M.end() ? Data.TrueStencil : Data.FalseStencil)
343
2
      ->eval(Match, Result);
344
2
}
345
346
Error evalData(const MatchConsumer<std::string> &Fn,
347
1
               const MatchFinder::MatchResult &Match, std::string *Result) {
348
1
  Expected<std::string> Value = Fn(Match);
349
1
  if (!Value)
350
0
    return Value.takeError();
351
1
  *Result += *Value;
352
1
  return Error::success();
353
1
}
354
355
Error evalData(const SequenceData &Data, const MatchFinder::MatchResult &Match,
356
24
               std::string *Result) {
357
24
  for (const auto &S : Data.Stencils)
358
94
    if (auto Err = S->eval(Match, Result))
359
3
      return Err;
360
21
  return Error::success();
361
24
}
362
363
template <typename T> class StencilImpl : public StencilInterface {
364
  T Data;
365
366
public:
367
  template <typename... Ps>
368
212
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::RawTextData>::StencilImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
368
126
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SelectorData>::StencilImpl<std::__1::function<llvm::Expected<clang::CharSourceRange> (clang::ast_matchers::MatchFinder::MatchResult const&)> >(std::__1::function<llvm::Expected<clang::CharSourceRange> (clang::ast_matchers::MatchFinder::MatchResult const&)>&&)
Line
Count
Source
368
19
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::DebugPrintNodeData>::StencilImpl<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
368
1
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::UnaryOperationData>::StencilImpl<(anonymous namespace)::UnaryNodeOperator, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >((anonymous namespace)::UnaryNodeOperator&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&)
Line
Count
Source
368
33
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::AccessData>::StencilImpl<llvm::StringRef&, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >(llvm::StringRef&, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&&)
Line
Count
Source
368
15
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::IfBoundData>::StencilImpl<llvm::StringRef&, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >(llvm::StringRef&, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&&, std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&&)
Line
Count
Source
368
5
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<std::__1::function<llvm::Expected<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (clang::ast_matchers::MatchFinder::MatchResult const&)> >::StencilImpl<std::__1::function<llvm::Expected<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (clang::ast_matchers::MatchFinder::MatchResult const&)> >(std::__1::function<llvm::Expected<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (clang::ast_matchers::MatchFinder::MatchResult const&)>&&)
Line
Count
Source
368
2
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SequenceData>::StencilImpl<std::__1::vector<std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::allocator<std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > >(std::__1::vector<std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::allocator<std::__1::shared_ptr<clang::transformer::MatchComputation<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > >&&)
Line
Count
Source
368
11
  explicit StencilImpl(Ps &&... Args) : Data(std::forward<Ps>(Args)...) {}
369
370
  Error eval(const MatchFinder::MatchResult &Match,
371
263
             std::string *Result) const override {
372
263
    return evalData(Data, Match, Result);
373
263
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::RawTextData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
156
             std::string *Result) const override {
372
156
    return evalData(Data, Match, Result);
373
156
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SelectorData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
44
             std::string *Result) const override {
372
44
    return evalData(Data, Match, Result);
373
44
  }
Unexecuted instantiation: Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::DebugPrintNodeData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::UnaryOperationData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
29
             std::string *Result) const override {
372
29
    return evalData(Data, Match, Result);
373
29
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::AccessData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
7
             std::string *Result) const override {
372
7
    return evalData(Data, Match, Result);
373
7
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::IfBoundData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
2
             std::string *Result) const override {
372
2
    return evalData(Data, Match, Result);
373
2
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<std::__1::function<llvm::Expected<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (clang::ast_matchers::MatchFinder::MatchResult const&)> >::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
1
             std::string *Result) const override {
372
1
    return evalData(Data, Match, Result);
373
1
  }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SequenceData>::eval(clang::ast_matchers::MatchFinder::MatchResult const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const
Line
Count
Source
371
24
             std::string *Result) const override {
372
24
    return evalData(Data, Match, Result);
373
24
  }
374
375
41
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::RawTextData>::toString() const
Line
Count
Source
375
18
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SelectorData>::toString() const
Line
Count
Source
375
2
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::DebugPrintNodeData>::toString() const
Line
Count
Source
375
1
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::UnaryOperationData>::toString() const
Line
Count
Source
375
4
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::AccessData>::toString() const
Line
Count
Source
375
8
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::IfBoundData>::toString() const
Line
Count
Source
375
3
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<std::__1::function<llvm::Expected<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > (clang::ast_matchers::MatchFinder::MatchResult const&)> >::toString() const
Line
Count
Source
375
1
  std::string toString() const override { return toStringData(Data); }
Stencil.cpp:(anonymous namespace)::StencilImpl<(anonymous namespace)::SequenceData>::toString() const
Line
Count
Source
375
4
  std::string toString() const override { return toStringData(Data); }
376
};
377
} // namespace
378
379
126
Stencil transformer::detail::makeStencil(StringRef Text) {
380
126
  return std::make_shared<StencilImpl<RawTextData>>(std::string(Text));
381
126
}
382
383
19
Stencil transformer::detail::makeStencil(RangeSelector Selector) {
384
19
  return std::make_shared<StencilImpl<SelectorData>>(std::move(Selector));
385
19
}
386
387
1
Stencil transformer::dPrint(StringRef Id) {
388
1
  return std::make_shared<StencilImpl<DebugPrintNodeData>>(std::string(Id));
389
1
}
390
391
5
Stencil transformer::expression(llvm::StringRef Id) {
392
5
  return std::make_shared<StencilImpl<UnaryOperationData>>(
393
5
      UnaryNodeOperator::Parens, std::string(Id));
394
5
}
395
396
4
Stencil transformer::deref(llvm::StringRef ExprId) {
397
4
  return std::make_shared<StencilImpl<UnaryOperationData>>(
398
4
      UnaryNodeOperator::Deref, std::string(ExprId));
399
4
}
400
401
7
Stencil transformer::maybeDeref(llvm::StringRef ExprId) {
402
7
  return std::make_shared<StencilImpl<UnaryOperationData>>(
403
7
      UnaryNodeOperator::MaybeDeref, std::string(ExprId));
404
7
}
405
406
5
Stencil transformer::addressOf(llvm::StringRef ExprId) {
407
5
  return std::make_shared<StencilImpl<UnaryOperationData>>(
408
5
      UnaryNodeOperator::AddressOf, std::string(ExprId));
409
5
}
410
411
5
Stencil transformer::maybeAddressOf(llvm::StringRef ExprId) {
412
5
  return std::make_shared<StencilImpl<UnaryOperationData>>(
413
5
      UnaryNodeOperator::MaybeAddressOf, std::string(ExprId));
414
5
}
415
416
7
Stencil transformer::describe(StringRef Id) {
417
7
  return std::make_shared<StencilImpl<UnaryOperationData>>(
418
7
      UnaryNodeOperator::Describe, std::string(Id));
419
7
}
420
421
15
Stencil transformer::access(StringRef BaseId, Stencil Member) {
422
15
  return std::make_shared<StencilImpl<AccessData>>(BaseId, std::move(Member));
423
15
}
424
425
Stencil transformer::ifBound(StringRef Id, Stencil TrueStencil,
426
5
                             Stencil FalseStencil) {
427
5
  return std::make_shared<StencilImpl<IfBoundData>>(Id, std::move(TrueStencil),
428
5
                                                    std::move(FalseStencil));
429
5
}
430
431
2
Stencil transformer::run(MatchConsumer<std::string> Fn) {
432
2
  return std::make_shared<StencilImpl<MatchConsumer<std::string>>>(
433
2
      std::move(Fn));
434
2
}
435
436
111
Stencil transformer::catVector(std::vector<Stencil> Parts) {
437
  // Only one argument, so don't wrap in sequence.
438
111
  if (Parts.size() == 1)
439
100
    return std::move(Parts[0]);
440
11
  return std::make_shared<StencilImpl<SequenceData>>(std::move(Parts));
441
11
}