clang  16.0.0git
RewriteRule.cpp
Go to the documentation of this file.
1 //===--- Transformer.cpp - Transformer library 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 
11 #include "clang/AST/Stmt.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Errc.h"
19 #include "llvm/Support/Error.h"
20 #include <map>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 using namespace clang;
26 using namespace transformer;
27 
29 using ast_matchers::internal::DynTypedMatcher;
30 
32 
33 const char transformer::RootID[] = "___root___";
34 
36 translateEdits(const MatchResult &Result, ArrayRef<ASTEdit> ASTEdits) {
38  for (const auto &E : ASTEdits) {
39  Expected<CharSourceRange> Range = E.TargetRange(Result);
40  if (!Range)
41  return Range.takeError();
43  tooling::getRangeForEdit(*Range, *Result.Context);
44  // FIXME: let user specify whether to treat this case as an error or ignore
45  // it as is currently done. This behavior is problematic in that it hides
46  // failures from bad ranges. Also, the behavior here differs from
47  // `flatten`. Here, we abort (without error), whereas flatten, if it hits an
48  // empty list, does not abort. As a result, `editList({A,B})` is not
49  // equivalent to `flatten(edit(A), edit(B))`. The former will abort if `A`
50  // produces a bad range, whereas the latter will simply ignore A.
51  if (!EditRange)
52  return SmallVector<Edit, 0>();
54  T.Kind = E.Kind;
55  T.Range = *EditRange;
56  if (E.Replacement) {
57  auto Replacement = E.Replacement->eval(Result);
58  if (!Replacement)
59  return Replacement.takeError();
60  T.Replacement = std::move(*Replacement);
61  }
62  if (E.Note) {
63  auto Note = E.Note->eval(Result);
64  if (!Note)
65  return Note.takeError();
66  T.Note = std::move(*Note);
67  }
68  if (E.Metadata) {
69  auto Metadata = E.Metadata(Result);
70  if (!Metadata)
71  return Metadata.takeError();
72  T.Metadata = std::move(*Metadata);
73  }
74  Edits.push_back(std::move(T));
75  }
76  return Edits;
77 }
78 
80  return [Edits = std::move(Edits)](const MatchResult &Result) {
81  return translateEdits(Result, Edits);
82  };
83 }
84 
86  return [Edit = std::move(Edit)](const MatchResult &Result) {
87  return translateEdits(Result, {Edit});
88  };
89 }
90 
92  return [Anchor = std::move(Anchor)](const MatchResult &Result)
94  Expected<CharSourceRange> Range = Anchor(Result);
95  if (!Range)
96  return Range.takeError();
97  // In case the range is inside a macro expansion, map the location back to a
98  // "real" source location.
100  Result.SourceManager->getSpellingLoc(Range->getBegin());
101  Edit E;
102  // Implicitly, leave `E.Replacement` as the empty string.
103  E.Kind = EditKind::Range;
105  return SmallVector<Edit, 1>{E};
106  };
107 }
108 
111  if (Generators.size() == 1)
112  return std::move(Generators[0]);
113  return
114  [Gs = std::move(Generators)](
115  const MatchResult &Result) -> llvm::Expected<SmallVector<Edit, 1>> {
116  SmallVector<Edit, 1> AllEdits;
117  for (const auto &G : Gs) {
118  llvm::Expected<SmallVector<Edit, 1>> Edits = G(Result);
119  if (!Edits)
120  return Edits.takeError();
121  AllEdits.append(Edits->begin(), Edits->end());
122  }
123  return AllEdits;
124  };
125 }
126 
128  ASTEdit E;
129  E.TargetRange = std::move(Target);
130  E.Replacement = std::move(Replacement);
131  return E;
132 }
133 
135  ASTEdit E;
136  E.TargetRange = transformer::before(Anchor);
137  E.Note = std::move(Note);
138  return E;
139 }
140 
141 namespace {
142 /// A \c TextGenerator that always returns a fixed string.
143 class SimpleTextGenerator : public MatchComputation<std::string> {
144  std::string S;
145 
146 public:
147  SimpleTextGenerator(std::string S) : S(std::move(S)) {}
148  llvm::Error eval(const ast_matchers::MatchFinder::MatchResult &,
149  std::string *Result) const override {
150  Result->append(S);
151  return llvm::Error::success();
152  }
153  std::string toString() const override {
154  return (llvm::Twine("text(\"") + S + "\")").str();
155  }
156 };
157 } // namespace
158 
160  return std::make_shared<SimpleTextGenerator>(std::move(S));
161 }
162 
164  return change(std::move(S), makeText(""));
165 }
166 
167 static std::string formatHeaderPath(StringRef Header, IncludeFormat Format) {
168  switch (Format) {
170  return Header.str();
172  return ("<" + Header + ">").str();
173  }
174  llvm_unreachable("Unknown transformer::IncludeFormat enum");
175 }
176 
178  IncludeFormat Format) {
179  ASTEdit E;
181  E.TargetRange = Target;
182  E.Replacement = makeText(formatHeaderPath(Header, Format));
183  return E;
184 }
185 
188  return editList(std::move(Edits));
189 }
190 
192  return edit(std::move(Edit));
193 }
194 
196  EditGenerator Edits) {
197  RewriteRule R;
198  R.Cases = {{std::move(M), std::move(Edits)}};
199  return R;
200 }
201 
202 RewriteRule transformer::makeRule(ast_matchers::internal::DynTypedMatcher M,
203  std::initializer_list<ASTEdit> Edits) {
204  return detail::makeRule(std::move(M),
205  detail::makeEditGenerator(std::move(Edits)));
206 }
207 
208 namespace {
209 
210 /// Unconditionally binds the given node set before trying `InnerMatcher` and
211 /// keeps the bound nodes on a successful match.
212 template <typename T>
213 class BindingsMatcher : public ast_matchers::internal::MatcherInterface<T> {
215  const ast_matchers::internal::Matcher<T> InnerMatcher;
216 
217 public:
218  explicit BindingsMatcher(ast_matchers::BoundNodes Nodes,
219  ast_matchers::internal::Matcher<T> InnerMatcher)
220  : Nodes(std::move(Nodes)), InnerMatcher(std::move(InnerMatcher)) {}
221 
222  bool matches(
223  const T &Node, ast_matchers::internal::ASTMatchFinder *Finder,
224  ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override {
225  ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
226  for (const auto &N : Nodes.getMap())
227  Result.setBinding(N.first, N.second);
228  if (InnerMatcher.matches(Node, Finder, &Result)) {
229  *Builder = std::move(Result);
230  return true;
231  }
232  return false;
233  }
234 };
235 
236 /// Matches nodes of type T that have at least one descendant node for which the
237 /// given inner matcher matches. Will match for each descendant node that
238 /// matches. Based on ForEachDescendantMatcher, but takes a dynamic matcher,
239 /// instead of a static one, because it is used by RewriteRule, which carries
240 /// (only top-level) dynamic matchers.
241 template <typename T>
242 class DynamicForEachDescendantMatcher
243  : public ast_matchers::internal::MatcherInterface<T> {
244  const DynTypedMatcher DescendantMatcher;
245 
246 public:
247  explicit DynamicForEachDescendantMatcher(DynTypedMatcher DescendantMatcher)
248  : DescendantMatcher(std::move(DescendantMatcher)) {}
249 
250  bool matches(
251  const T &Node, ast_matchers::internal::ASTMatchFinder *Finder,
252  ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override {
253  return Finder->matchesDescendantOf(
254  Node, this->DescendantMatcher, Builder,
255  ast_matchers::internal::ASTMatchFinder::BK_All);
256  }
257 };
258 
259 template <typename T>
260 ast_matchers::internal::Matcher<T>
261 forEachDescendantDynamically(ast_matchers::BoundNodes Nodes,
262  DynTypedMatcher M) {
263  return ast_matchers::internal::makeMatcher(new BindingsMatcher<T>(
264  std::move(Nodes),
265  ast_matchers::internal::makeMatcher(
266  new DynamicForEachDescendantMatcher<T>(std::move(M)))));
267 }
268 
269 class ApplyRuleCallback : public MatchFinder::MatchCallback {
270 public:
271  ApplyRuleCallback(RewriteRule Rule) : Rule(std::move(Rule)) {}
272 
273  template <typename T>
274  void registerMatchers(const ast_matchers::BoundNodes &Nodes,
275  MatchFinder *MF) {
276  for (auto &Matcher : transformer::detail::buildMatchers(Rule))
277  MF->addMatcher(forEachDescendantDynamically<T>(Nodes, Matcher), this);
278  }
279 
280  void run(const MatchFinder::MatchResult &Result) override {
281  if (!Edits)
282  return;
283  size_t I = transformer::detail::findSelectedCase(Result, Rule);
284  auto Transformations = Rule.Cases[I].Edits(Result);
285  if (!Transformations) {
286  Edits = Transformations.takeError();
287  return;
288  }
289  Edits->append(Transformations->begin(), Transformations->end());
290  }
291 
292  RewriteRule Rule;
293 
294  // Initialize to a non-error state.
296 };
297 } // namespace
298 
299 template <typename T>
302  const MatchResult &Result) {
303  ApplyRuleCallback Callback(std::move(Rule));
304  MatchFinder Finder;
305  Callback.registerMatchers<T>(Result.Nodes, &Finder);
306  Finder.match(Node, *Result.Context);
307  return std::move(Callback.Edits);
308 }
309 
312  const MatchResult &Result) {
313  return rewriteDescendantsImpl(Node, std::move(Rule), Result);
314 }
315 
318  const MatchResult &Result) {
319  return rewriteDescendantsImpl(Node, std::move(Rule), Result);
320 }
321 
324  const MatchResult &Result) {
325  return rewriteDescendantsImpl(Node, std::move(Rule), Result);
326 }
327 
330  RewriteRule Rule,
331  const MatchResult &Result) {
332  if (const auto *Node = DNode.get<Decl>())
333  return rewriteDescendantsImpl(*Node, std::move(Rule), Result);
334  if (const auto *Node = DNode.get<Stmt>())
335  return rewriteDescendantsImpl(*Node, std::move(Rule), Result);
336  if (const auto *Node = DNode.get<TypeLoc>())
337  return rewriteDescendantsImpl(*Node, std::move(Rule), Result);
338 
339  return llvm::make_error<llvm::StringError>(
340  llvm::errc::invalid_argument,
341  "type unsupported for recursive rewriting, Kind=" +
342  DNode.getNodeKind().asStringRef());
343 }
344 
346  RewriteRule Rule) {
347  return [NodeId = std::move(NodeId),
348  Rule = std::move(Rule)](const MatchResult &Result)
350  const ast_matchers::BoundNodes::IDToNodeMap &NodesMap =
351  Result.Nodes.getMap();
352  auto It = NodesMap.find(NodeId);
353  if (It == NodesMap.end())
354  return llvm::make_error<llvm::StringError>(llvm::errc::invalid_argument,
355  "ID not bound: " + NodeId);
356  return detail::rewriteDescendants(It->second, std::move(Rule), Result);
357  };
358 }
359 
360 void transformer::addInclude(RewriteRuleBase &Rule, StringRef Header,
361  IncludeFormat Format) {
362  for (auto &Case : Rule.Cases)
363  Case.Edits = flatten(std::move(Case.Edits), addInclude(Header, Format));
364 }
365 
366 #ifndef NDEBUG
367 // Filters for supported matcher kinds. FIXME: Explicitly list the allowed kinds
368 // (all node matcher types except for `QualType` and `Type`), rather than just
369 // banning `QualType` and `Type`.
370 static bool hasValidKind(const DynTypedMatcher &M) {
371  return !M.canConvertTo<QualType>();
372 }
373 #endif
374 
375 // Binds each rule's matcher to a unique (and deterministic) tag based on
376 // `TagBase` and the id paired with the case. All of the returned matchers have
377 // their traversal kind explicitly set, either based on a pre-set kind or to the
378 // provided `DefaultTraversalKind`.
379 static std::vector<DynTypedMatcher> taggedMatchers(
380  StringRef TagBase,
381  const SmallVectorImpl<std::pair<size_t, RewriteRule::Case>> &Cases,
382  TraversalKind DefaultTraversalKind) {
383  std::vector<DynTypedMatcher> Matchers;
384  Matchers.reserve(Cases.size());
385  for (const auto &Case : Cases) {
386  std::string Tag = (TagBase + Twine(Case.first)).str();
387  // HACK: Many matchers are not bindable, so ensure that tryBind will work.
388  DynTypedMatcher BoundMatcher(Case.second.Matcher);
389  BoundMatcher.setAllowBind(true);
390  auto M = *BoundMatcher.tryBind(Tag);
391  Matchers.push_back(!M.getTraversalKind()
392  ? M.withTraversalKind(DefaultTraversalKind)
393  : std::move(M));
394  }
395  return Matchers;
396 }
397 
398 // Simply gathers the contents of the various rules into a single rule. The
399 // actual work to combine these into an ordered choice is deferred to matcher
400 // registration.
401 template <>
404  RewriteRule R;
405  for (auto &Rule : Rules)
406  R.Cases.append(Rule.Cases.begin(), Rule.Cases.end());
407  return R;
408 }
409 
410 std::vector<DynTypedMatcher>
412  // Map the cases into buckets of matchers -- one for each "root" AST kind,
413  // which guarantees that they can be combined in a single anyOf matcher. Each
414  // case is paired with an identifying number that is converted to a string id
415  // in `taggedMatchers`.
416  std::map<ASTNodeKind,
418  Buckets;
419  const SmallVectorImpl<RewriteRule::Case> &Cases = Rule.Cases;
420  for (int I = 0, N = Cases.size(); I < N; ++I) {
421  assert(hasValidKind(Cases[I].Matcher) &&
422  "Matcher must be non-(Qual)Type node matcher");
423  Buckets[Cases[I].Matcher.getSupportedKind()].emplace_back(I, Cases[I]);
424  }
425 
426  // Each anyOf explicitly controls the traversal kind. The anyOf itself is set
427  // to `TK_AsIs` to ensure no nodes are skipped, thereby deferring to the kind
428  // of the branches. Then, each branch is either left as is, if the kind is
429  // already set, or explicitly set to `TK_AsIs`. We choose this setting because
430  // it is the default interpretation of matchers.
431  std::vector<DynTypedMatcher> Matchers;
432  for (const auto &Bucket : Buckets) {
433  DynTypedMatcher M = DynTypedMatcher::constructVariadic(
434  DynTypedMatcher::VO_AnyOf, Bucket.first,
435  taggedMatchers("Tag", Bucket.second, TK_AsIs));
436  M.setAllowBind(true);
437  // `tryBind` is guaranteed to succeed, because `AllowBind` was set to true.
438  Matchers.push_back(M.tryBind(RootID)->withTraversalKind(TK_AsIs));
439  }
440  return Matchers;
441 }
442 
444  std::vector<DynTypedMatcher> Ms = buildMatchers(Rule);
445  assert(Ms.size() == 1 && "Cases must have compatible matchers.");
446  return Ms[0];
447 }
448 
450  auto &NodesMap = Result.Nodes.getMap();
451  auto Root = NodesMap.find(RootID);
452  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
454  CharSourceRange::getTokenRange(Root->second.getSourceRange()),
455  *Result.Context);
456  if (RootRange)
457  return RootRange->getBegin();
458  // The match doesn't have a coherent range, so fall back to the expansion
459  // location as the "beginning" of the match.
460  return Result.SourceManager->getExpansionLoc(
461  Root->second.getSourceRange().getBegin());
462 }
463 
464 // Finds the case that was "selected" -- that is, whose matcher triggered the
465 // `MatchResult`.
467  const RewriteRuleBase &Rule) {
468  if (Rule.Cases.size() == 1)
469  return 0;
470 
471  auto &NodesMap = Result.Nodes.getMap();
472  for (size_t i = 0, N = Rule.Cases.size(); i < N; ++i) {
473  std::string Tag = ("Tag" + Twine(i)).str();
474  if (NodesMap.find(Tag) != NodesMap.end())
475  return i;
476  }
477  llvm_unreachable("No tag found for this rule.");
478 }
clang::TraversalKind
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
Definition: ASTTypeTraits.h:38
clang::transformer::RootID
const char RootID[]
Definition: RewriteRule.cpp:33
Nodes
BoundNodesTreeBuilder Nodes
Definition: ASTMatchFinder.cpp:83
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::ast_matchers::MatchFinder
A class to allow finding matches over the Clang AST.
Definition: ASTMatchFinder.h:68
hasValidKind
static bool hasValidKind(const DynTypedMatcher &M)
Definition: RewriteRule.cpp:370
clang::MultiVersionKind::Target
@ Target
RewriteRule.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::transformer::detail::findSelectedCase
size_t findSelectedCase(const ast_matchers::MatchFinder::MatchResult &Result, const RewriteRuleBase &Rule)
Returns the index of the Case of Rule that was selected in the match result.
Definition: RewriteRule.cpp:466
clang::transformer::noopEdit
EditGenerator noopEdit(RangeSelector Anchor)
Generates a single, no-op edit anchored at the start location of the specified range.
Definition: RewriteRule.cpp:91
clang::transformer::run
Stencil run(MatchConsumer< std::string > C)
Wraps a MatchConsumer in a Stencil, so that it can be used in a Stencil.
Definition: Stencil.cpp:484
clang::transformer::EditKind::AddInclude
@ AddInclude
clang::transformer::editList
EditGenerator editList(llvm::SmallVector< ASTEdit, 1 > Edits)
Lifts a list of ASTEdits into an EditGenerator.
Definition: RewriteRule.cpp:79
llvm::Optional
Definition: LLVM.h:40
clang::transformer::ASTEdit::Note
TextGenerator Note
Definition: RewriteRule.h:111
llvm::Expected
Definition: LLVM.h:41
ASTMatchFinder.h
taggedMatchers
static std::vector< DynTypedMatcher > taggedMatchers(StringRef TagBase, const SmallVectorImpl< std::pair< size_t, RewriteRule::Case >> &Cases, TraversalKind DefaultTraversalKind)
Definition: RewriteRule.cpp:379
clang::transformer::ASTEdit
Definition: RewriteRule.h:107
clang::transformer::Edit::Replacement
std::string Replacement
Definition: RewriteRule.h:48
clang::transformer::RangeSelector
MatchConsumer< CharSourceRange > RangeSelector
Definition: RangeSelector.h:27
clang::transformer::edit
EditGenerator edit(ASTEdit E)
Generates a single (specified) edit.
Definition: RewriteRule.cpp:85
clang::DynTypedNode::getNodeKind
ASTNodeKind getNodeKind() const
Definition: ASTTypeTraits.h:280
MatchResult
MatchFinder::MatchResult MatchResult
Definition: RewriteRule.cpp:31
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:265
clang::transformer::change
ASTEdit change(RangeSelector Target, TextGenerator Replacement)
DEPRECATED: use changeTo.
Definition: RewriteRule.h:184
rewriteDescendantsImpl
llvm::Expected< SmallVector< clang::transformer::Edit, 1 > > rewriteDescendantsImpl(const T &Node, RewriteRule Rule, const MatchResult &Result)
Definition: RewriteRule.cpp:301
clang::transformer::Edit::Range
CharSourceRange Range
Definition: RewriteRule.h:47
clang::transformer::detail::buildMatchers
std::vector< ast_matchers::internal::DynTypedMatcher > buildMatchers(const RewriteRuleBase &Rule)
Builds a set of matchers that cover the rule.
Definition: RewriteRule.cpp:411
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:68
clang::transformer::Edit
A concrete description of a source edit, represented by a character range in the source to be replace...
Definition: RewriteRule.h:45
clang::transformer::makeRule
RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M, EditsT &&Edits)
Constructs a simple RewriteRule.
Definition: RewriteRule.h:328
MatchResult
MatchFinder::MatchResult MatchResult
Definition: RangeSelector.cpp:30
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:91
ASTMatchers.h
formatHeaderPath
static std::string formatHeaderPath(StringRef Header, IncludeFormat Format)
Definition: RewriteRule.cpp:167
clang::transformer::flatten
EditGenerator flatten(Ts &&...Edits)
Definition: RewriteRule.h:172
clang::tooling::getRangeForEdit
llvm::Optional< CharSourceRange > getRangeForEdit(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts)
Attempts to resolve the given range to one that can be edited by a rewrite; generally,...
Definition: SourceCode.cpp:82
makeText
static TextGenerator makeText(std::string S)
Definition: RewriteRule.cpp:159
clang::transformer::applyFirst
RewriteRuleWith< MetadataT > applyFirst(ArrayRef< RewriteRuleWith< MetadataT >> Rules)
Applies the first rule whose pattern matches; other rules are ignored.
Definition: RewriteRule.h:414
clang::transformer::Edit::Kind
EditKind Kind
Definition: RewriteRule.h:46
clang::transformer::MatchComputation
A failable computation over nodes bound by AST matchers, with (limited) reflection via the toString m...
Definition: MatchConsumer.h:64
translateEdits
static Expected< SmallVector< transformer::Edit, 1 > > translateEdits(const MatchResult &Result, ArrayRef< ASTEdit > ASTEdits)
Definition: RewriteRule.cpp:36
clang::transformer::note
ASTEdit note(RangeSelector Anchor, TextGenerator Note)
Generates a single, no-op edit with the associated note anchored at the start location of the specifi...
Definition: RewriteRule.cpp:134
clang::transformer::RewriteRuleBase
Description of a source-code transformation.
Definition: RewriteRule.h:282
clang::transformer::RewriteRuleWith< void >
Definition: RewriteRule.h:299
clang::transformer::detail::makeEditGenerator
EditGenerator makeEditGenerator(EditGenerator Edits)
Definition: RewriteRule.h:318
clang::transformer::IncludeFormat
IncludeFormat
Format of the path in an include directive – angle brackets or quotes.
Definition: RewriteRule.h:54
clang::transformer::EditKind::Range
@ Range
clang::transformer::ASTEdit::Replacement
TextGenerator Replacement
Definition: RewriteRule.h:110
clang::transformer::remove
ASTEdit remove(RangeSelector S)
Removes the source selected by S.
Definition: RewriteRule.cpp:163
clang::transformer::detail::buildMatcher
ast_matchers::internal::DynTypedMatcher buildMatcher(const RewriteRuleBase &Rule)
Builds a single matcher for the rule, covering all of the rule's cases.
Definition: RewriteRule.cpp:443
SourceLocation.h
clang::ast_matchers::MatchFinder::addMatcher
void addMatcher(const DeclarationMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.
Definition: ASTMatchFinder.cpp:1563
clang::transformer::addInclude
ASTEdit addInclude(RangeSelector Target, StringRef Header, IncludeFormat Format=IncludeFormat::Quoted)
Adds an include directive for the given header to the file of Target.
Definition: RewriteRule.cpp:177
clang::transformer::ASTEdit::Kind
EditKind Kind
Definition: RewriteRule.h:108
clang::TK_AsIs
@ TK_AsIs
Will traverse all child nodes.
Definition: ASTTypeTraits.h:40
clang::CharSourceRange::getTokenRange
static CharSourceRange getTokenRange(SourceRange R)
Definition: SourceLocation.h:261
SourceCode.h
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::transformer::changeTo
ASTEdit changeTo(RangeSelector Target, TextGenerator Replacement)
Replaces a portion of the source text with Replacement.
Definition: RewriteRule.cpp:127
clang::transformer::rewriteDescendants
EditGenerator rewriteDescendants(std::string NodeId, RewriteRule Rule)
Applies Rule to all descendants of the node bound to NodeId.
Definition: RewriteRule.cpp:345
clang::transformer::TextGenerator
Generator< std::string > TextGenerator
Definition: RewriteRule.h:67
clang::transformer::ASTEdit::TargetRange
RangeSelector TargetRange
Definition: RewriteRule.h:109
ASTTypeTraits.h
clang::threadSafety::sx::matches
bool matches(const til::SExpr *E1, const til::SExpr *E2)
Definition: ThreadSafetyCommon.h:69
clang::ast_matchers::MatchFinder::MatchResult
Contains all information for a given match.
Definition: ASTMatchFinder.h:74
clang::transformer::IncludeFormat::Quoted
@ Quoted
std
Definition: Format.h:4477
clang::ast_matchers::BoundNodes::IDToNodeMap
internal::BoundNodesMap::IDToNodeMap IDToNodeMap
Type of mapping from binding identifiers to bound nodes.
Definition: ASTMatchers.h:121
clang::ASTNodeKind
Kind identifier.
Definition: ASTTypeTraits.h:51
clang
Definition: CalledOnceCheck.h:17
clang::transformer::detail::rewriteDescendants
llvm::Expected< SmallVector< Edit, 1 > > rewriteDescendants(const Decl &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result)
The following overload set is a version of rewriteDescendants that operates directly on the AST,...
Definition: RewriteRule.cpp:311
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::transformer::IncludeFormat::Angled
@ Angled
clang::DynTypedNode::get
const T * get() const
Retrieve the stored node as type T.
Definition: ASTTypeTraits.h:268
clang::ast_matchers::BoundNodes
Maps string IDs to AST nodes matched by parts of a matcher.
Definition: ASTMatchers.h:107
clang::transformer::detail::makeRule
RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M, EditGenerator Edits)
clang::DynTypedNode
A dynamically typed AST node container.
Definition: ASTTypeTraits.h:248
clang::transformer::Edit::Metadata
llvm::Any Metadata
Definition: RewriteRule.h:50
Stmt.h
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::transformer::flattenVector
EditGenerator flattenVector(SmallVector< EditGenerator, 2 > Generators)
Flattens a list of generators into a single generator whose elements are the concatenation of the res...
Definition: RewriteRule.cpp:110
clang::transformer::RewriteRuleBase::Cases
SmallVector< Case, 1 > Cases
Definition: RewriteRule.h:288
clang::transformer::EditGenerator
MatchConsumer< llvm::SmallVector< Edit, 1 > > EditGenerator
Maps a match result to a list of concrete edits (with possible failure).
Definition: RewriteRule.h:63
clang::transformer::before
RangeSelector before(RangeSelector Selector)
Selects the (empty) range [B,B) when Selector selects the range [B,E).
Definition: RangeSelector.cpp:106
clang::transformer::detail::getRuleMatchLoc
SourceLocation getRuleMatchLoc(const ast_matchers::MatchFinder::MatchResult &Result)
Gets the beginning location of the source matched by a rewrite rule.
Definition: RewriteRule.cpp:449
clang::ast_matchers::MatchFinder::MatchCallback
Called when the Match registered for it was successfully found in the AST.
Definition: ASTMatchFinder.h:91
clang::transformer::Edit::Note
std::string Note
Definition: RewriteRule.h:49
clang::ASTNodeKind::asStringRef
StringRef asStringRef() const
String representation of the kind.
Definition: ASTTypeTraits.cpp:87