Coverage Report

Created: 2022-05-17 06:19

/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.6k
ParentMapContext::ParentMapContext(ASTContext &Ctx) : ASTCtx(Ctx) {}
23
24
21.5k
ParentMapContext::~ParentMapContext() = default;
25
26
69
void ParentMapContext::clear() { Parents.reset(); }
27
28
488k
const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
29
488k
  return traverseIgnored(const_cast<Expr *>(E));
30
488k
}
31
32
535k
Expr *ParentMapContext::traverseIgnored(Expr *E) const {
33
535k
  if (!E)
34
0
    return nullptr;
35
36
535k
  switch (Traversal) {
37
500k
  case TK_AsIs:
38
500k
    return E;
39
35.7k
  case TK_IgnoreUnlessSpelledInSource:
40
35.7k
    return E->IgnoreUnlessSpelledInSource();
41
535k
  }
42
0
  llvm_unreachable("Invalid Traversal type!");
43
0
}
44
45
1.19M
DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
46
1.19M
  if (const auto *E = N.get<Expr>()) {
47
488k
    return DynTypedNode::create(*traverseIgnored(E));
48
488k
  }
49
708k
  return N;
50
1.19M
}
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
37.8k
  getSingleDynTypedNodeFromParentMap(ParentMapPointers::mapped_type U) {
87
37.8k
    if (const auto *D = U.dyn_cast<const Decl *>())
88
15.4k
      return DynTypedNode::create(*D);
89
22.4k
    if (const auto *S = U.dyn_cast<const Stmt *>())
90
13.0k
      return DynTypedNode::create(*S);
91
9.44k
    return *U.get<DynTypedNode *>();
92
22.4k
  }
93
94
  template <typename NodeTy, typename MapTy>
95
  static DynTypedNodeList getDynNodeFromMap(const NodeTy &Node,
96
27.9k
                                                        const MapTy &Map) {
97
27.9k
    auto I = Map.find(Node);
98
27.9k
    if (I == Map.end()) {
99
944
      return llvm::ArrayRef<DynTypedNode>();
100
944
    }
101
27.0k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
134
      return llvm::makeArrayRef(*V);
103
134
    }
104
26.8k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
27.0k
  }
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
20.1k
                                                        const MapTy &Map) {
97
20.1k
    auto I = Map.find(Node);
98
20.1k
    if (I == Map.end()) {
99
893
      return llvm::ArrayRef<DynTypedNode>();
100
893
    }
101
19.2k
    if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
102
119
      return llvm::makeArrayRef(*V);
103
119
    }
104
19.0k
    return getSingleDynTypedNodeFromParentMap(I->second);
105
19.2k
  }
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.59k
  ~ParentMap() {
110
353k
    for (const auto &Entry : PointerParents) {
111
353k
      if (Entry.second.is<DynTypedNode *>()) {
112
39.9k
        delete Entry.second.get<DynTypedNode *>();
113
313k
      } else if (Entry.second.is<ParentVector *>()) {
114
1.59k
        delete Entry.second.get<ParentVector *>();
115
1.59k
      }
116
353k
    }
117
468k
    for (const auto &Entry : OtherParents) {
118
468k
      if (Entry.second.is<DynTypedNode *>()) {
119
315k
        delete Entry.second.get<DynTypedNode *>();
120
315k
      } else 
if (153k
Entry.second.is<ParentVector *>()153k
) {
121
9.39k
        delete Entry.second.get<ParentVector *>();
122
9.39k
      }
123
468k
    }
124
1.59k
  }
125
126
25.7k
  DynTypedNodeList getParents(TraversalKind TK, const DynTypedNode &Node) {
127
25.7k
    if (Node.getNodeKind().hasPointerIdentity()) {
128
20.1k
      auto ParentList =
129
20.1k
          getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
130
20.1k
      if (ParentList.size() > 0 && 
TK == TK_IgnoreUnlessSpelledInSource19.2k
) {
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
20.0k
      return ParentList;
198
20.1k
    }
199
5.62k
    return getDynNodeFromMap(Node, OtherParents);
200
25.7k
  }
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
246k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
246k
  return DynTypedNode::create(*Node);
325
246k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Decl*>(clang::Decl* const&)
Line
Count
Source
323
244k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
244k
  return DynTypedNode::create(*Node);
325
244k
}
ParentMapContext.cpp:clang::DynTypedNode createDynTypedNode<clang::Attr*>(clang::Attr* const&)
Line
Count
Source
323
1.35k
template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
324
1.35k
  return DynTypedNode::create(*Node);
325
1.35k
}
326
403k
template <> DynTypedNode createDynTypedNode(const TypeLoc &Node) {
327
403k
  return DynTypedNode::create(Node);
328
403k
}
329
template <>
330
77.1k
DynTypedNode createDynTypedNode(const NestedNameSpecifierLoc &Node) {
331
77.1k
  return DynTypedNode::create(Node);
332
77.1k
}
333
6
template <> DynTypedNode createDynTypedNode(const ObjCProtocolLoc &Node) {
334
6
  return DynTypedNode::create(Node);
335
6
}
336
/// @}
337
338
/// A \c RecursiveASTVisitor that builds a map from nodes to their
339
/// parents as defined by the \c RecursiveASTVisitor.
340
///
341
/// Note that the relationship described here is purely in terms of AST
342
/// traversal - there are other relationships (for example declaration context)
343
/// in the AST that are better modeled by special matchers.
344
class ParentMapContext::ParentMap::ASTVisitor
345
    : public RecursiveASTVisitor<ASTVisitor> {
346
public:
347
1.59k
  ASTVisitor(ParentMap &Map) : Map(Map) {}
348
349
private:
350
  friend class RecursiveASTVisitor<ASTVisitor>;
351
352
  using VisitorBase = RecursiveASTVisitor<ASTVisitor>;
353
354
36.7k
  bool shouldVisitTemplateInstantiations() const { return true; }
355
356
260k
  bool shouldVisitImplicitCode() const { return true; }
357
358
  /// Record the parent of the node we're visiting.
359
  /// MapNode is the child, the parent is on top of ParentStack.
360
  /// Parents is the parent storage (either PointerParents or OtherParents).
361
  template <typename MapNodeTy, typename MapTy>
362
838k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
363
838k
    if (ParentStack.empty())
364
1.59k
      return;
365
366
    // FIXME: Currently we add the same parent multiple times, but only
367
    // when no memoization data is available for the type.
368
    // For example when we visit all subexpressions of template
369
    // instantiations; this is suboptimal, but benign: the only way to
370
    // visit those is with hasAncestor / hasParent, and those do not create
371
    // new matches.
372
    // The plan is to enable DynTypedNode to be storable in a map or hash
373
    // map. The main problem there is to implement hash functions /
374
    // comparison operators for all types that DynTypedNode supports that
375
    // do not have pointer identity.
376
836k
    auto &NodeOrVector = (*Parents)[MapNode];
377
836k
    if (NodeOrVector.isNull()) {
378
822k
      if (const auto *D = ParentStack.back().get<Decl>())
379
345k
        NodeOrVector = D;
380
477k
      else if (const auto *S = ParentStack.back().get<Stmt>())
381
115k
        NodeOrVector = S;
382
362k
      else
383
362k
        NodeOrVector = new DynTypedNode(ParentStack.back());
384
822k
    } else {
385
14.0k
      if (!NodeOrVector.template is<ParentVector *>()) {
386
10.9k
        auto *Vector = new ParentVector(
387
10.9k
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
388
10.9k
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
389
10.9k
        NodeOrVector = Vector;
390
10.9k
      }
391
392
14.0k
      auto *Vector = NodeOrVector.template get<ParentVector *>();
393
      // Skip duplicates for types that have memoization data.
394
      // We must check that the type has memoization data before calling
395
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
396
      // types.
397
14.0k
      bool Found = ParentStack.back().getMemoizationData() &&
398
14.0k
                   
llvm::is_contained(*Vector, ParentStack.back())5.57k
;
399
14.0k
      if (!Found)
400
13.7k
        Vector->push_back(ParentStack.back());
401
14.0k
    }
402
836k
  }
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
362
244k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
363
244k
    if (ParentStack.empty())
364
1.59k
      return;
365
366
    // FIXME: Currently we add the same parent multiple times, but only
367
    // when no memoization data is available for the type.
368
    // For example when we visit all subexpressions of template
369
    // instantiations; this is suboptimal, but benign: the only way to
370
    // visit those is with hasAncestor / hasParent, and those do not create
371
    // new matches.
372
    // The plan is to enable DynTypedNode to be storable in a map or hash
373
    // map. The main problem there is to implement hash functions /
374
    // comparison operators for all types that DynTypedNode supports that
375
    // do not have pointer identity.
376
243k
    auto &NodeOrVector = (*Parents)[MapNode];
377
243k
    if (NodeOrVector.isNull()) {
378
243k
      if (const auto *D = ParentStack.back().get<Decl>())
379
215k
        NodeOrVector = D;
380
27.0k
      else if (const auto *S = ParentStack.back().get<Stmt>())
381
2.43k
        NodeOrVector = S;
382
24.6k
      else
383
24.6k
        NodeOrVector = new DynTypedNode(ParentStack.back());
384
243k
    } else {
385
282
      if (!NodeOrVector.template is<ParentVector *>()) {
386
160
        auto *Vector = new ParentVector(
387
160
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
388
160
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
389
160
        NodeOrVector = Vector;
390
160
      }
391
392
282
      auto *Vector = NodeOrVector.template get<ParentVector *>();
393
      // Skip duplicates for types that have memoization data.
394
      // We must check that the type has memoization data before calling
395
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
396
      // types.
397
282
      bool Found = ParentStack.back().getMemoizationData() &&
398
282
                   
llvm::is_contained(*Vector, ParentStack.back())134
;
399
282
      if (!Found)
400
282
        Vector->push_back(ParentStack.back());
401
282
    }
402
243k
  }
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
362
480k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
363
480k
    if (ParentStack.empty())
364
0
      return;
365
366
    // FIXME: Currently we add the same parent multiple times, but only
367
    // when no memoization data is available for the type.
368
    // For example when we visit all subexpressions of template
369
    // instantiations; this is suboptimal, but benign: the only way to
370
    // visit those is with hasAncestor / hasParent, and those do not create
371
    // new matches.
372
    // The plan is to enable DynTypedNode to be storable in a map or hash
373
    // map. The main problem there is to implement hash functions /
374
    // comparison operators for all types that DynTypedNode supports that
375
    // do not have pointer identity.
376
480k
    auto &NodeOrVector = (*Parents)[MapNode];
377
480k
    if (NodeOrVector.isNull()) {
378
468k
      if (const auto *D = ParentStack.back().get<Decl>())
379
112k
        NodeOrVector = D;
380
356k
      else if (const auto *S = ParentStack.back().get<Stmt>())
381
33.5k
        NodeOrVector = S;
382
322k
      else
383
322k
        NodeOrVector = new DynTypedNode(ParentStack.back());
384
468k
    } else {
385
12.0k
      if (!NodeOrVector.template is<ParentVector *>()) {
386
9.39k
        auto *Vector = new ParentVector(
387
9.39k
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
388
9.39k
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
389
9.39k
        NodeOrVector = Vector;
390
9.39k
      }
391
392
12.0k
      auto *Vector = NodeOrVector.template get<ParentVector *>();
393
      // Skip duplicates for types that have memoization data.
394
      // We must check that the type has memoization data before calling
395
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
396
      // types.
397
12.0k
      bool Found = ParentStack.back().getMemoizationData() &&
398
12.0k
                   
llvm::is_contained(*Vector, ParentStack.back())3.78k
;
399
12.0k
      if (!Found)
400
11.9k
        Vector->push_back(ParentStack.back());
401
12.0k
    }
402
480k
  }
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
362
111k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
363
111k
    if (ParentStack.empty())
364
0
      return;
365
366
    // FIXME: Currently we add the same parent multiple times, but only
367
    // when no memoization data is available for the type.
368
    // For example when we visit all subexpressions of template
369
    // instantiations; this is suboptimal, but benign: the only way to
370
    // visit those is with hasAncestor / hasParent, and those do not create
371
    // new matches.
372
    // The plan is to enable DynTypedNode to be storable in a map or hash
373
    // map. The main problem there is to implement hash functions /
374
    // comparison operators for all types that DynTypedNode supports that
375
    // do not have pointer identity.
376
111k
    auto &NodeOrVector = (*Parents)[MapNode];
377
111k
    if (NodeOrVector.isNull()) {
378
109k
      if (const auto *D = ParentStack.back().get<Decl>())
379
15.0k
        NodeOrVector = D;
380
94.3k
      else if (const auto *S = ParentStack.back().get<Stmt>())
381
79.0k
        NodeOrVector = S;
382
15.3k
      else
383
15.3k
        NodeOrVector = new DynTypedNode(ParentStack.back());
384
109k
    } else {
385
1.66k
      if (!NodeOrVector.template is<ParentVector *>()) {
386
1.43k
        auto *Vector = new ParentVector(
387
1.43k
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
388
1.43k
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
389
1.43k
        NodeOrVector = Vector;
390
1.43k
      }
391
392
1.66k
      auto *Vector = NodeOrVector.template get<ParentVector *>();
393
      // Skip duplicates for types that have memoization data.
394
      // We must check that the type has memoization data before calling
395
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
396
      // types.
397
1.66k
      bool Found = ParentStack.back().getMemoizationData() &&
398
1.66k
                   llvm::is_contained(*Vector, ParentStack.back());
399
1.66k
      if (!Found)
400
1.56k
        Vector->push_back(ParentStack.back());
401
1.66k
    }
402
111k
  }
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
362
1.35k
  void addParent(MapNodeTy MapNode, MapTy *Parents) {
363
1.35k
    if (ParentStack.empty())
364
0
      return;
365
366
    // FIXME: Currently we add the same parent multiple times, but only
367
    // when no memoization data is available for the type.
368
    // For example when we visit all subexpressions of template
369
    // instantiations; this is suboptimal, but benign: the only way to
370
    // visit those is with hasAncestor / hasParent, and those do not create
371
    // new matches.
372
    // The plan is to enable DynTypedNode to be storable in a map or hash
373
    // map. The main problem there is to implement hash functions /
374
    // comparison operators for all types that DynTypedNode supports that
375
    // do not have pointer identity.
376
1.35k
    auto &NodeOrVector = (*Parents)[MapNode];
377
1.35k
    if (NodeOrVector.isNull()) {
378
1.35k
      if (const auto *D = ParentStack.back().get<Decl>())
379
1.35k
        NodeOrVector = D;
380
0
      else if (const auto *S = ParentStack.back().get<Stmt>())
381
0
        NodeOrVector = S;
382
0
      else
383
0
        NodeOrVector = new DynTypedNode(ParentStack.back());
384
1.35k
    } else {
385
0
      if (!NodeOrVector.template is<ParentVector *>()) {
386
0
        auto *Vector = new ParentVector(
387
0
            1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
388
0
        delete NodeOrVector.template dyn_cast<DynTypedNode *>();
389
0
        NodeOrVector = Vector;
390
0
      }
391
392
0
      auto *Vector = NodeOrVector.template get<ParentVector *>();
393
      // Skip duplicates for types that have memoization data.
394
      // We must check that the type has memoization data before calling
395
      // llvm::is_contained() because DynTypedNode::operator== can't compare all
396
      // types.
397
0
      bool Found = ParentStack.back().getMemoizationData() &&
398
0
                   llvm::is_contained(*Vector, ParentStack.back());
399
0
      if (!Found)
400
0
        Vector->push_back(ParentStack.back());
401
0
    }
402
1.35k
  }
403
404
875k
  template <typename T> static bool isNull(T Node) { return !Node; }
bool clang::ParentMapContext::ParentMap::ASTVisitor::isNull<clang::Decl*>(clang::Decl*)
Line
Count
Source
404
245k
  template <typename T> static bool isNull(T Node) { return !Node; }
bool clang::ParentMapContext::ParentMap::ASTVisitor::isNull<clang::NestedNameSpecifierLoc>(clang::NestedNameSpecifierLoc)
Line
Count
Source
404
225k
  template <typename T> static bool isNull(T Node) { return !Node; }
bool clang::ParentMapContext::ParentMap::ASTVisitor::isNull<clang::TypeLoc>(clang::TypeLoc)
Line
Count
Source
404
403k
  template <typename T> static bool isNull(T Node) { return !Node; }
bool clang::ParentMapContext::ParentMap::ASTVisitor::isNull<clang::Attr*>(clang::Attr*)
Line
Count
Source
404
1.35k
  template <typename T> static bool isNull(T Node) { return !Node; }
405
6
  static bool isNull(ObjCProtocolLoc Node) { return false; }
406
407
  template <typename T, typename MapNodeTy, typename BaseTraverseFn,
408
            typename MapTy>
409
  bool TraverseNode(T Node, MapNodeTy MapNode, BaseTraverseFn BaseTraverse,
410
875k
                    MapTy *Parents) {
411
875k
    if (isNull(Node))
412
148k
      return true;
413
727k
    addParent(MapNode, Parents);
414
727k
    ParentStack.push_back(createDynTypedNode(Node));
415
727k
    bool Result = BaseTraverse();
416
727k
    ParentStack.pop_back();
417
727k
    return Result;
418
875k
  }
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
410
245k
                    MapTy *Parents) {
411
245k
    if (isNull(Node))
412
648
      return true;
413
244k
    addParent(MapNode, Parents);
414
244k
    ParentStack.push_back(createDynTypedNode(Node));
415
244k
    bool Result = BaseTraverse();
416
244k
    ParentStack.pop_back();
417
244k
    return Result;
418
245k
  }
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
410
225k
                    MapTy *Parents) {
411
225k
    if (isNull(Node))
412
148k
      return true;
413
77.1k
    addParent(MapNode, Parents);
414
77.1k
    ParentStack.push_back(createDynTypedNode(Node));
415
77.1k
    bool Result = BaseTraverse();
416
77.1k
    ParentStack.pop_back();
417
77.1k
    return Result;
418
225k
  }
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
410
403k
                    MapTy *Parents) {
411
403k
    if (isNull(Node))
412
0
      return true;
413
403k
    addParent(MapNode, Parents);
414
403k
    ParentStack.push_back(createDynTypedNode(Node));
415
403k
    bool Result = BaseTraverse();
416
403k
    ParentStack.pop_back();
417
403k
    return Result;
418
403k
  }
bool clang::ParentMapContext::ParentMap::ASTVisitor::TraverseNode<clang::ObjCProtocolLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseObjCProtocolLoc(clang::ObjCProtocolLoc)::'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::ObjCProtocolLoc, clang::DynTypedNode, clang::ParentMapContext::ParentMap::ASTVisitor::TraverseObjCProtocolLoc(clang::ObjCProtocolLoc)::'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
410
6
                    MapTy *Parents) {
411
6
    if (isNull(Node))
412
0
      return true;
413
6
    addParent(MapNode, Parents);
414
6
    ParentStack.push_back(createDynTypedNode(Node));
415
6
    bool Result = BaseTraverse();
416
6
    ParentStack.pop_back();
417
6
    return Result;
418
6
  }
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
410
1.35k
                    MapTy *Parents) {
411
1.35k
    if (isNull(Node))
412
0
      return true;
413
1.35k
    addParent(MapNode, Parents);
414
1.35k
    ParentStack.push_back(createDynTypedNode(Node));
415
1.35k
    bool Result = BaseTraverse();
416
1.35k
    ParentStack.pop_back();
417
1.35k
    return Result;
418
1.35k
  }
419
420
245k
  bool TraverseDecl(Decl *DeclNode) {
421
245k
    return TraverseNode(
422
245k
        DeclNode, DeclNode, [&] 
{ return VisitorBase::TraverseDecl(DeclNode); }244k
,
423
245k
        &Map.PointerParents);
424
245k
  }
425
403k
  bool TraverseTypeLoc(TypeLoc TypeLocNode) {
426
403k
    return TraverseNode(
427
403k
        TypeLocNode, DynTypedNode::create(TypeLocNode),
428
403k
        [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); },
429
403k
        &Map.OtherParents);
430
403k
  }
431
225k
  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLocNode) {
432
225k
    return TraverseNode(
433
225k
        NNSLocNode, DynTypedNode::create(NNSLocNode),
434
225k
        [&] 
{ return VisitorBase::TraverseNestedNameSpecifierLoc(NNSLocNode); }77.1k
,
435
225k
        &Map.OtherParents);
436
225k
  }
437
1.35k
  bool TraverseAttr(Attr *AttrNode) {
438
1.35k
    return TraverseNode(
439
1.35k
        AttrNode, AttrNode, [&] { return VisitorBase::TraverseAttr(AttrNode); },
440
1.35k
        &Map.PointerParents);
441
1.35k
  }
442
6
  bool TraverseObjCProtocolLoc(ObjCProtocolLoc ProtocolLocNode) {
443
6
    return TraverseNode(
444
6
        ProtocolLocNode, DynTypedNode::create(ProtocolLocNode),
445
6
        [&] { return VisitorBase::TraverseObjCProtocolLoc(ProtocolLocNode); },
446
6
        &Map.OtherParents);
447
6
  }
448
449
  // Using generic TraverseNode for Stmt would prevent data-recursion.
450
111k
  bool dataTraverseStmtPre(Stmt *StmtNode) {
451
111k
    addParent(StmtNode, &Map.PointerParents);
452
111k
    ParentStack.push_back(DynTypedNode::create(*StmtNode));
453
111k
    return true;
454
111k
  }
455
111k
  bool dataTraverseStmtPost(Stmt *StmtNode) {
456
111k
    ParentStack.pop_back();
457
111k
    return true;
458
111k
  }
459
460
  ParentMap &Map;
461
  llvm::SmallVector<DynTypedNode, 16> ParentStack;
462
};
463
464
1.59k
ParentMapContext::ParentMap::ParentMap(ASTContext &Ctx) {
465
1.59k
  ASTVisitor(*this).TraverseAST(Ctx);
466
1.59k
}
467
468
25.7k
DynTypedNodeList ParentMapContext::getParents(const DynTypedNode &Node) {
469
25.7k
  if (!Parents)
470
    // We build the parent map for the traversal scope (usually whole TU), as
471
    // hasAncestor can escape any subtree.
472
1.59k
    Parents = std::make_unique<ParentMap>(ASTCtx);
473
25.7k
  return Parents->getParents(getTraversalKind(), Node);
474
25.7k
}