Coverage Report

Created: 2021-09-21 08:58

/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
20.1k
ParentMapContext::ParentMapContext(ASTContext &Ctx) : ASTCtx(Ctx) {}
23
24
20.1k
ParentMapContext::~ParentMapContext() = default;
25
26
71
void ParentMapContext::clear() { Parents.reset(); }
27
28
391k
const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
29
391k
  return traverseIgnored(const_cast<Expr *>(E));
30
391k
}
31
32
434k
Expr *ParentMapContext::traverseIgnored(Expr *E) const {
33
434k
  if (!E)
34
0
    return nullptr;
35
36
434k
  switch (Traversal) {
37
399k
  case TK_AsIs:
38
399k
    return E;
39
35.7k
  case TK_IgnoreUnlessSpelledInSource:
40
35.7k
    return E->IgnoreUnlessSpelledInSource();
41
434k
  }
42
0
  llvm_unreachable("Invalid Traversal type!");
43
0
}
44
45
904k
DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
46
904k
  if (const auto *E = N.get<Expr>()) {
47
391k
    return DynTypedNode::create(*traverseIgnored(E));
48
391k
  }
49
513k
  return N;
50
904k
}
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
20.0k
  getSingleDynTypedNodeFromParentMap(ParentMapPointers::mapped_type U) {
87
20.0k
    if (const auto *D = U.dyn_cast<const Decl *>())
88
9.00k
      return DynTypedNode::create(*D);
89
11.0k
    if (const auto *S = U.dyn_cast<const Stmt *>())
90
8.32k
      return DynTypedNode::create(*S);
91
2.70k
    return *U.get<DynTypedNode *>();
92
11.0k
  }
93
94
  template <typename NodeTy, typename MapTy>
95
  static DynTypedNodeList getDynNodeFromMap(const NodeTy &Node,
96
20.4k
                                                        const MapTy &Map) {
97
20.4k
    auto I = Map.find(Node);
98
20.4k
    if (I == Map.end()) {
99
945
      return llvm::ArrayRef<DynTypedNode>();
100
945
    }
101
19.5k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
106
      return llvm::makeArrayRef(*V);
103
106
    }
104
19.4k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
19.5k
  }
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*>, 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*>, 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
12.6k
                                                        const MapTy &Map) {
97
12.6k
    auto I = Map.find(Node);
98
12.6k
    if (I == Map.end()) {
99
894
      return llvm::ArrayRef<DynTypedNode>();
100
894
    }
101
11.7k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
91
      return llvm::makeArrayRef(*V);
103
91
    }
104
11.6k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
11.7k
  }
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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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*>, 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>, 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>, 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.26k
  ~ParentMap() {
110
46.3k
    for (const auto &Entry : PointerParents) {
111
46.3k
      if (Entry.second.is<DynTypedNode *>()) {
112
1.29k
        delete Entry.second.get<DynTypedNode *>();
113
45.0k
      } else if (Entry.second.is<ParentVector *>()) {
114
263
        delete Entry.second.get<ParentVector *>();
115
263
      }
116
46.3k
    }
117
25.3k
    for (const auto &Entry : OtherParents) {
118
25.3k
      if (Entry.second.is<DynTypedNode *>()) {
119
9.80k
        delete Entry.second.get<DynTypedNode *>();
120
15.5k
      } else if (Entry.second.is<ParentVector *>()) {
121
334
        delete Entry.second.get<ParentVector *>();
122
334
      }
123
25.3k
    }
124
1.26k
  }
125
126
18.2k
  DynTypedNodeList getParents(TraversalKind TK, const DynTypedNode &Node) {
127
18.2k
    if (Node.getNodeKind().hasPointerIdentity()) {
128
12.6k
      auto ParentList =
129
12.6k
          getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
130
12.6k
      if (ParentList.size() > 0 && 
TK == TK_IgnoreUnlessSpelledInSource11.7k
) {
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
12.5k
      return ParentList;
198
12.6k
    }
199
5.62k
    return getDynNodeFromMap(Node, OtherParents);
200
18.2k
  }
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
29.4k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
29.4k
  return DynTypedNode::create(*Node);
325
29.4k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Decl*>(clang::Decl* const&)
Line
Count
Source
323
29.0k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
29.0k
  return DynTypedNode::create(*Node);
325
29.0k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Attr*>(clang::Attr* const&)
Line
Count
Source
323
437
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
437
  return DynTypedNode::create(*Node);
325
437
}
326
24.9k
template <> DynTypedNode createDynTypedNode(const TypeLoc &Node) {
327
24.9k
  return DynTypedNode::create(Node);
328
24.9k
}
329
template <>
330
798
DynTypedNode createDynTypedNode(const NestedNameSpecifierLoc &Node) {
331
798
  return DynTypedNode::create(Node);
332
798
}
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.26k
  ASTVisitor(ParentMap &Map) : Map(Map) {}
345
346
private:
347
  friend class RecursiveASTVisitor<ASTVisitor>;
348
349
  using VisitorBase = RecursiveASTVisitor<ASTVisitor>;
350
351
1.10k
  bool shouldVisitTemplateInstantiations() const { return true; }
352
353
34.3k
  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
73.7k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
73.7k
    if (ParentStack.empty())
361
1.26k
      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
72.5k
    auto &NodeOrVector = (*Parents)[MapNode];
374
72.5k
    if (NodeOrVector.isNull()) {
375
71.6k
      if (const auto *D = ParentStack.back().get<Decl>())
376
44.3k
        NodeOrVector = D;
377
27.2k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
16.0k
        NodeOrVector = S;
379
11.2k
      else
380
11.2k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
71.6k
    } else {
382
842
      if (!NodeOrVector.template is<ParentVector *>()) {
383
597
        auto *Vector = new ParentVector(
384
597
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
597
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
597
        NodeOrVector = Vector;
387
597
      }
388
389
842
      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
      // std::find() because DynTypedNode::operator== can't compare all
393
      // types.
394
842
      bool Found = ParentStack.back().getMemoizationData() &&
395
842
                   std::find(Vector->begin(), Vector->end(),
396
574
                             ParentStack.back()) != Vector->end();
397
842
      if (!Found)
398
604
        Vector->push_back(ParentStack.back());
399
842
    }
400
72.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*>, 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*>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
29.0k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
29.0k
    if (ParentStack.empty())
361
1.26k
      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.7k
    auto &NodeOrVector = (*Parents)[MapNode];
374
27.7k
    if (NodeOrVector.isNull()) {
375
27.5k
      if (const auto *D = ParentStack.back().get<Decl>())
376
24.1k
        NodeOrVector = D;
377
3.41k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
2.13k
        NodeOrVector = S;
379
1.27k
      else
380
1.27k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
27.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
      // std::find() because DynTypedNode::operator== can't compare all
393
      // types.
394
205
      bool Found = ParentStack.back().getMemoizationData() &&
395
205
                   std::find(Vector->begin(), Vector->end(),
396
57
                             ParentStack.back()) != Vector->end();
397
205
      if (!Found)
398
205
        Vector->push_back(ParentStack.back());
399
205
    }
400
27.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>, 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>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
25.7k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
25.7k
    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
25.7k
    auto &NodeOrVector = (*Parents)[MapNode];
374
25.7k
    if (NodeOrVector.isNull()) {
375
25.3k
      if (const auto *D = ParentStack.back().get<Decl>())
376
14.7k
        NodeOrVector = D;
377
10.5k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
631
        NodeOrVector = S;
379
9.91k
      else
380
9.91k
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
25.3k
    } else {
382
448
      if (!NodeOrVector.template is<ParentVector *>()) {
383
334
        auto *Vector = new ParentVector(
384
334
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
385
334
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
386
334
        NodeOrVector = Vector;
387
334
      }
388
389
448
      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
      // std::find() because DynTypedNode::operator== can't compare all
393
      // types.
394
448
      bool Found = ParentStack.back().getMemoizationData() &&
395
448
                   std::find(Vector->begin(), Vector->end(),
396
328
                             ParentStack.back()) != Vector->end();
397
448
      if (!Found)
398
299
        Vector->push_back(ParentStack.back());
399
448
    }
400
25.7k
  }
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*>, 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*>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
18.5k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
18.5k
    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
18.5k
    auto &NodeOrVector = (*Parents)[MapNode];
374
18.5k
    if (NodeOrVector.isNull()) {
375
18.3k
      if (const auto *D = ParentStack.back().get<Decl>())
376
5.02k
        NodeOrVector = D;
377
13.3k
      else if (const auto *S = ParentStack.back().get<Stmt>())
378
13.2k
        NodeOrVector = S;
379
69
      else
380
69
        NodeOrVector = new DynTypedNode(ParentStack.back());
381
18.3k
    } 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
      // std::find() because DynTypedNode::operator== can't compare all
393
      // types.
394
189
      bool Found = ParentStack.back().getMemoizationData() &&
395
189
                   std::find(Vector->begin(), Vector->end(),
396
189
                             ParentStack.back()) != Vector->end();
397
189
      if (!Found)
398
100
        Vector->push_back(ParentStack.back());
399
189
    }
400
18.5k
  }
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*>, 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*>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
359
437
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
360
437
    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
437
    auto &NodeOrVector = (*Parents)[MapNode];
374
437
    if (NodeOrVector.isNull()) {
375
437
      if (const auto *D = ParentStack.back().get<Decl>())
376
437
        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
437
    } 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
      // std::find() because DynTypedNode::operator== can't compare all
393
      // types.
394
0
      bool Found = ParentStack.back().getMemoizationData() &&
395
0
                   std::find(Vector->begin(), Vector->end(),
396
0
                             ParentStack.back()) != Vector->end();
397
0
      if (!Found)
398
0
        Vector->push_back(ParentStack.back());
399
0
    }
400
437
  }
401
402
  template <typename T, typename MapNodeTy, typename BaseTraverseFn,
403
            typename MapTy>
404
  bool TraverseNode(T Node, MapNodeTy MapNode, BaseTraverseFn BaseTraverse,
405
76.8k
                    MapTy *Parents) {
406
76.8k
    if (!Node)
407
21.5k
      return true;
408
55.2k
    addParent(MapNode, Parents);
409
55.2k
    ParentStack.push_back(createDynTypedNode(Node));
410
55.2k
    bool Result = BaseTraverse();
411
55.2k
    ParentStack.pop_back();
412
55.2k
    return Result;
413
76.8k
  }
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*>, 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*>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
405
29.0k
                    MapTy *Parents) {
406
29.0k
    if (!Node)
407
0
      return true;
408
29.0k
    addParent(MapNode, Parents);
409
29.0k
    ParentStack.push_back(createDynTypedNode(Node));
410
29.0k
    bool Result = BaseTraverse();
411
29.0k
    ParentStack.pop_back();
412
29.0k
    return Result;
413
29.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>, 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>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
405
22.3k
                    MapTy *Parents) {
406
22.3k
    if (!Node)
407
21.5k
      return true;
408
798
    addParent(MapNode, Parents);
409
798
    ParentStack.push_back(createDynTypedNode(Node));
410
798
    bool Result = BaseTraverse();
411
798
    ParentStack.pop_back();
412
798
    return Result;
413
22.3k
  }
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>, 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>, llvm::detail::DenseMapPair<clang::DynTypedNode, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
405
24.9k
                    MapTy *Parents) {
406
24.9k
    if (!Node)
407
0
      return true;
408
24.9k
    addParent(MapNode, Parents);
409
24.9k
    ParentStack.push_back(createDynTypedNode(Node));
410
24.9k
    bool Result = BaseTraverse();
411
24.9k
    ParentStack.pop_back();
412
24.9k
    return Result;
413
24.9k
  }
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*>, 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*>, llvm::detail::DenseMapPair<void const*, llvm::PointerUnion<clang::Decl const*, clang::Stmt const*, clang::DynTypedNode*, llvm::SmallVector<clang::DynTypedNode, 2u>*> > >*)
Line
Count
Source
405
437
                    MapTy *Parents) {
406
437
    if (!Node)
407
0
      return true;
408
437
    addParent(MapNode, Parents);
409
437
    ParentStack.push_back(createDynTypedNode(Node));
410
437
    bool Result = BaseTraverse();
411
437
    ParentStack.pop_back();
412
437
    return Result;
413
437
  }
414
415
29.0k
  bool TraverseDecl(Decl *DeclNode) {
416
29.0k
    return TraverseNode(
417
29.0k
        DeclNode, DeclNode, [&] { return VisitorBase::TraverseDecl(DeclNode); },
418
29.0k
        &Map.PointerParents);
419
29.0k
  }
420
24.9k
  bool TraverseTypeLoc(TypeLoc TypeLocNode) {
421
24.9k
    return TraverseNode(
422
24.9k
        TypeLocNode, DynTypedNode::create(TypeLocNode),
423
24.9k
        [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); },
424
24.9k
        &Map.OtherParents);
425
24.9k
  }
426
22.3k
  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLocNode) {
427
22.3k
    return TraverseNode(
428
22.3k
        NNSLocNode, DynTypedNode::create(NNSLocNode),
429
22.3k
        [&] 
{ return VisitorBase::TraverseNestedNameSpecifierLoc(NNSLocNode); }798
,
430
22.3k
        &Map.OtherParents);
431
22.3k
  }
432
437
  bool TraverseAttr(Attr *AttrNode) {
433
437
    return TraverseNode(
434
437
        AttrNode, AttrNode, [&] { return VisitorBase::TraverseAttr(AttrNode); },
435
437
        &Map.PointerParents);
436
437
  }
437
438
  // Using generic TraverseNode for Stmt would prevent data-recursion.
439
18.5k
  bool dataTraverseStmtPre(Stmt *StmtNode) {
440
18.5k
    addParent(StmtNode, &Map.PointerParents);
441
18.5k
    ParentStack.push_back(DynTypedNode::create(*StmtNode));
442
18.5k
    return true;
443
18.5k
  }
444
18.5k
  bool dataTraverseStmtPost(Stmt *StmtNode) {
445
18.5k
    ParentStack.pop_back();
446
18.5k
    return true;
447
18.5k
  }
448
449
  ParentMap &Map;
450
  llvm::SmallVector<DynTypedNode, 16> ParentStack;
451
};
452
453
1.26k
ParentMapContext::ParentMap::ParentMap(ASTContext &Ctx) {
454
1.26k
  ASTVisitor(*this).TraverseAST(Ctx);
455
1.26k
}
456
457
18.2k
DynTypedNodeList ParentMapContext::getParents(const DynTypedNode &Node) {
458
18.2k
  if (!Parents)
459
    // We build the parent map for the traversal scope (usually whole TU), as
460
    // hasAncestor can escape any subtree.
461
1.26k
    Parents = std::make_unique<ParentMap>(ASTCtx);
462
18.2k
  return Parents->getParents(getTraversalKind(), Node);
463
18.2k
}