Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ParentMapContext.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ParentMapContext.cpp - Map of parents using DynTypedNode -*- 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
// Similar to ParentMap.cpp, but generalizes to non-Stmt nodes, which can have
10
// multiple parents.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/ParentMapContext.h"
15
#include "clang/AST/RecursiveASTVisitor.h"
16
#include "clang/AST/Decl.h"
17
#include "clang/AST/Expr.h"
18
#include "clang/AST/TemplateBase.h"
19
20
using namespace clang;
21
22
21.1k
ParentMapContext::ParentMapContext(ASTContext &Ctx) : ASTCtx(Ctx) {}
23
24
21.1k
ParentMapContext::~ParentMapContext() = default;
25
26
71
void ParentMapContext::clear() { Parents.reset(); }
27
28
395k
const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
29
395k
  return traverseIgnored(const_cast<Expr *>(E));
30
395k
}
31
32
440k
Expr *ParentMapContext::traverseIgnored(Expr *E) const {
33
440k
  if (!E)
34
0
    return nullptr;
35
36
440k
  switch (Traversal) {
37
404k
  case TK_AsIs:
38
404k
    return E;
39
35.7k
  case TK_IgnoreUnlessSpelledInSource:
40
35.7k
    return E->IgnoreUnlessSpelledInSource();
41
440k
  }
42
0
  llvm_unreachable("Invalid Traversal type!");
43
0
}
44
45
937k
DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
46
937k
  if (const auto *E = N.get<Expr>()) {
47
395k
    return DynTypedNode::create(*traverseIgnored(E));
48
395k
  }
49
542k
  return N;
50
937k
}
51
52
template <typename T, typename... U>
53
std::tuple<bool, DynTypedNodeList, const T *, const U *...>
54
matchParents(const DynTypedNodeList &NodeList,
55
             ParentMapContext::ParentMap *ParentMap);
56
57
template <typename, typename...> struct MatchParents;
58
59
class ParentMapContext::ParentMap {
60
61
  template <typename, typename...> friend struct ::MatchParents;
62
63
  /// Contains parents of a node.
64
  using ParentVector = llvm::SmallVector<DynTypedNode, 2>;
65
66
  /// Maps from a node to its parents. This is used for nodes that have
67
  /// pointer identity only, which are more common and we can save space by
68
  /// only storing a unique pointer to them.
69
  using ParentMapPointers =
70
      llvm::DenseMap<const void *,
71
                     llvm::PointerUnion<const Decl *, const Stmt *,
72
                                        DynTypedNode *, ParentVector *>>;
73
74
  /// Parent map for nodes without pointer identity. We store a full
75
  /// DynTypedNode for all keys.
76
  using ParentMapOtherNodes =
77
      llvm::DenseMap<DynTypedNode,
78
                     llvm::PointerUnion<const Decl *, const Stmt *,
79
                                        DynTypedNode *, ParentVector *>>;
80
81
  ParentMapPointers PointerParents;
82
  ParentMapOtherNodes OtherParents;
83
  class ASTVisitor;
84
85
  static DynTypedNode
86
23.3k
  getSingleDynTypedNodeFromParentMap(ParentMapPointers::mapped_type U) {
87
23.3k
    if (const auto *D = U.dyn_cast<const Decl *>())
88
11.7k
      return DynTypedNode::create(*D);
89
11.6k
    if (const auto *S = U.dyn_cast<const Stmt *>())
90
8.95k
      return DynTypedNode::create(*S);
91
2.70k
    return *U.get<DynTypedNode *>();
92
11.6k
  }
93
94
  template <typename NodeTy, typename MapTy>
95
  static DynTypedNodeList getDynNodeFromMap(const NodeTy &Node,
96
23.8k
                                                        const MapTy &Map) {
97
23.8k
    auto I = Map.find(Node);
98
23.8k
    if (I == Map.end()) {
99
945
      return llvm::ArrayRef<DynTypedNode>();
100
945
    }
101
22.8k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
106
      return llvm::makeArrayRef(*V);
103
106
    }
104
22.7k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
22.8k
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<void const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(void const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
15.9k
                                                        const MapTy &Map) {
97
15.9k
    auto I = Map.find(Node);
98
15.9k
    if (I == Map.end()) {
99
894
      return llvm::ArrayRef<DynTypedNode>();
100
894
    }
101
15.0k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
91
      return llvm::makeArrayRef(*V);
103
91
    }
104
14.9k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
15.0k
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::Stmt const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Stmt const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
2.09k
                                                        const MapTy &Map) {
97
2.09k
    auto I = Map.find(Node);
98
2.09k
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
2.09k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
4
      return llvm::makeArrayRef(*V);
103
4
    }
104
2.08k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
2.09k
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::DeclStmt const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::DeclStmt const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
62
                                                        const MapTy &Map) {
97
62
    auto I = Map.find(Node);
98
62
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
62
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
62
    return getSingleDynTypedNodeFromParentMap(I->second);
105
62
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::CXXForRangeStmt const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::CXXForRangeStmt const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
6
                                                        const MapTy &Map) {
97
6
    auto I = Map.find(Node);
98
6
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
6
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
6
    return getSingleDynTypedNodeFromParentMap(I->second);
105
6
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::VarDecl const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::VarDecl const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
31
                                                        const MapTy &Map) {
97
31
    auto I = Map.find(Node);
98
31
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
31
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
31
    return getSingleDynTypedNodeFromParentMap(I->second);
105
31
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::CXXMethodDecl const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::CXXMethodDecl const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
6
                                                        const MapTy &Map) {
97
6
    auto I = Map.find(Node);
98
6
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
6
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
6
    return getSingleDynTypedNodeFromParentMap(I->second);
105
6
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::CXXRecordDecl const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::CXXRecordDecl const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
6
                                                        const MapTy &Map) {
97
6
    auto I = Map.find(Node);
98
6
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
6
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
6
    return getSingleDynTypedNodeFromParentMap(I->second);
105
6
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::LambdaExpr const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::LambdaExpr const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
6
                                                        const MapTy &Map) {
97
6
    auto I = Map.find(Node);
98
6
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
6
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
6
    return getSingleDynTypedNodeFromParentMap(I->second);
105
6
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::FunctionTemplateDecl const*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::FunctionTemplateDecl const* const&, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
2
                                                        const MapTy &Map) {
97
2
    auto I = Map.find(Node);
98
2
    if (I == Map.end()) {
99
0
      return llvm::ArrayRef<DynTypedNode>();
100
0
    }
101
2
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
0
      return llvm::makeArrayRef(*V);
103
0
    }
104
2
    return getSingleDynTypedNodeFromParentMap(I->second);
105
2
  }
clang::DynTypedNodeList clang::ParentMapContext::ParentMap::getDynNodeFromMap<clang::DynTypedNode, llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::DynTypedNode const&, llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > const&)
Line
Count
Source
96
5.62k
                                                        const MapTy &Map) {
97
5.62k
    auto I = Map.find(Node);
98
5.62k
    if (I == Map.end()) {
99
51
      return llvm::ArrayRef<DynTypedNode>();
100
51
    }
101
5.57k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
11
      return llvm::makeArrayRef(*V);
103
11
    }
104
5.56k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
5.57k
  }
106
107
public:
108
  ParentMap(ASTContext &Ctx);
109
1.35k
  ~ParentMap() {
110
48.9k
    for (const auto &Entry : PointerParents) {
111
48.9k
      if (Entry.second.is<DynTypedNode *>()) {
112
1.36k
        delete Entry.second.get<DynTypedNode *>();
113
47.6k
      } else if (Entry.second.is<ParentVector *>()) {
114
263
        delete Entry.second.get<ParentVector *>();
115
263
      }
116
48.9k
    }
117
26.7k
    for (const auto &Entry : OtherParents) {
118
26.7k
      if (Entry.second.is<DynTypedNode *>()) {
119
10.2k
        delete Entry.second.get<DynTypedNode *>();
120
16.5k
      } else if (Entry.second.is<ParentVector *>()) {
121
335
        delete Entry.second.get<ParentVector *>();
122
335
      }
123
26.7k
    }
124
1.35k
  }
125
126
21.6k
  DynTypedNodeList getParents(TraversalKind TK, const DynTypedNode &Node) {
127
21.6k
    if (Node.getNodeKind().hasPointerIdentity()) {
128
15.9k
      auto ParentList =
129
15.9k
          getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
130
15.9k
      if (ParentList.size() > 0 && 
TK == TK_IgnoreUnlessSpelledInSource15.0k
) {
131
132
3.73k
        const auto *ChildExpr = Node.get<Expr>();
133
134
3.73k
        {
135
          // Don't match explicit node types because different stdlib
136
          // implementations implement this in different ways and have
137
          // different intermediate nodes.
138
          // Look up 4 levels for a cxxRewrittenBinaryOperator as that is
139
          // enough for the major stdlib implementations.
140
3.73k
          auto RewrittenBinOpParentsList = ParentList;
141
3.73k
          int I = 0;
142
5.82k
          while (ChildExpr && 
RewrittenBinOpParentsList.size() == 13.18k
&&
143
5.82k
                 
I++ < 43.18k
) {
144
3.16k
            const auto *S = RewrittenBinOpParentsList[0].get<Stmt>();
145
3.16k
            if (!S)
146
1.06k
              break;
147
148
2.09k
            const auto *RWBO = dyn_cast<CXXRewrittenBinaryOperator>(S);
149
2.09k
            if (!RWBO) {
150
2.09k
              RewrittenBinOpParentsList = getDynNodeFromMap(S, PointerParents);
151
2.09k
              continue;
152
2.09k
            }
153
4
            if (RWBO->getLHS()->IgnoreUnlessSpelledInSource() != ChildExpr &&
154
4
                
RWBO->getRHS()->IgnoreUnlessSpelledInSource() != ChildExpr2
)
155
0
              break;
156
4
            return DynTypedNode::create(*RWBO);
157
4
          }
158
3.73k
        }
159
160
3.73k
        const auto *ParentExpr = ParentList[0].get<Expr>();
161
3.73k
        if (ParentExpr && 
ChildExpr57
)
162
55
          return AscendIgnoreUnlessSpelledInSource(ParentExpr, ChildExpr);
163
164
3.67k
        {
165
3.67k
          auto AncestorNodes =
166
3.67k
              matchParents<DeclStmt, CXXForRangeStmt>(ParentList, this);
167
3.67k
          if (std::get<bool>(AncestorNodes) &&
168
3.67k
              std::get<const CXXForRangeStmt *>(AncestorNodes)
169
2
                      ->getLoopVarStmt() ==
170
2
                  std::get<const DeclStmt *>(AncestorNodes))
171
2
            return std::get<DynTypedNodeList>(AncestorNodes);
172
3.67k
        }
173
3.67k
        {
174
3.67k
          auto AncestorNodes = matchParents<VarDecl, DeclStmt, CXXForRangeStmt>(
175
3.67k
              ParentList, this);
176
3.67k
          if (std::get<bool>(AncestorNodes) &&
177
3.67k
              std::get<const CXXForRangeStmt *>(AncestorNodes)
178
4
                      ->getRangeStmt() ==
179
4
                  std::get<const DeclStmt *>(AncestorNodes))
180
4
            return std::get<DynTypedNodeList>(AncestorNodes);
181
3.67k
        }
182
3.67k
        {
183
3.67k
          auto AncestorNodes =
184
3.67k
              matchParents<CXXMethodDecl, CXXRecordDecl, LambdaExpr>(ParentList,
185
3.67k
                                                                     this);
186
3.67k
          if (std::get<bool>(AncestorNodes))
187
4
            return std::get<DynTypedNodeList>(AncestorNodes);
188
3.67k
        }
189
3.66k
        {
190
3.66k
          auto AncestorNodes =
191
3.66k
              matchParents<FunctionTemplateDecl, CXXRecordDecl, LambdaExpr>(
192
3.66k
                  ParentList, this);
193
3.66k
          if (std::get<bool>(AncestorNodes))
194
2
            return std::get<DynTypedNodeList>(AncestorNodes);
195
3.66k
        }
196
3.66k
      }
197
15.9k
      return ParentList;
198
15.9k
    }
199
5.62k
    return getDynNodeFromMap(Node, OtherParents);
200
21.6k
  }
201
202
  DynTypedNodeList AscendIgnoreUnlessSpelledInSource(const Expr *E,
203
55
                                                     const Expr *Child) {
204
205
90
    auto ShouldSkip = [](const Expr *E, const Expr *Child) {
206
90
      if (isa<ImplicitCastExpr>(E))
207
41
        return true;
208
209
49
      if (isa<FullExpr>(E))
210
1
        return true;
211
212
48
      if (isa<MaterializeTemporaryExpr>(E))
213
1
        return true;
214
215
47
      if (isa<CXXBindTemporaryExpr>(E))
216
0
        return true;
217
218
47
      if (isa<ParenExpr>(E))
219
2
        return true;
220
221
45
      if (isa<ExprWithCleanups>(E))
222
0
        return true;
223
224
45
      auto SR = Child->getSourceRange();
225
226
45
      if (const auto *C = dyn_cast<CXXFunctionalCastExpr>(E)) {
227
2
        if (C->getSourceRange() == SR)
228
2
          return true;
229
2
      }
230
231
43
      if (const auto *C = dyn_cast<CXXConstructExpr>(E)) {
232
25
        if (C->getSourceRange() == SR || 
C->isElidable()12
)
233
13
          return true;
234
25
      }
235
236
30
      if (const auto *C = dyn_cast<CXXMemberCallExpr>(E)) {
237
2
        if (C->getSourceRange() == SR)
238
2
          return true;
239
2
      }
240
241
28
      if (const auto *C = dyn_cast<MemberExpr>(E)) {
242
2
        if (C->getSourceRange() == SR)
243
2
          return true;
244
2
      }
245
26
      return false;
246
28
    };
247
248
90
    while (ShouldSkip(E, Child)) {
249
64
      auto It = PointerParents.find(E);
250
64
      if (It == PointerParents.end())
251
0
        break;
252
64
      const auto *S = It->second.dyn_cast<const Stmt *>();
253
64
      if (!S) {
254
13
        if (auto *Vec = It->second.dyn_cast<ParentVector *>())
255
4
          return llvm::makeArrayRef(*Vec);
256
9
        return getSingleDynTypedNodeFromParentMap(It->second);
257
13
      }
258
51
      const auto *P = dyn_cast<Expr>(S);
259
51
      if (!P)
260
16
        return DynTypedNode::create(*S);
261
35
      Child = E;
262
35
      E = P;
263
35
    }
264
26
    return DynTypedNode::create(*E);
265
55
  }
266
};
267
268
template <typename Tuple, std::size_t... Is>
269
44
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
44
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
44
}
auto tuple_pop_front_impl<std::__1::tuple<clang::DynTypedNodeList, clang::CXXForRangeStmt const*>, 0ul>(std::__1::tuple<clang::DynTypedNodeList, clang::CXXForRangeStmt const*> const&, std::__1::integer_sequence<unsigned long, 0ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
auto tuple_pop_front_impl<std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXForRangeStmt const*>, 0ul, 1ul>(std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXForRangeStmt const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
auto tuple_pop_front_impl<std::__1::tuple<clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*>, 0ul, 1ul>(std::__1::tuple<clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>)
Line
Count
Source
269
4
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
4
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
4
}
auto tuple_pop_front_impl<std::__1::tuple<bool, clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*>, 0ul, 1ul, 2ul>(std::__1::tuple<bool, clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul, 2ul>)
Line
Count
Source
269
4
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
4
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
4
}
auto tuple_pop_front_impl<std::__1::tuple<clang::DynTypedNodeList, clang::LambdaExpr const*>, 0ul>(std::__1::tuple<clang::DynTypedNodeList, clang::LambdaExpr const*> const&, std::__1::integer_sequence<unsigned long, 0ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
auto tuple_pop_front_impl<std::__1::tuple<bool, clang::DynTypedNodeList, clang::LambdaExpr const*>, 0ul, 1ul>(std::__1::tuple<bool, clang::DynTypedNodeList, clang::LambdaExpr const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
auto tuple_pop_front_impl<std::__1::tuple<clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*>, 0ul, 1ul>(std::__1::tuple<clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
auto tuple_pop_front_impl<std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*>, 0ul, 1ul, 2ul>(std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul, 2ul>)
Line
Count
Source
269
6
auto tuple_pop_front_impl(const Tuple &tuple, std::index_sequence<Is...>) {
270
6
  return std::make_tuple(std::get<1 + Is>(tuple)...);
271
6
}
272
273
44
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
44
  return tuple_pop_front_impl(
275
44
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
44
}
auto tuple_pop_front<std::__1::tuple<clang::DynTypedNodeList, clang::CXXForRangeStmt const*> >(std::__1::tuple<clang::DynTypedNodeList, clang::CXXForRangeStmt const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
auto tuple_pop_front<std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXForRangeStmt const*> >(std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXForRangeStmt const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
auto tuple_pop_front<std::__1::tuple<clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> >(std::__1::tuple<clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> const&)
Line
Count
Source
273
4
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
4
  return tuple_pop_front_impl(
275
4
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
4
}
auto tuple_pop_front<std::__1::tuple<bool, clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> >(std::__1::tuple<bool, clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> const&)
Line
Count
Source
273
4
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
4
  return tuple_pop_front_impl(
275
4
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
4
}
auto tuple_pop_front<std::__1::tuple<clang::DynTypedNodeList, clang::LambdaExpr const*> >(std::__1::tuple<clang::DynTypedNodeList, clang::LambdaExpr const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
auto tuple_pop_front<std::__1::tuple<bool, clang::DynTypedNodeList, clang::LambdaExpr const*> >(std::__1::tuple<bool, clang::DynTypedNodeList, clang::LambdaExpr const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
auto tuple_pop_front<std::__1::tuple<clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> >(std::__1::tuple<clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
auto tuple_pop_front<std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> >(std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXRecordDecl const*, clang::LambdaExpr const*> const&)
Line
Count
Source
273
6
template <typename Tuple> auto tuple_pop_front(const Tuple &tuple) {
274
6
  return tuple_pop_front_impl(
275
6
      tuple, std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
276
6
}
277
278
template <typename T, typename... U> struct MatchParents {
279
  static std::tuple<bool, DynTypedNodeList, const T *, const U *...>
280
  match(const DynTypedNodeList &NodeList,
281
14.7k
        ParentMapContext::ParentMap *ParentMap) {
282
14.7k
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
107
      auto NextParentList =
284
107
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
107
      if (NextParentList.size() == 1) {
286
107
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
107
        if (std::get<bool>(TailTuple)) {
288
22
          return std::tuple_cat(
289
22
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
22
                              TypedNode),
291
22
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
22
        }
293
107
      }
294
107
    }
295
14.7k
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
14.7k
                          std::tuple<const T *, const U *...>());
297
14.7k
  }
MatchParents<clang::DeclStmt, clang::CXXForRangeStmt>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
281
3.70k
        ParentMapContext::ParentMap *ParentMap) {
282
3.70k
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
62
      auto NextParentList =
284
62
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
62
      if (NextParentList.size() == 1) {
286
62
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
62
        if (std::get<bool>(TailTuple)) {
288
6
          return std::tuple_cat(
289
6
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
6
                              TypedNode),
291
6
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
6
        }
293
62
      }
294
62
    }
295
3.70k
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
3.70k
                          std::tuple<const T *, const U *...>());
297
3.70k
  }
MatchParents<clang::VarDecl, clang::DeclStmt, clang::CXXForRangeStmt>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
281
3.67k
        ParentMapContext::ParentMap *ParentMap) {
282
3.67k
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
31
      auto NextParentList =
284
31
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
31
      if (NextParentList.size() == 1) {
286
31
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
31
        if (std::get<bool>(TailTuple)) {
288
4
          return std::tuple_cat(
289
4
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
4
                              TypedNode),
291
4
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
4
        }
293
31
      }
294
31
    }
295
3.67k
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
3.67k
                          std::tuple<const T *, const U *...>());
297
3.67k
  }
MatchParents<clang::CXXMethodDecl, clang::CXXRecordDecl, clang::LambdaExpr>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
281
3.67k
        ParentMapContext::ParentMap *ParentMap) {
282
3.67k
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
6
      auto NextParentList =
284
6
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
6
      if (NextParentList.size() == 1) {
286
6
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
6
        if (std::get<bool>(TailTuple)) {
288
4
          return std::tuple_cat(
289
4
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
4
                              TypedNode),
291
4
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
4
        }
293
6
      }
294
6
    }
295
3.66k
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
3.66k
                          std::tuple<const T *, const U *...>());
297
3.67k
  }
MatchParents<clang::CXXRecordDecl, clang::LambdaExpr>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
281
8
        ParentMapContext::ParentMap *ParentMap) {
282
8
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
6
      auto NextParentList =
284
6
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
6
      if (NextParentList.size() == 1) {
286
6
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
6
        if (std::get<bool>(TailTuple)) {
288
6
          return std::tuple_cat(
289
6
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
6
                              TypedNode),
291
6
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
6
        }
293
6
      }
294
6
    }
295
2
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
2
                          std::tuple<const T *, const U *...>());
297
8
  }
MatchParents<clang::FunctionTemplateDecl, clang::CXXRecordDecl, clang::LambdaExpr>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
281
3.66k
        ParentMapContext::ParentMap *ParentMap) {
282
3.66k
    if (const auto *TypedNode = NodeList[0].get<T>()) {
283
2
      auto NextParentList =
284
2
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
285
2
      if (NextParentList.size() == 1) {
286
2
        auto TailTuple = MatchParents<U...>::match(NextParentList, ParentMap);
287
2
        if (std::get<bool>(TailTuple)) {
288
2
          return std::tuple_cat(
289
2
              std::make_tuple(true, std::get<DynTypedNodeList>(TailTuple),
290
2
                              TypedNode),
291
2
              tuple_pop_front(tuple_pop_front(TailTuple)));
292
2
        }
293
2
      }
294
2
    }
295
3.66k
    return std::tuple_cat(std::make_tuple(false, NodeList),
296
3.66k
                          std::tuple<const T *, const U *...>());
297
3.66k
  }
298
};
299
300
template <typename T> struct MatchParents<T> {
301
  static std::tuple<bool, DynTypedNodeList, const T *>
302
  match(const DynTypedNodeList &NodeList,
303
68
        ParentMapContext::ParentMap *ParentMap) {
304
68
    if (const auto *TypedNode = NodeList[0].get<T>()) {
305
12
      auto NextParentList =
306
12
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
307
12
      if (NextParentList.size() == 1)
308
12
        return std::make_tuple(true, NodeList, TypedNode);
309
12
    }
310
56
    return std::make_tuple(false, NodeList, nullptr);
311
68
  }
MatchParents<clang::CXXForRangeStmt>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
303
62
        ParentMapContext::ParentMap *ParentMap) {
304
62
    if (const auto *TypedNode = NodeList[0].get<T>()) {
305
6
      auto NextParentList =
306
6
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
307
6
      if (NextParentList.size() == 1)
308
6
        return std::make_tuple(true, NodeList, TypedNode);
309
6
    }
310
56
    return std::make_tuple(false, NodeList, nullptr);
311
62
  }
MatchParents<clang::LambdaExpr>::match(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
303
6
        ParentMapContext::ParentMap *ParentMap) {
304
6
    if (const auto *TypedNode = NodeList[0].get<T>()) {
305
6
      auto NextParentList =
306
6
          ParentMap->getDynNodeFromMap(TypedNode, ParentMap->PointerParents);
307
6
      if (NextParentList.size() == 1)
308
6
        return std::make_tuple(true, NodeList, TypedNode);
309
6
    }
310
0
    return std::make_tuple(false, NodeList, nullptr);
311
6
  }
312
};
313
314
template <typename T, typename... U>
315
std::tuple<bool, DynTypedNodeList, const T *, const U *...>
316
matchParents(const DynTypedNodeList &NodeList,
317
14.6k
             ParentMapContext::ParentMap *ParentMap) {
318
14.6k
  return MatchParents<T, U...>::match(NodeList, ParentMap);
319
14.6k
}
std::__1::tuple<bool, clang::DynTypedNodeList, clang::DeclStmt const*, clang::CXXForRangeStmt const*> matchParents<clang::DeclStmt, clang::CXXForRangeStmt>(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
317
3.67k
             ParentMapContext::ParentMap *ParentMap) {
318
3.67k
  return MatchParents<T, U...>::match(NodeList, ParentMap);
319
3.67k
}
std::__1::tuple<bool, clang::DynTypedNodeList, clang::VarDecl const*, clang::DeclStmt const*, clang::CXXForRangeStmt const*> matchParents<clang::VarDecl, clang::DeclStmt, clang::CXXForRangeStmt>(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
317
3.67k
             ParentMapContext::ParentMap *ParentMap) {
318
3.67k
  return MatchParents<T, U...>::match(NodeList, ParentMap);
319
3.67k
}
std::__1::tuple<bool, clang::DynTypedNodeList, clang::CXXMethodDecl const*, clang::CXXRecordDecl const*, clang::LambdaExpr const*> matchParents<clang::CXXMethodDecl, clang::CXXRecordDecl, clang::LambdaExpr>(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
317
3.67k
             ParentMapContext::ParentMap *ParentMap) {
318
3.67k
  return MatchParents<T, U...>::match(NodeList, ParentMap);
319
3.67k
}
std::__1::tuple<bool, clang::DynTypedNodeList, clang::FunctionTemplateDecl const*, clang::CXXRecordDecl const*, clang::LambdaExpr const*> matchParents<clang::FunctionTemplateDecl, clang::CXXRecordDecl, clang::LambdaExpr>(clang::DynTypedNodeList const&, clang::ParentMapContext::ParentMap*)
Line
Count
Source
317
3.66k
             ParentMapContext::ParentMap *ParentMap) {
318
3.66k
  return MatchParents<T, U...>::match(NodeList, ParentMap);
319
3.66k
}
320
321
/// Template specializations to abstract away from pointers and TypeLocs.
322
/// @{
323
31.5k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
31.5k
  return DynTypedNode::create(*Node);
325
31.5k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Decl*>(clang::Decl* const&)
Line
Count
Source
323
31.0k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
31.0k
  return DynTypedNode::create(*Node);
325
31.0k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Attr*>(clang::Attr* const&)
Line
Count
Source
323
475
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
475
  return DynTypedNode::create(*Node);
325
475
}
326
26.3k
template <> DynTypedNode createDynTypedNode(const TypeLoc &Node) {
327
26.3k
  return DynTypedNode::create(Node);
328
26.3k
}
329
template <>
330
862
DynTypedNode createDynTypedNode(const NestedNameSpecifierLoc &Node) {
331
862
  return DynTypedNode::create(Node);
332
862
}
333
/// @}
334
335
/// A \c RecursiveASTVisitor that builds a map from nodes to their
336
/// parents as defined by the \c RecursiveASTVisitor.
337
///
338
/// Note that the relationship described here is purely in terms of AST
339
/// traversal - there are other relationships (for example declaration context)
340
/// in the AST that are better modeled by special matchers.
341
class ParentMapContext::ParentMap::ASTVisitor
342
    : public RecursiveASTVisitor<ASTVisitor> {
343
public:
344
1.35k
  ASTVisitor(ParentMap &Map) : Map(Map) {}
345
346
private:
347
  friend class RecursiveASTVisitor<ASTVisitor>;
348
349
  using VisitorBase = RecursiveASTVisitor<ASTVisitor>;
350
351
1.11k
  bool shouldVisitTemplateInstantiations() const { return true; }
352
353
37.1k
  bool shouldVisitImplicitCode() const { return true; }
354
355
  /// Record the parent of the node we're visiting.
356
  /// MapNode is the child, the parent is on top of ParentStack.
357
  /// Parents is the parent storage (either PointerParents or OtherParents).
358
  template <typename MapNodeTy, typename MapTy>
359
77.9k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
77.9k
    if (ParentStack.empty())
361
1.35k
      return;
362
363
    // FIXME: Currently we add the same parent multiple times, but only
364
    // when no memoization data is available for the type.
365
    // For example when we visit all subexpressions of template
366
    // instantiations; this is suboptimal, but benign: the only way to
367
    // visit those is with hasAncestor / hasParent, and those do not create
368
    // new matches.
369
    // The plan is to enable DynTypedNode to be storable in a map or hash
370
    // map. The main problem there is to implement hash functions /
371
    // comparison operators for all types that DynTypedNode supports that
372
    // do not have pointer identity.
373
76.5k
    auto &NodeOrVector = (*Parents)[MapNode];
374
76.5k
    if (NodeOrVector.isNull()) {
375
75.7k
      if (const auto *D = ParentStack.back().get<Decl>())
376
47.3k
        NodeOrVector = D;
377
28.3k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
16.6k
        NodeOrVector = S;
379
11.7k
      else
380
11.7k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
75.7k
    } else {
382
843
      if (!NodeOrVector.template is<ParentVector *>()) {
383
598
        auto *Vector = new ParentVector(
384
598
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
598
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
598
        NodeOrVector = Vector;
387
598
      }
388
389
843
      auto *Vector = NodeOrVector.template get<ParentVector *>();
390
      // Skip duplicates for types that have memoization data.
391
      // We must check that the type has memoization data before calling
392
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
393
      // types.
394
843
      bool Found = ParentStack.back().getMemoizationData() &&
395
843
                   
llvm::is_contained(*Vector, ParentStack.back())574
;
396
843
      if (!Found)
397
605
        Vector->push_back(ParentStack.back());
398
843
    }
399
76.5k
  }
void clang::ParentMapContext::ParentMap::ASTVisitor::addParent<clang::Decl*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Decl*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
31.0k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
31.0k
    if (ParentStack.empty())
361
1.35k
      return;
362
363
    // FIXME: Currently we add the same parent multiple times, but only
364
    // when no memoization data is available for the type.
365
    // For example when we visit all subexpressions of template
366
    // instantiations; this is suboptimal, but benign: the only way to
367
    // visit those is with hasAncestor / hasParent, and those do not create
368
    // new matches.
369
    // The plan is to enable DynTypedNode to be storable in a map or hash
370
    // map. The main problem there is to implement hash functions /
371
    // comparison operators for all types that DynTypedNode supports that
372
    // do not have pointer identity.
373
29.7k
    auto &NodeOrVector = (*Parents)[MapNode];
374
29.7k
    if (NodeOrVector.isNull()) {
375
29.5k
      if (const auto *D = ParentStack.back().get<Decl>())
376
25.9k
        NodeOrVector = D;
377
3.57k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
2.22k
        NodeOrVector = S;
379
1.34k
      else
380
1.34k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
29.5k
    } else {
382
205
      if (!NodeOrVector.template is<ParentVector *>()) {
383
83
        auto *Vector = new ParentVector(
384
83
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
83
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
83
        NodeOrVector = Vector;
387
83
      }
388
389
205
      auto *Vector = NodeOrVector.template get<ParentVector *>();
390
      // Skip duplicates for types that have memoization data.
391
      // We must check that the type has memoization data before calling
392
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
393
      // types.
394
205
      bool Found = ParentStack.back().getMemoizationData() &&
395
205
                   
llvm::is_contained(*Vector, ParentStack.back())57
;
396
205
      if (!Found)
397
205
        Vector->push_back(ParentStack.back());
398
205
    }
399
29.7k
  }
void clang::ParentMapContext::ParentMap::ASTVisitor::addParent<clang::DynTypedNode, llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::DynTypedNode, llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
27.1k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
27.1k
    if (ParentStack.empty())
361
0
      return;
362
363
    // FIXME: Currently we add the same parent multiple times, but only
364
    // when no memoization data is available for the type.
365
    // For example when we visit all subexpressions of template
366
    // instantiations; this is suboptimal, but benign: the only way to
367
    // visit those is with hasAncestor / hasParent, and those do not create
368
    // new matches.
369
    // The plan is to enable DynTypedNode to be storable in a map or hash
370
    // map. The main problem there is to implement hash functions /
371
    // comparison operators for all types that DynTypedNode supports that
372
    // do not have pointer identity.
373
27.1k
    auto &NodeOrVector = (*Parents)[MapNode];
374
27.1k
    if (NodeOrVector.isNull()) {
375
26.7k
      if (const auto *D = ParentStack.back().get<Decl>())
376
15.7k
        NodeOrVector = D;
377
10.9k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
666
        NodeOrVector = S;
379
10.3k
      else
380
10.3k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
26.7k
    } else {
382
449
      if (!NodeOrVector.template is<ParentVector *>()) {
383
335
        auto *Vector = new ParentVector(
384
335
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
335
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
335
        NodeOrVector = Vector;
387
335
      }
388
389
449
      auto *Vector = NodeOrVector.template get<ParentVector *>();
390
      // Skip duplicates for types that have memoization data.
391
      // We must check that the type has memoization data before calling
392
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
393
      // types.
394
449
      bool Found = ParentStack.back().getMemoizationData() &&
395
449
                   
llvm::is_contained(*Vector, ParentStack.back())328
;
396
449
      if (!Found)
397
300
        Vector->push_back(ParentStack.back());
398
449
    }
399
27.1k
  }
void clang::ParentMapContext::ParentMap::ASTVisitor::addParent<clang::Stmt*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Stmt*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
19.1k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
19.1k
    if (ParentStack.empty())
361
0
      return;
362
363
    // FIXME: Currently we add the same parent multiple times, but only
364
    // when no memoization data is available for the type.
365
    // For example when we visit all subexpressions of template
366
    // instantiations; this is suboptimal, but benign: the only way to
367
    // visit those is with hasAncestor / hasParent, and those do not create
368
    // new matches.
369
    // The plan is to enable DynTypedNode to be storable in a map or hash
370
    // map. The main problem there is to implement hash functions /
371
    // comparison operators for all types that DynTypedNode supports that
372
    // do not have pointer identity.
373
19.1k
    auto &NodeOrVector = (*Parents)[MapNode];
374
19.1k
    if (NodeOrVector.isNull()) {
375
18.9k
      if (const auto *D = ParentStack.back().get<Decl>())
376
5.16k
        NodeOrVector = D;
377
13.8k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
13.7k
        NodeOrVector = S;
379
69
      else
380
69
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
18.9k
    } else {
382
189
      if (!NodeOrVector.template is<ParentVector *>()) {
383
180
        auto *Vector = new ParentVector(
384
180
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
180
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
180
        NodeOrVector = Vector;
387
180
      }
388
389
189
      auto *Vector = NodeOrVector.template get<ParentVector *>();
390
      // Skip duplicates for types that have memoization data.
391
      // We must check that the type has memoization data before calling
392
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
393
      // types.
394
189
      bool Found = ParentStack.back().getMemoizationData() &&
395
189
                   llvm::is_contained(*Vector, ParentStack.back());
396
189
      if (!Found)
397
100
        Vector->push_back(ParentStack.back());
398
189
    }
399
19.1k
  }
void clang::ParentMapContext::ParentMap::ASTVisitor::addParent<clang::Attr*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Attr*, llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
475
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
475
    if (ParentStack.empty())
361
0
      return;
362
363
    // FIXME: Currently we add the same parent multiple times, but only
364
    // when no memoization data is available for the type.
365
    // For example when we visit all subexpressions of template
366
    // instantiations; this is suboptimal, but benign: the only way to
367
    // visit those is with hasAncestor / hasParent, and those do not create
368
    // new matches.
369
    // The plan is to enable DynTypedNode to be storable in a map or hash
370
    // map. The main problem there is to implement hash functions /
371
    // comparison operators for all types that DynTypedNode supports that
372
    // do not have pointer identity.
373
475
    auto &NodeOrVector = (*Parents)[MapNode];
374
475
    if (NodeOrVector.isNull()) {
375
475
      if (const auto *D = ParentStack.back().get<Decl>())
376
475
        NodeOrVector = D;
377
0
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
0
        NodeOrVector = S;
379
0
      else
380
0
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
475
    } else {
382
0
      if (!NodeOrVector.template is<ParentVector *>()) {
383
0
        auto *Vector = new ParentVector(
384
0
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
0
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
0
        NodeOrVector = Vector;
387
0
      }
388
389
0
      auto *Vector = NodeOrVector.template get<ParentVector *>();
390
      // Skip duplicates for types that have memoization data.
391
      // We must check that the type has memoization data before calling
392
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
393
      // types.
394
0
      bool Found = ParentStack.back().getMemoizationData() &&
395
0
                   llvm::is_contained(*Vector, ParentStack.back());
396
0
      if (!Found)
397
0
        Vector->push_back(ParentStack.back());
398
0
    }
399
475
  }
400
401
  template <typename T, typename MapNodeTy, typename BaseTraverseFn,
402
            typename MapTy>
403
  bool TraverseNode(T Node, MapNodeTy MapNode, BaseTraverseFn BaseTraverse,
404
81.6k
                    MapTy *Parents) {
405
81.6k
    if (!Node)
406
22.8k
      return true;
407
58.7k
    addParent(MapNode, Parents);
408
58.7k
    ParentStack.push_back(createDynTypedNode(Node));
409
58.7k
    bool Result = BaseTraverse();
410
58.7k
    ParentStack.pop_back();
411
58.7k
    return Result;
412
81.6k
  }
bool clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNode<clang::Decl*, clang::Decl*, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseDecl(clang::Decl*)::'lambda'(), llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Decl*, clang::Decl*, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseDecl(clang::Decl*)::'lambda'(), llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
404
31.0k
                    MapTy *Parents) {
405
31.0k
    if (!Node)
406
0
      return true;
407
31.0k
    addParent(MapNode, Parents);
408
31.0k
    ParentStack.push_back(createDynTypedNode(Node));
409
31.0k
    bool Result = BaseTraverse();
410
31.0k
    ParentStack.pop_back();
411
31.0k
    return Result;
412
31.0k
  }
bool clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNode<clang::NestedNameSpecifierLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc)::'lambda'(), llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::NestedNameSpecifierLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc)::'lambda'(), llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
404
23.7k
                    MapTy *Parents) {
405
23.7k
    if (!Node)
406
22.8k
      return true;
407
862
    addParent(MapNode, Parents);
408
862
    ParentStack.push_back(createDynTypedNode(Node));
409
862
    bool Result = BaseTraverse();
410
862
    ParentStack.pop_back();
411
862
    return Result;
412
23.7k
  }
bool clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNode<clang::TypeLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseTypeLoc(clang::TypeLoc)::'lambda'(), llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::TypeLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseTypeLoc(clang::TypeLoc)::'lambda'(), llvm::DenseMap<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<clang::DynTypedNode, void>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
404
26.3k
                    MapTy *Parents) {
405
26.3k
    if (!Node)
406
0
      return true;
407
26.3k
    addParent(MapNode, Parents);
408
26.3k
    ParentStack.push_back(createDynTypedNode(Node));
409
26.3k
    bool Result = BaseTraverse();
410
26.3k
    ParentStack.pop_back();
411
26.3k
    return Result;
412
26.3k
  }
bool clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNode<clang::Attr*, clang::Attr*, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseAttr(clang::Attr*)::'lambda'(), llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > > >(clang::Attr*, clang::Attr*, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseAttr(clang::Attr*)::'lambda'(), llvm::DenseMap<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*>, llvm::DenseMapInfo<void const*, void>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
404
475
                    MapTy *Parents) {
405
475
    if (!Node)
406
0
      return true;
407
475
    addParent(MapNode, Parents);
408
475
    ParentStack.push_back(createDynTypedNode(Node));
409
475
    bool Result = BaseTraverse();
410
475
    ParentStack.pop_back();
411
475
    return Result;
412
475
  }
413
414
31.0k
  bool TraverseDecl(Decl *DeclNode) {
415
31.0k
    return TraverseNode(
416
31.0k
        DeclNode, DeclNode, [&] { return VisitorBase::TraverseDecl(DeclNode); },
417
31.0k
        &Map.PointerParents);
418
31.0k
  }
419
26.3k
  bool TraverseTypeLoc(TypeLoc TypeLocNode) {
420
26.3k
    return TraverseNode(
421
26.3k
        TypeLocNode, DynTypedNode::create(TypeLocNode),
422
26.3k
        [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); },
423
26.3k
        &Map.OtherParents);
424
26.3k
  }
425
23.7k
  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLocNode) {
426
23.7k
    return TraverseNode(
427
23.7k
        NNSLocNode, DynTypedNode::create(NNSLocNode),
428
23.7k
        [&] 
{ return VisitorBase::TraverseNestedNameSpecifierLoc(NNSLocNode); }862
,
429
23.7k
        &Map.OtherParents);
430
23.7k
  }
431
475
  bool TraverseAttr(Attr *AttrNode) {
432
475
    return TraverseNode(
433
475
        AttrNode, AttrNode, [&] { return VisitorBase::TraverseAttr(AttrNode); },
434
475
        &Map.PointerParents);
435
475
  }
436
437
  // Using generic TraverseNode for Stmt would prevent data-recursion.
438
19.1k
  bool dataTraverseStmtPre(Stmt *StmtNode) {
439
19.1k
    addParent(StmtNode, &Map.PointerParents);
440
19.1k
    ParentStack.push_back(DynTypedNode::create(*StmtNode));
441
19.1k
    return true;
442
19.1k
  }
443
19.1k
  bool dataTraverseStmtPost(Stmt *StmtNode) {
444
19.1k
    ParentStack.pop_back();
445
19.1k
    return true;
446
19.1k
  }
447
448
  ParentMap &Map;
449
  llvm::SmallVector<DynTypedNode, 16> ParentStack;
450
};
451
452
1.35k
ParentMapContext::ParentMap::ParentMap(ASTContext &Ctx) {
453
1.35k
  ASTVisitor(*this).TraverseAST(Ctx);
454
1.35k
}
455
456
21.6k
DynTypedNodeList ParentMapContext::getParents(const DynTypedNode &Node) {
457
21.6k
  if (!Parents)
458
    // We build the parent map for the traversal scope (usually whole TU), as
459
    // hasAncestor can escape any subtree.
460
1.35k
    Parents = std::make_unique<ParentMap>(ASTCtx);
461
21.6k
  return Parents->getParents(getTraversalKind(), Node);
462
21.6k
}