Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/JSONNodeDumper.h
Line
Count
Source (jump to first uncovered line)
1
//===--- JSONNodeDumper.h - Printing of AST nodes to JSON -----------------===//
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
// This file implements AST dumping of components of individual AST nodes to
10
// a JSON.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H
15
#define LLVM_CLANG_AST_JSONNODEDUMPER_H
16
17
#include "clang/AST/ASTContext.h"
18
#include "clang/AST/ASTDumperUtils.h"
19
#include "clang/AST/ASTNodeTraverser.h"
20
#include "clang/AST/AttrVisitor.h"
21
#include "clang/AST/CommentCommandTraits.h"
22
#include "clang/AST/CommentVisitor.h"
23
#include "clang/AST/ExprConcepts.h"
24
#include "clang/AST/ExprCXX.h"
25
#include "clang/AST/Mangle.h"
26
#include "clang/AST/Type.h"
27
#include "llvm/Support/JSON.h"
28
29
namespace clang {
30
31
class APValue;
32
33
class NodeStreamer {
34
  bool FirstChild = true;
35
  bool TopLevel = true;
36
  llvm::SmallVector<std::function<void(bool IsLastChild)>, 32> Pending;
37
38
protected:
39
  llvm::json::OStream JOS;
40
41
public:
42
  /// Add a child of the current node.  Calls DoAddChild without arguments
43
2.75k
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
2.75k
    return AddChild("", DoAddChild);
45
2.75k
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
2.05k
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
2.05k
    return AddChild("", DoAddChild);
45
2.05k
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::BlockDecl::Capture const&)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
3
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
3
    return AddChild("", DoAddChild);
45
3
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::OMPClause const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
2
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
2
    return AddChild("", DoAddChild);
45
2
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::TemplateArgument const&, clang::SourceRange, clang::Decl const*, char const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
39
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
39
    return AddChild("", DoAddChild);
45
39
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Type const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
495
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
495
    return AddChild("", DoAddChild);
45
495
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::QualType)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
1
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
1
    return AddChild("", DoAddChild);
45
1
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::GenericSelectionExpr::AssociationTy<true> const&)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
12
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
12
    return AddChild("", DoAddChild);
45
12
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::concepts::Requirement const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
4
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
4
    return AddChild("", DoAddChild);
45
4
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::CXXCtorInitializer const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
21
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
21
    return AddChild("", DoAddChild);
45
21
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(clang::ClassTemplateSpecializationDecl)
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(clang::ClassTemplateSpecializationDecl)
Line
Count
Source
43
20
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
20
    return AddChild("", DoAddChild);
45
20
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda'()>(clang::FunctionDecl)
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda0'()>(clang::FunctionDecl)
Line
Count
Source
43
1
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
1
    return AddChild("", DoAddChild);
45
1
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(clang::VarTemplateSpecializationDecl)
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(clang::VarTemplateSpecializationDecl)
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Attr const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
35
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
35
    return AddChild("", DoAddChild);
45
35
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::comments::Comment const*, clang::comments::FullComment const*)::'lambda'()>(clang::JSONDumper)
Line
Count
Source
43
64
  template <typename Fn> void AddChild(Fn DoAddChild) {
44
64
    return AddChild("", DoAddChild);
45
64
  }
46
47
  /// Add a child of the current node with an optional label.
48
  /// Calls DoAddChild without arguments.
49
5.58k
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
5.58k
    if (TopLevel) {
53
167
      TopLevel = false;
54
167
      JOS.objectBegin();
55
56
167
      DoAddChild();
57
58
296
      while (!Pending.empty()) {
59
129
        Pending.back()(true);
60
129
        Pending.pop_back();
61
129
      }
62
63
167
      JOS.objectEnd();
64
167
      TopLevel = true;
65
167
      return;
66
167
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
5.41k
    std::string LabelStr(!Label.empty() ? 
Label1
:
"inner"5.41k
);
71
5.41k
    bool WasFirstChild = FirstChild;
72
5.41k
    auto DumpWithIndent = [=](bool IsLastChild) {
73
5.41k
      if (WasFirstChild) {
74
3.12k
        JOS.attributeBegin(LabelStr);
75
3.12k
        JOS.arrayBegin();
76
3.12k
      }
77
78
5.41k
      FirstChild = true;
79
5.41k
      unsigned Depth = Pending.size();
80
5.41k
      JOS.objectBegin();
81
82
5.41k
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
8.41k
      while (Depth < Pending.size()) {
87
2.99k
        Pending.back()(true);
88
2.99k
        this->Pending.pop_back();
89
2.99k
      }
90
91
5.41k
      JOS.objectEnd();
92
93
5.41k
      if (IsLastChild) {
94
3.12k
        JOS.arrayEnd();
95
3.12k
        JOS.attributeEnd();
96
3.12k
      }
97
5.41k
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::BlockDecl::Capture const&)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
3
    auto DumpWithIndent = [=](bool IsLastChild) {
73
3
      if (WasFirstChild) {
74
2
        JOS.attributeBegin(LabelStr);
75
2
        JOS.arrayBegin();
76
2
      }
77
78
3
      FirstChild = true;
79
3
      unsigned Depth = Pending.size();
80
3
      JOS.objectBegin();
81
82
3
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
3
      while (Depth < Pending.size()) {
87
0
        Pending.back()(true);
88
0
        this->Pending.pop_back();
89
0
      }
90
91
3
      JOS.objectEnd();
92
93
3
      if (IsLastChild) {
94
0
        JOS.arrayEnd();
95
0
        JOS.attributeEnd();
96
0
      }
97
3
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::OMPClause const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
2
    auto DumpWithIndent = [=](bool IsLastChild) {
73
2
      if (WasFirstChild) {
74
2
        JOS.attributeBegin(LabelStr);
75
2
        JOS.arrayBegin();
76
2
      }
77
78
2
      FirstChild = true;
79
2
      unsigned Depth = Pending.size();
80
2
      JOS.objectBegin();
81
82
2
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
4
      while (Depth < Pending.size()) {
87
2
        Pending.back()(true);
88
2
        this->Pending.pop_back();
89
2
      }
90
91
2
      JOS.objectEnd();
92
93
2
      if (IsLastChild) {
94
0
        JOS.arrayEnd();
95
0
        JOS.attributeEnd();
96
0
      }
97
2
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Type const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
495
    auto DumpWithIndent = [=](bool IsLastChild) {
73
495
      if (WasFirstChild) {
74
484
        JOS.attributeBegin(LabelStr);
75
484
        JOS.arrayBegin();
76
484
      }
77
78
495
      FirstChild = true;
79
495
      unsigned Depth = Pending.size();
80
495
      JOS.objectBegin();
81
82
495
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
631
      while (Depth < Pending.size()) {
87
136
        Pending.back()(true);
88
136
        this->Pending.pop_back();
89
136
      }
90
91
495
      JOS.objectEnd();
92
93
495
      if (IsLastChild) {
94
476
        JOS.arrayEnd();
95
476
        JOS.attributeEnd();
96
476
      }
97
495
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::QualType)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
1
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1
      if (WasFirstChild) {
74
1
        JOS.attributeBegin(LabelStr);
75
1
        JOS.arrayBegin();
76
1
      }
77
78
1
      FirstChild = true;
79
1
      unsigned Depth = Pending.size();
80
1
      JOS.objectBegin();
81
82
1
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
2
      while (Depth < Pending.size()) {
87
1
        Pending.back()(true);
88
1
        this->Pending.pop_back();
89
1
      }
90
91
1
      JOS.objectEnd();
92
93
1
      if (IsLastChild) {
94
1
        JOS.arrayEnd();
95
1
        JOS.attributeEnd();
96
1
      }
97
1
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::TemplateArgument const&, clang::SourceRange, clang::Decl const*, char const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
39
    auto DumpWithIndent = [=](bool IsLastChild) {
73
39
      if (WasFirstChild) {
74
35
        JOS.attributeBegin(LabelStr);
75
35
        JOS.arrayBegin();
76
35
      }
77
78
39
      FirstChild = true;
79
39
      unsigned Depth = Pending.size();
80
39
      JOS.objectBegin();
81
82
39
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
64
      while (Depth < Pending.size()) {
87
25
        Pending.back()(true);
88
25
        this->Pending.pop_back();
89
25
      }
90
91
39
      JOS.objectEnd();
92
93
39
      if (IsLastChild) {
94
7
        JOS.arrayEnd();
95
7
        JOS.attributeEnd();
96
7
      }
97
39
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::GenericSelectionExpr::AssociationTy<true> const&)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
12
    auto DumpWithIndent = [=](bool IsLastChild) {
73
12
      if (WasFirstChild) {
74
0
        JOS.attributeBegin(LabelStr);
75
0
        JOS.arrayBegin();
76
0
      }
77
78
12
      FirstChild = true;
79
12
      unsigned Depth = Pending.size();
80
12
      JOS.objectBegin();
81
82
12
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
24
      while (Depth < Pending.size()) {
87
12
        Pending.back()(true);
88
12
        this->Pending.pop_back();
89
12
      }
90
91
12
      JOS.objectEnd();
92
93
12
      if (IsLastChild) {
94
7
        JOS.arrayEnd();
95
7
        JOS.attributeEnd();
96
7
      }
97
12
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::concepts::Requirement const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
4
    auto DumpWithIndent = [=](bool IsLastChild) {
73
4
      if (WasFirstChild) {
74
0
        JOS.attributeBegin(LabelStr);
75
0
        JOS.arrayBegin();
76
0
      }
77
78
4
      FirstChild = true;
79
4
      unsigned Depth = Pending.size();
80
4
      JOS.objectBegin();
81
82
4
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
8
      while (Depth < Pending.size()) {
87
4
        Pending.back()(true);
88
4
        this->Pending.pop_back();
89
4
      }
90
91
4
      JOS.objectEnd();
92
93
4
      if (IsLastChild) {
94
1
        JOS.arrayEnd();
95
1
        JOS.attributeEnd();
96
1
      }
97
4
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Stmt const*, llvm::StringRef)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
2.83k
    auto DumpWithIndent = [=](bool IsLastChild) {
73
2.83k
      if (WasFirstChild) {
74
1.88k
        JOS.attributeBegin(LabelStr);
75
1.88k
        JOS.arrayBegin();
76
1.88k
      }
77
78
2.83k
      FirstChild = true;
79
2.83k
      unsigned Depth = Pending.size();
80
2.83k
      JOS.objectBegin();
81
82
2.83k
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
4.56k
      while (Depth < Pending.size()) {
87
1.73k
        Pending.back()(true);
88
1.73k
        this->Pending.pop_back();
89
1.73k
      }
90
91
2.83k
      JOS.objectEnd();
92
93
2.83k
      if (IsLastChild) {
94
2.06k
        JOS.arrayEnd();
95
2.06k
        JOS.attributeEnd();
96
2.06k
      }
97
2.83k
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::CXXCtorInitializer const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
21
    auto DumpWithIndent = [=](bool IsLastChild) {
73
21
      if (WasFirstChild) {
74
0
        JOS.attributeBegin(LabelStr);
75
0
        JOS.arrayBegin();
76
0
      }
77
78
21
      FirstChild = true;
79
21
      unsigned Depth = Pending.size();
80
21
      JOS.objectBegin();
81
82
21
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
42
      while (Depth < Pending.size()) {
87
21
        Pending.back()(true);
88
21
        this->Pending.pop_back();
89
21
      }
90
91
21
      JOS.objectEnd();
92
93
21
      if (IsLastChild) {
94
0
        JOS.arrayEnd();
95
0
        JOS.attributeEnd();
96
0
      }
97
21
    };
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::ClassTemplateSpecializationDecl)::'lambda'(bool)::operator()(bool) const
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::ClassTemplateSpecializationDecl)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
20
    auto DumpWithIndent = [=](bool IsLastChild) {
73
20
      if (WasFirstChild) {
74
0
        JOS.attributeBegin(LabelStr);
75
0
        JOS.arrayBegin();
76
0
      }
77
78
20
      FirstChild = true;
79
20
      unsigned Depth = Pending.size();
80
20
      JOS.objectBegin();
81
82
20
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
20
      while (Depth < Pending.size()) {
87
0
        Pending.back()(true);
88
0
        this->Pending.pop_back();
89
0
      }
90
91
20
      JOS.objectEnd();
92
93
20
      if (IsLastChild) {
94
8
        JOS.arrayEnd();
95
8
        JOS.attributeEnd();
96
8
      }
97
20
    };
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::FunctionDecl)::'lambda'(bool)::operator()(bool) const
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::FunctionDecl)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
1
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1
      if (WasFirstChild) {
74
0
        JOS.attributeBegin(LabelStr);
75
0
        JOS.arrayBegin();
76
0
      }
77
78
1
      FirstChild = true;
79
1
      unsigned Depth = Pending.size();
80
1
      JOS.objectBegin();
81
82
1
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
1
      while (Depth < Pending.size()) {
87
0
        Pending.back()(true);
88
0
        this->Pending.pop_back();
89
0
      }
90
91
1
      JOS.objectEnd();
92
93
1
      if (IsLastChild) {
94
1
        JOS.arrayEnd();
95
1
        JOS.attributeEnd();
96
1
      }
97
1
    };
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::VarTemplateSpecializationDecl)::'lambda'(bool)::operator()(bool) const
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::VarTemplateSpecializationDecl)::'lambda'(bool)::operator()(bool) const
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Attr const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
35
    auto DumpWithIndent = [=](bool IsLastChild) {
73
35
      if (WasFirstChild) {
74
6
        JOS.attributeBegin(LabelStr);
75
6
        JOS.arrayBegin();
76
6
      }
77
78
35
      FirstChild = true;
79
35
      unsigned Depth = Pending.size();
80
35
      JOS.objectBegin();
81
82
35
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
35
      while (Depth < Pending.size()) {
87
0
        Pending.back()(true);
88
0
        this->Pending.pop_back();
89
0
      }
90
91
35
      JOS.objectEnd();
92
93
35
      if (IsLastChild) {
94
19
        JOS.arrayEnd();
95
19
        JOS.attributeEnd();
96
19
      }
97
35
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::comments::Comment const*, clang::comments::FullComment const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
64
    auto DumpWithIndent = [=](bool IsLastChild) {
73
64
      if (WasFirstChild) {
74
45
        JOS.attributeBegin(LabelStr);
75
45
        JOS.arrayBegin();
76
45
      }
77
78
64
      FirstChild = true;
79
64
      unsigned Depth = Pending.size();
80
64
      JOS.objectBegin();
81
82
64
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
101
      while (Depth < Pending.size()) {
87
37
        Pending.back()(true);
88
37
        this->Pending.pop_back();
89
37
      }
90
91
64
      JOS.objectEnd();
92
93
64
      if (IsLastChild) {
94
49
        JOS.arrayEnd();
95
49
        JOS.attributeEnd();
96
49
      }
97
64
    };
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)::'lambda'(bool)::operator()(bool) const
Line
Count
Source
72
1.89k
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1.89k
      if (WasFirstChild) {
74
659
        JOS.attributeBegin(LabelStr);
75
659
        JOS.arrayBegin();
76
659
      }
77
78
1.89k
      FirstChild = true;
79
1.89k
      unsigned Depth = Pending.size();
80
1.89k
      JOS.objectBegin();
81
82
1.89k
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
2.91k
      while (Depth < Pending.size()) {
87
1.02k
        Pending.back()(true);
88
1.02k
        this->Pending.pop_back();
89
1.02k
      }
90
91
1.89k
      JOS.objectEnd();
92
93
1.89k
      if (IsLastChild) {
94
483
        JOS.arrayEnd();
95
483
        JOS.attributeEnd();
96
483
      }
97
1.89k
    };
98
99
5.41k
    if (FirstChild) {
100
3.12k
      Pending.push_back(std::move(DumpWithIndent));
101
3.12k
    } else {
102
2.29k
      Pending.back()(false);
103
2.29k
      Pending.back() = std::move(DumpWithIndent);
104
2.29k
    }
105
5.41k
    FirstChild = false;
106
5.41k
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
2.05k
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
2.05k
    if (TopLevel) {
53
167
      TopLevel = false;
54
167
      JOS.objectBegin();
55
56
167
      DoAddChild();
57
58
296
      while (!Pending.empty()) {
59
129
        Pending.back()(true);
60
129
        Pending.pop_back();
61
129
      }
62
63
167
      JOS.objectEnd();
64
167
      TopLevel = true;
65
167
      return;
66
167
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
1.89k
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
1.89k
    bool WasFirstChild = FirstChild;
72
1.89k
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1.89k
      if (WasFirstChild) {
74
1.89k
        JOS.attributeBegin(LabelStr);
75
1.89k
        JOS.arrayBegin();
76
1.89k
      }
77
78
1.89k
      FirstChild = true;
79
1.89k
      unsigned Depth = Pending.size();
80
1.89k
      JOS.objectBegin();
81
82
1.89k
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
1.89k
      while (Depth < Pending.size()) {
87
1.89k
        Pending.back()(true);
88
1.89k
        this->Pending.pop_back();
89
1.89k
      }
90
91
1.89k
      JOS.objectEnd();
92
93
1.89k
      if (IsLastChild) {
94
1.89k
        JOS.arrayEnd();
95
1.89k
        JOS.attributeEnd();
96
1.89k
      }
97
1.89k
    };
98
99
1.89k
    if (FirstChild) {
100
659
      Pending.push_back(std::move(DumpWithIndent));
101
1.23k
    } else {
102
1.23k
      Pending.back()(false);
103
1.23k
      Pending.back() = std::move(DumpWithIndent);
104
1.23k
    }
105
1.89k
    FirstChild = false;
106
1.89k
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::BlockDecl::Capture const&)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
3
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
3
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
3
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
3
    bool WasFirstChild = FirstChild;
72
3
    auto DumpWithIndent = [=](bool IsLastChild) {
73
3
      if (WasFirstChild) {
74
3
        JOS.attributeBegin(LabelStr);
75
3
        JOS.arrayBegin();
76
3
      }
77
78
3
      FirstChild = true;
79
3
      unsigned Depth = Pending.size();
80
3
      JOS.objectBegin();
81
82
3
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
3
      while (Depth < Pending.size()) {
87
3
        Pending.back()(true);
88
3
        this->Pending.pop_back();
89
3
      }
90
91
3
      JOS.objectEnd();
92
93
3
      if (IsLastChild) {
94
3
        JOS.arrayEnd();
95
3
        JOS.attributeEnd();
96
3
      }
97
3
    };
98
99
3
    if (FirstChild) {
100
2
      Pending.push_back(std::move(DumpWithIndent));
101
2
    } else {
102
1
      Pending.back()(false);
103
1
      Pending.back() = std::move(DumpWithIndent);
104
1
    }
105
3
    FirstChild = false;
106
3
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Stmt const*, llvm::StringRef)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
2.83k
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
2.83k
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
2.83k
    std::string LabelStr(!Label.empty() ? 
Label1
:
"inner"2.83k
);
71
2.83k
    bool WasFirstChild = FirstChild;
72
2.83k
    auto DumpWithIndent = [=](bool IsLastChild) {
73
2.83k
      if (WasFirstChild) {
74
2.83k
        JOS.attributeBegin(LabelStr);
75
2.83k
        JOS.arrayBegin();
76
2.83k
      }
77
78
2.83k
      FirstChild = true;
79
2.83k
      unsigned Depth = Pending.size();
80
2.83k
      JOS.objectBegin();
81
82
2.83k
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
2.83k
      while (Depth < Pending.size()) {
87
2.83k
        Pending.back()(true);
88
2.83k
        this->Pending.pop_back();
89
2.83k
      }
90
91
2.83k
      JOS.objectEnd();
92
93
2.83k
      if (IsLastChild) {
94
2.83k
        JOS.arrayEnd();
95
2.83k
        JOS.attributeEnd();
96
2.83k
      }
97
2.83k
    };
98
99
2.83k
    if (FirstChild) {
100
1.88k
      Pending.push_back(std::move(DumpWithIndent));
101
1.88k
    } else {
102
944
      Pending.back()(false);
103
944
      Pending.back() = std::move(DumpWithIndent);
104
944
    }
105
2.83k
    FirstChild = false;
106
2.83k
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::OMPClause const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
2
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
2
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
2
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
2
    bool WasFirstChild = FirstChild;
72
2
    auto DumpWithIndent = [=](bool IsLastChild) {
73
2
      if (WasFirstChild) {
74
2
        JOS.attributeBegin(LabelStr);
75
2
        JOS.arrayBegin();
76
2
      }
77
78
2
      FirstChild = true;
79
2
      unsigned Depth = Pending.size();
80
2
      JOS.objectBegin();
81
82
2
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
2
      while (Depth < Pending.size()) {
87
2
        Pending.back()(true);
88
2
        this->Pending.pop_back();
89
2
      }
90
91
2
      JOS.objectEnd();
92
93
2
      if (IsLastChild) {
94
2
        JOS.arrayEnd();
95
2
        JOS.attributeEnd();
96
2
      }
97
2
    };
98
99
2
    if (FirstChild) {
100
2
      Pending.push_back(std::move(DumpWithIndent));
101
2
    } else {
102
0
      Pending.back()(false);
103
0
      Pending.back() = std::move(DumpWithIndent);
104
0
    }
105
2
    FirstChild = false;
106
2
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::TemplateArgument const&, clang::SourceRange, clang::Decl const*, char const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
39
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
39
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
39
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
39
    bool WasFirstChild = FirstChild;
72
39
    auto DumpWithIndent = [=](bool IsLastChild) {
73
39
      if (WasFirstChild) {
74
39
        JOS.attributeBegin(LabelStr);
75
39
        JOS.arrayBegin();
76
39
      }
77
78
39
      FirstChild = true;
79
39
      unsigned Depth = Pending.size();
80
39
      JOS.objectBegin();
81
82
39
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
39
      while (Depth < Pending.size()) {
87
39
        Pending.back()(true);
88
39
        this->Pending.pop_back();
89
39
      }
90
91
39
      JOS.objectEnd();
92
93
39
      if (IsLastChild) {
94
39
        JOS.arrayEnd();
95
39
        JOS.attributeEnd();
96
39
      }
97
39
    };
98
99
39
    if (FirstChild) {
100
35
      Pending.push_back(std::move(DumpWithIndent));
101
35
    } else {
102
4
      Pending.back()(false);
103
4
      Pending.back() = std::move(DumpWithIndent);
104
4
    }
105
39
    FirstChild = false;
106
39
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Type const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
495
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
495
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
495
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
495
    bool WasFirstChild = FirstChild;
72
495
    auto DumpWithIndent = [=](bool IsLastChild) {
73
495
      if (WasFirstChild) {
74
495
        JOS.attributeBegin(LabelStr);
75
495
        JOS.arrayBegin();
76
495
      }
77
78
495
      FirstChild = true;
79
495
      unsigned Depth = Pending.size();
80
495
      JOS.objectBegin();
81
82
495
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
495
      while (Depth < Pending.size()) {
87
495
        Pending.back()(true);
88
495
        this->Pending.pop_back();
89
495
      }
90
91
495
      JOS.objectEnd();
92
93
495
      if (IsLastChild) {
94
495
        JOS.arrayEnd();
95
495
        JOS.attributeEnd();
96
495
      }
97
495
    };
98
99
495
    if (FirstChild) {
100
484
      Pending.push_back(std::move(DumpWithIndent));
101
484
    } else {
102
11
      Pending.back()(false);
103
11
      Pending.back() = std::move(DumpWithIndent);
104
11
    }
105
495
    FirstChild = false;
106
495
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::QualType)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
1
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
1
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
1
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
1
    bool WasFirstChild = FirstChild;
72
1
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1
      if (WasFirstChild) {
74
1
        JOS.attributeBegin(LabelStr);
75
1
        JOS.arrayBegin();
76
1
      }
77
78
1
      FirstChild = true;
79
1
      unsigned Depth = Pending.size();
80
1
      JOS.objectBegin();
81
82
1
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
1
      while (Depth < Pending.size()) {
87
1
        Pending.back()(true);
88
1
        this->Pending.pop_back();
89
1
      }
90
91
1
      JOS.objectEnd();
92
93
1
      if (IsLastChild) {
94
1
        JOS.arrayEnd();
95
1
        JOS.attributeEnd();
96
1
      }
97
1
    };
98
99
1
    if (FirstChild) {
100
1
      Pending.push_back(std::move(DumpWithIndent));
101
1
    } else {
102
0
      Pending.back()(false);
103
0
      Pending.back() = std::move(DumpWithIndent);
104
0
    }
105
1
    FirstChild = false;
106
1
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::GenericSelectionExpr::AssociationTy<true> const&)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
12
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
12
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
12
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
12
    bool WasFirstChild = FirstChild;
72
12
    auto DumpWithIndent = [=](bool IsLastChild) {
73
12
      if (WasFirstChild) {
74
12
        JOS.attributeBegin(LabelStr);
75
12
        JOS.arrayBegin();
76
12
      }
77
78
12
      FirstChild = true;
79
12
      unsigned Depth = Pending.size();
80
12
      JOS.objectBegin();
81
82
12
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
12
      while (Depth < Pending.size()) {
87
12
        Pending.back()(true);
88
12
        this->Pending.pop_back();
89
12
      }
90
91
12
      JOS.objectEnd();
92
93
12
      if (IsLastChild) {
94
12
        JOS.arrayEnd();
95
12
        JOS.attributeEnd();
96
12
      }
97
12
    };
98
99
12
    if (FirstChild) {
100
0
      Pending.push_back(std::move(DumpWithIndent));
101
12
    } else {
102
12
      Pending.back()(false);
103
12
      Pending.back() = std::move(DumpWithIndent);
104
12
    }
105
12
    FirstChild = false;
106
12
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::concepts::Requirement const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
4
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
4
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
4
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
4
    bool WasFirstChild = FirstChild;
72
4
    auto DumpWithIndent = [=](bool IsLastChild) {
73
4
      if (WasFirstChild) {
74
4
        JOS.attributeBegin(LabelStr);
75
4
        JOS.arrayBegin();
76
4
      }
77
78
4
      FirstChild = true;
79
4
      unsigned Depth = Pending.size();
80
4
      JOS.objectBegin();
81
82
4
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
4
      while (Depth < Pending.size()) {
87
4
        Pending.back()(true);
88
4
        this->Pending.pop_back();
89
4
      }
90
91
4
      JOS.objectEnd();
92
93
4
      if (IsLastChild) {
94
4
        JOS.arrayEnd();
95
4
        JOS.attributeEnd();
96
4
      }
97
4
    };
98
99
4
    if (FirstChild) {
100
0
      Pending.push_back(std::move(DumpWithIndent));
101
4
    } else {
102
4
      Pending.back()(false);
103
4
      Pending.back() = std::move(DumpWithIndent);
104
4
    }
105
4
    FirstChild = false;
106
4
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::CXXCtorInitializer const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
21
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
21
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
21
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
21
    bool WasFirstChild = FirstChild;
72
21
    auto DumpWithIndent = [=](bool IsLastChild) {
73
21
      if (WasFirstChild) {
74
21
        JOS.attributeBegin(LabelStr);
75
21
        JOS.arrayBegin();
76
21
      }
77
78
21
      FirstChild = true;
79
21
      unsigned Depth = Pending.size();
80
21
      JOS.objectBegin();
81
82
21
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
21
      while (Depth < Pending.size()) {
87
21
        Pending.back()(true);
88
21
        this->Pending.pop_back();
89
21
      }
90
91
21
      JOS.objectEnd();
92
93
21
      if (IsLastChild) {
94
21
        JOS.arrayEnd();
95
21
        JOS.attributeEnd();
96
21
      }
97
21
    };
98
99
21
    if (FirstChild) {
100
0
      Pending.push_back(std::move(DumpWithIndent));
101
21
    } else {
102
21
      Pending.back()(false);
103
21
      Pending.back() = std::move(DumpWithIndent);
104
21
    }
105
21
    FirstChild = false;
106
21
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::ClassTemplateSpecializationDecl)
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::ClassTemplateSpecializationDecl)
Line
Count
Source
49
20
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
20
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
20
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
20
    bool WasFirstChild = FirstChild;
72
20
    auto DumpWithIndent = [=](bool IsLastChild) {
73
20
      if (WasFirstChild) {
74
20
        JOS.attributeBegin(LabelStr);
75
20
        JOS.arrayBegin();
76
20
      }
77
78
20
      FirstChild = true;
79
20
      unsigned Depth = Pending.size();
80
20
      JOS.objectBegin();
81
82
20
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
20
      while (Depth < Pending.size()) {
87
20
        Pending.back()(true);
88
20
        this->Pending.pop_back();
89
20
      }
90
91
20
      JOS.objectEnd();
92
93
20
      if (IsLastChild) {
94
20
        JOS.arrayEnd();
95
20
        JOS.attributeEnd();
96
20
      }
97
20
    };
98
99
20
    if (FirstChild) {
100
0
      Pending.push_back(std::move(DumpWithIndent));
101
20
    } else {
102
20
      Pending.back()(false);
103
20
      Pending.back() = std::move(DumpWithIndent);
104
20
    }
105
20
    FirstChild = false;
106
20
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::FunctionDecl)
void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::FunctionDecl)
Line
Count
Source
49
1
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
1
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
1
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
1
    bool WasFirstChild = FirstChild;
72
1
    auto DumpWithIndent = [=](bool IsLastChild) {
73
1
      if (WasFirstChild) {
74
1
        JOS.attributeBegin(LabelStr);
75
1
        JOS.arrayBegin();
76
1
      }
77
78
1
      FirstChild = true;
79
1
      unsigned Depth = Pending.size();
80
1
      JOS.objectBegin();
81
82
1
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
1
      while (Depth < Pending.size()) {
87
1
        Pending.back()(true);
88
1
        this->Pending.pop_back();
89
1
      }
90
91
1
      JOS.objectEnd();
92
93
1
      if (IsLastChild) {
94
1
        JOS.arrayEnd();
95
1
        JOS.attributeEnd();
96
1
      }
97
1
    };
98
99
1
    if (FirstChild) {
100
0
      Pending.push_back(std::move(DumpWithIndent));
101
1
    } else {
102
1
      Pending.back()(false);
103
1
      Pending.back() = std::move(DumpWithIndent);
104
1
    }
105
1
    FirstChild = false;
106
1
  }
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda'()>(llvm::StringRef, clang::VarTemplateSpecializationDecl)
Unexecuted instantiation: void clang::NodeStreamer::AddChild<void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda0'()>(llvm::StringRef, clang::VarTemplateSpecializationDecl)
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::Attr const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
35
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
35
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
35
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
35
    bool WasFirstChild = FirstChild;
72
35
    auto DumpWithIndent = [=](bool IsLastChild) {
73
35
      if (WasFirstChild) {
74
35
        JOS.attributeBegin(LabelStr);
75
35
        JOS.arrayBegin();
76
35
      }
77
78
35
      FirstChild = true;
79
35
      unsigned Depth = Pending.size();
80
35
      JOS.objectBegin();
81
82
35
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
35
      while (Depth < Pending.size()) {
87
35
        Pending.back()(true);
88
35
        this->Pending.pop_back();
89
35
      }
90
91
35
      JOS.objectEnd();
92
93
35
      if (IsLastChild) {
94
35
        JOS.arrayEnd();
95
35
        JOS.attributeEnd();
96
35
      }
97
35
    };
98
99
35
    if (FirstChild) {
100
6
      Pending.push_back(std::move(DumpWithIndent));
101
29
    } else {
102
29
      Pending.back()(false);
103
29
      Pending.back() = std::move(DumpWithIndent);
104
29
    }
105
35
    FirstChild = false;
106
35
  }
void clang::NodeStreamer::AddChild<clang::ASTNodeTraverser<clang::JSONDumper, clang::JSONNodeDumper>::Visit(clang::comments::Comment const*, clang::comments::FullComment const*)::'lambda'()>(llvm::StringRef, clang::JSONDumper)
Line
Count
Source
49
64
  template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) {
50
    // If we're at the top level, there's nothing interesting to do; just
51
    // run the dumper.
52
64
    if (TopLevel) {
53
0
      TopLevel = false;
54
0
      JOS.objectBegin();
55
56
0
      DoAddChild();
57
58
0
      while (!Pending.empty()) {
59
0
        Pending.back()(true);
60
0
        Pending.pop_back();
61
0
      }
62
63
0
      JOS.objectEnd();
64
0
      TopLevel = true;
65
0
      return;
66
0
    }
67
68
    // We need to capture an owning-string in the lambda because the lambda
69
    // is invoked in a deferred manner.
70
64
    std::string LabelStr(!Label.empty() ? 
Label0
: "inner");
71
64
    bool WasFirstChild = FirstChild;
72
64
    auto DumpWithIndent = [=](bool IsLastChild) {
73
64
      if (WasFirstChild) {
74
64
        JOS.attributeBegin(LabelStr);
75
64
        JOS.arrayBegin();
76
64
      }
77
78
64
      FirstChild = true;
79
64
      unsigned Depth = Pending.size();
80
64
      JOS.objectBegin();
81
82
64
      DoAddChild();
83
84
      // If any children are left, they're the last at their nesting level.
85
      // Dump those ones out now.
86
64
      while (Depth < Pending.size()) {
87
64
        Pending.back()(true);
88
64
        this->Pending.pop_back();
89
64
      }
90
91
64
      JOS.objectEnd();
92
93
64
      if (IsLastChild) {
94
64
        JOS.arrayEnd();
95
64
        JOS.attributeEnd();
96
64
      }
97
64
    };
98
99
64
    if (FirstChild) {
100
45
      Pending.push_back(std::move(DumpWithIndent));
101
45
    } else {
102
19
      Pending.back()(false);
103
19
      Pending.back() = std::move(DumpWithIndent);
104
19
    }
105
64
    FirstChild = false;
106
64
  }
107
108
167
  NodeStreamer(raw_ostream &OS) : JOS(OS, 2) {}
109
};
110
111
// Dumps AST nodes in JSON format. There is no implied stability for the
112
// content or format of the dump between major releases of Clang, other than it
113
// being valid JSON output. Further, there is no requirement that the
114
// information dumped is a complete representation of the AST, only that the
115
// information presented is correct.
116
class JSONNodeDumper
117
    : public ConstAttrVisitor<JSONNodeDumper>,
118
      public comments::ConstCommentVisitor<JSONNodeDumper, void,
119
                                           const comments::FullComment *>,
120
      public ConstTemplateArgumentVisitor<JSONNodeDumper>,
121
      public ConstStmtVisitor<JSONNodeDumper>,
122
      public TypeVisitor<JSONNodeDumper>,
123
      public ConstDeclVisitor<JSONNodeDumper>,
124
      public NodeStreamer {
125
  friend class JSONDumper;
126
127
  const SourceManager &SM;
128
  ASTContext& Ctx;
129
  ASTNameGenerator ASTNameGen;
130
  PrintingPolicy PrintPolicy;
131
  const comments::CommandTraits *Traits;
132
  StringRef LastLocFilename, LastLocPresumedFilename;
133
  unsigned LastLocLine, LastLocPresumedLine;
134
135
  using InnerAttrVisitor = ConstAttrVisitor<JSONNodeDumper>;
136
  using InnerCommentVisitor =
137
      comments::ConstCommentVisitor<JSONNodeDumper, void,
138
                                    const comments::FullComment *>;
139
  using InnerTemplateArgVisitor = ConstTemplateArgumentVisitor<JSONNodeDumper>;
140
  using InnerStmtVisitor = ConstStmtVisitor<JSONNodeDumper>;
141
  using InnerTypeVisitor = TypeVisitor<JSONNodeDumper>;
142
  using InnerDeclVisitor = ConstDeclVisitor<JSONNodeDumper>;
143
144
16.2k
  void attributeOnlyIfTrue(StringRef Key, bool Value) {
145
16.2k
    if (Value)
146
1.23k
      JOS.attribute(Key, Value);
147
16.2k
  }
148
149
  void writeIncludeStack(PresumedLoc Loc, bool JustFirst = false);
150
151
  // Writes the attributes of a SourceLocation object without.
152
  void writeBareSourceLocation(SourceLocation Loc, bool IsSpelling);
153
154
  // Writes the attributes of a SourceLocation to JSON based on its presumed
155
  // spelling location. If the given location represents a macro invocation,
156
  // this outputs two sub-objects: one for the spelling and one for the
157
  // expansion location.
158
  void writeSourceLocation(SourceLocation Loc);
159
  void writeSourceRange(SourceRange R);
160
  std::string createPointerRepresentation(const void *Ptr);
161
  llvm::json::Object createQualType(QualType QT, bool Desugar = true);
162
  llvm::json::Object createBareDeclRef(const Decl *D);
163
  llvm::json::Object createFPOptions(FPOptionsOverride FPO);
164
  void writeBareDeclRef(const Decl *D);
165
  llvm::json::Object createCXXRecordDefinitionData(const CXXRecordDecl *RD);
166
  llvm::json::Object createCXXBaseSpecifier(const CXXBaseSpecifier &BS);
167
  std::string createAccessSpecifier(AccessSpecifier AS);
168
  llvm::json::Array createCastPath(const CastExpr *C);
169
170
214
  void writePreviousDeclImpl(...) {}
171
172
146
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
146
    const T *First = D->getFirstDecl();
174
146
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
146
  }
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::LifetimeExtendedTemporaryDecl>(clang::Mergeable<clang::LifetimeExtendedTemporaryDecl> const*)
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UsingDecl>(clang::Mergeable<clang::UsingDecl> const*)
Line
Count
Source
172
5
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
5
    const T *First = D->getFirstDecl();
174
5
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
5
  }
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UsingEnumDecl>(clang::Mergeable<clang::UsingEnumDecl> const*)
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::ConceptDecl>(clang::Mergeable<clang::ConceptDecl> const*)
Line
Count
Source
172
2
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
2
    const T *First = D->getFirstDecl();
174
2
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
2
  }
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UnresolvedUsingTypenameDecl>(clang::Mergeable<clang::UnresolvedUsingTypenameDecl> const*)
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UsingPackDecl>(clang::Mergeable<clang::UsingPackDecl> const*)
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::FieldDecl>(clang::Mergeable<clang::FieldDecl> const*)
Line
Count
Source
172
111
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
111
    const T *First = D->getFirstDecl();
174
111
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
111
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::EnumConstantDecl>(clang::Mergeable<clang::EnumConstantDecl> const*)
Line
Count
Source
172
18
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
18
    const T *First = D->getFirstDecl();
174
18
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
18
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::IndirectFieldDecl>(clang::Mergeable<clang::IndirectFieldDecl> const*)
Line
Count
Source
172
10
  template <typename T> void writePreviousDeclImpl(const Mergeable<T> *D) {
173
10
    const T *First = D->getFirstDecl();
174
10
    if (First != D)
175
0
      JOS.attribute("firstRedecl", createPointerRepresentation(First));
176
10
  }
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::MSGuidDecl>(clang::Mergeable<clang::MSGuidDecl> const*)
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::TemplateParamObjectDecl>(clang::Mergeable<clang::TemplateParamObjectDecl> const*)
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UnnamedGlobalConstantDecl>(clang::Mergeable<clang::UnnamedGlobalConstantDecl> const*)
Unexecuted instantiation: void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UnresolvedUsingValueDecl>(clang::Mergeable<clang::UnresolvedUsingValueDecl> const*)
177
178
1.69k
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
1.69k
    const T *Prev = D->getPreviousDecl();
180
1.69k
    if (Prev)
181
31
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
1.69k
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl> const*)
Line
Count
Source
178
16
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
16
    const T *Prev = D->getPreviousDecl();
180
16
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
16
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl> const*)
Line
Count
Source
178
1
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
1
    const T *Prev = D->getPreviousDecl();
180
1
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
1
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl> const*)
Line
Count
Source
178
4
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
4
    const T *Prev = D->getPreviousDecl();
180
4
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
4
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl> const*)
Line
Count
Source
178
1
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
1
    const T *Prev = D->getPreviousDecl();
180
1
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
1
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl> const*)
Line
Count
Source
178
48
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
48
    const T *Prev = D->getPreviousDecl();
180
48
    if (Prev)
181
1
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
48
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::TagDecl>(clang::Redeclarable<clang::TagDecl> const*)
Line
Count
Source
178
274
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
274
    const T *Prev = D->getPreviousDecl();
180
274
    if (Prev)
181
3
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
274
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl> const*)
Line
Count
Source
178
315
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
315
    const T *Prev = D->getPreviousDecl();
180
315
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
315
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::UsingShadowDecl>(clang::Redeclarable<clang::UsingShadowDecl> const*)
Line
Count
Source
178
4
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
4
    const T *Prev = D->getPreviousDecl();
180
4
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
4
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::FunctionDecl>(clang::Redeclarable<clang::FunctionDecl> const*)
Line
Count
Source
178
501
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
501
    const T *Prev = D->getPreviousDecl();
180
501
    if (Prev)
181
27
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
501
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::VarDecl>(clang::Redeclarable<clang::VarDecl> const*)
Line
Count
Source
178
468
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
468
    const T *Prev = D->getPreviousDecl();
180
468
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
468
  }
void clang::JSONNodeDumper::writePreviousDeclImpl<clang::TranslationUnitDecl>(clang::Redeclarable<clang::TranslationUnitDecl> const*)
Line
Count
Source
178
64
  template <typename T> void writePreviousDeclImpl(const Redeclarable<T> *D) {
179
64
    const T *Prev = D->getPreviousDecl();
180
64
    if (Prev)
181
0
      JOS.attribute("previousDecl", createPointerRepresentation(Prev));
182
64
  }
183
  void addPreviousDeclaration(const Decl *D);
184
185
  StringRef getCommentCommandName(unsigned CommandID) const;
186
187
public:
188
  JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
189
                 const PrintingPolicy &PrintPolicy,
190
                 const comments::CommandTraits *Traits)
191
      : NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), ASTNameGen(Ctx),
192
        PrintPolicy(PrintPolicy), Traits(Traits), LastLocLine(0),
193
167
        LastLocPresumedLine(0) {}
194
195
  void Visit(const Attr *A);
196
  void Visit(const Stmt *Node);
197
  void Visit(const Type *T);
198
  void Visit(QualType T);
199
  void Visit(const Decl *D);
200
201
  void Visit(const comments::Comment *C, const comments::FullComment *FC);
202
  void Visit(const TemplateArgument &TA, SourceRange R = {},
203
             const Decl *From = nullptr, StringRef Label = {});
204
  void Visit(const CXXCtorInitializer *Init);
205
  void Visit(const OMPClause *C);
206
  void Visit(const BlockDecl::Capture &C);
207
  void Visit(const GenericSelectionExpr::ConstAssociation &A);
208
  void Visit(const concepts::Requirement *R);
209
  void Visit(const APValue &Value, QualType Ty);
210
211
  void VisitTypedefType(const TypedefType *TT);
212
  void VisitFunctionType(const FunctionType *T);
213
  void VisitFunctionProtoType(const FunctionProtoType *T);
214
  void VisitRValueReferenceType(const ReferenceType *RT);
215
  void VisitArrayType(const ArrayType *AT);
216
  void VisitConstantArrayType(const ConstantArrayType *CAT);
217
  void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *VT);
218
  void VisitVectorType(const VectorType *VT);
219
  void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT);
220
  void VisitUnaryTransformType(const UnaryTransformType *UTT);
221
  void VisitTagType(const TagType *TT);
222
  void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT);
223
  void VisitAutoType(const AutoType *AT);
224
  void VisitTemplateSpecializationType(const TemplateSpecializationType *TST);
225
  void VisitInjectedClassNameType(const InjectedClassNameType *ICNT);
226
  void VisitObjCInterfaceType(const ObjCInterfaceType *OIT);
227
  void VisitPackExpansionType(const PackExpansionType *PET);
228
  void VisitElaboratedType(const ElaboratedType *ET);
229
  void VisitMacroQualifiedType(const MacroQualifiedType *MQT);
230
  void VisitMemberPointerType(const MemberPointerType *MPT);
231
232
  void VisitNamedDecl(const NamedDecl *ND);
233
  void VisitTypedefDecl(const TypedefDecl *TD);
234
  void VisitTypeAliasDecl(const TypeAliasDecl *TAD);
235
  void VisitNamespaceDecl(const NamespaceDecl *ND);
236
  void VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD);
237
  void VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD);
238
  void VisitUsingDecl(const UsingDecl *UD);
239
  void VisitUsingEnumDecl(const UsingEnumDecl *UED);
240
  void VisitUsingShadowDecl(const UsingShadowDecl *USD);
241
  void VisitVarDecl(const VarDecl *VD);
242
  void VisitFieldDecl(const FieldDecl *FD);
243
  void VisitFunctionDecl(const FunctionDecl *FD);
244
  void VisitEnumDecl(const EnumDecl *ED);
245
  void VisitEnumConstantDecl(const EnumConstantDecl *ECD);
246
  void VisitRecordDecl(const RecordDecl *RD);
247
  void VisitCXXRecordDecl(const CXXRecordDecl *RD);
248
  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
249
  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
250
  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
251
  void VisitLinkageSpecDecl(const LinkageSpecDecl *LSD);
252
  void VisitAccessSpecDecl(const AccessSpecDecl *ASD);
253
  void VisitFriendDecl(const FriendDecl *FD);
254
255
  void VisitObjCIvarDecl(const ObjCIvarDecl *D);
256
  void VisitObjCMethodDecl(const ObjCMethodDecl *D);
257
  void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D);
258
  void VisitObjCCategoryDecl(const ObjCCategoryDecl *D);
259
  void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D);
260
  void VisitObjCProtocolDecl(const ObjCProtocolDecl *D);
261
  void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D);
262
  void VisitObjCImplementationDecl(const ObjCImplementationDecl *D);
263
  void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D);
264
  void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
265
  void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
266
  void VisitBlockDecl(const BlockDecl *D);
267
268
  void VisitDeclRefExpr(const DeclRefExpr *DRE);
269
  void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);
270
  void VisitPredefinedExpr(const PredefinedExpr *PE);
271
  void VisitUnaryOperator(const UnaryOperator *UO);
272
  void VisitBinaryOperator(const BinaryOperator *BO);
273
  void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO);
274
  void VisitMemberExpr(const MemberExpr *ME);
275
  void VisitCXXNewExpr(const CXXNewExpr *NE);
276
  void VisitCXXDeleteExpr(const CXXDeleteExpr *DE);
277
  void VisitCXXThisExpr(const CXXThisExpr *TE);
278
  void VisitCastExpr(const CastExpr *CE);
279
  void VisitImplicitCastExpr(const ImplicitCastExpr *ICE);
280
  void VisitCallExpr(const CallExpr *CE);
281
  void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *TTE);
282
  void VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE);
283
  void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE);
284
  void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
285
  void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
286
  void VisitConstantExpr(const ConstantExpr *CE);
287
  void VisitInitListExpr(const InitListExpr *ILE);
288
  void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE);
289
  void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *UCE);
290
  void VisitCXXConstructExpr(const CXXConstructExpr *CE);
291
  void VisitExprWithCleanups(const ExprWithCleanups *EWC);
292
  void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE);
293
  void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE);
294
  void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *ME);
295
  void VisitRequiresExpr(const RequiresExpr *RE);
296
297
  void VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE);
298
  void VisitObjCMessageExpr(const ObjCMessageExpr *OME);
299
  void VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE);
300
  void VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE);
301
  void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE);
302
  void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE);
303
  void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *OSRE);
304
  void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE);
305
  void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE);
306
307
  void VisitIntegerLiteral(const IntegerLiteral *IL);
308
  void VisitCharacterLiteral(const CharacterLiteral *CL);
309
  void VisitFixedPointLiteral(const FixedPointLiteral *FPL);
310
  void VisitFloatingLiteral(const FloatingLiteral *FL);
311
  void VisitStringLiteral(const StringLiteral *SL);
312
  void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE);
313
314
  void VisitIfStmt(const IfStmt *IS);
315
  void VisitSwitchStmt(const SwitchStmt *SS);
316
  void VisitCaseStmt(const CaseStmt *CS);
317
  void VisitLabelStmt(const LabelStmt *LS);
318
  void VisitGotoStmt(const GotoStmt *GS);
319
  void VisitWhileStmt(const WhileStmt *WS);
320
  void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *OACS);
321
  void VisitCompoundStmt(const CompoundStmt *IS);
322
323
  void VisitNullTemplateArgument(const TemplateArgument &TA);
324
  void VisitTypeTemplateArgument(const TemplateArgument &TA);
325
  void VisitDeclarationTemplateArgument(const TemplateArgument &TA);
326
  void VisitNullPtrTemplateArgument(const TemplateArgument &TA);
327
  void VisitIntegralTemplateArgument(const TemplateArgument &TA);
328
  void VisitTemplateTemplateArgument(const TemplateArgument &TA);
329
  void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
330
  void VisitExpressionTemplateArgument(const TemplateArgument &TA);
331
  void VisitPackTemplateArgument(const TemplateArgument &TA);
332
333
  void visitTextComment(const comments::TextComment *C,
334
                        const comments::FullComment *);
335
  void visitInlineCommandComment(const comments::InlineCommandComment *C,
336
                                 const comments::FullComment *);
337
  void visitHTMLStartTagComment(const comments::HTMLStartTagComment *C,
338
                                const comments::FullComment *);
339
  void visitHTMLEndTagComment(const comments::HTMLEndTagComment *C,
340
                              const comments::FullComment *);
341
  void visitBlockCommandComment(const comments::BlockCommandComment *C,
342
                                const comments::FullComment *);
343
  void visitParamCommandComment(const comments::ParamCommandComment *C,
344
                                const comments::FullComment *FC);
345
  void visitTParamCommandComment(const comments::TParamCommandComment *C,
346
                                 const comments::FullComment *FC);
347
  void visitVerbatimBlockComment(const comments::VerbatimBlockComment *C,
348
                                 const comments::FullComment *);
349
  void
350
  visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment *C,
351
                                const comments::FullComment *);
352
  void visitVerbatimLineComment(const comments::VerbatimLineComment *C,
353
                                const comments::FullComment *);
354
};
355
356
class JSONDumper : public ASTNodeTraverser<JSONDumper, JSONNodeDumper> {
357
  JSONNodeDumper NodeDumper;
358
359
  template <typename SpecializationDecl>
360
  void writeTemplateDeclSpecialization(const SpecializationDecl *SD,
361
                                       bool DumpExplicitInst,
362
27
                                       bool DumpRefOnly) {
363
27
    bool DumpedAny = false;
364
28
    for (const auto *RedeclWithBadType : SD->redecls()) {
365
      // FIXME: The redecls() range sometimes has elements of a less-specific
366
      // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
367
      // us TagDecls, and should give CXXRecordDecls).
368
28
      const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
369
28
      if (!Redecl) {
370
        // Found the injected-class-name for a class template. This will be
371
        // dumped as part of its surrounding class so we don't need to dump it
372
        // here.
373
0
        assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
374
0
               "expected an injected-class-name");
375
0
        continue;
376
0
      }
377
378
28
      switch (Redecl->getTemplateSpecializationKind()) {
379
0
      case TSK_ExplicitInstantiationDeclaration:
380
18
      case TSK_ExplicitInstantiationDefinition:
381
18
        if (!DumpExplicitInst)
382
18
          break;
383
18
        
LLVM_FALLTHROUGH0
;0
384
0
      case TSK_Undeclared:
385
6
      case TSK_ImplicitInstantiation:
386
6
        if (DumpRefOnly)
387
0
          NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
Unexecuted instantiation: void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda'()::operator()() const
Unexecuted instantiation: void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda'()::operator()() const
Unexecuted instantiation: void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda'()::operator()() const
388
6
        else
389
6
          Visit(Redecl);
390
6
        DumpedAny = true;
391
6
        break;
392
4
      case TSK_ExplicitSpecialization:
393
4
        break;
394
28
      }
395
28
    }
396
397
    // Ensure we dump at least one decl for each specialization.
398
27
    if (!DumpedAny)
399
21
      NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)::'lambda0'()::operator()() const
Line
Count
Source
399
20
      NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)::'lambda0'()::operator()() const
Line
Count
Source
399
1
      NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
Unexecuted instantiation: void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)::'lambda0'()::operator()() const
400
27
  }
void clang::JSONDumper::writeTemplateDeclSpecialization<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl const*, bool, bool)
Line
Count
Source
362
25
                                       bool DumpRefOnly) {
363
25
    bool DumpedAny = false;
364
25
    for (const auto *RedeclWithBadType : SD->redecls()) {
365
      // FIXME: The redecls() range sometimes has elements of a less-specific
366
      // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
367
      // us TagDecls, and should give CXXRecordDecls).
368
25
      const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
369
25
      if (!Redecl) {
370
        // Found the injected-class-name for a class template. This will be
371
        // dumped as part of its surrounding class so we don't need to dump it
372
        // here.
373
0
        assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
374
0
               "expected an injected-class-name");
375
0
        continue;
376
0
      }
377
378
25
      switch (Redecl->getTemplateSpecializationKind()) {
379
0
      case TSK_ExplicitInstantiationDeclaration:
380
18
      case TSK_ExplicitInstantiationDefinition:
381
18
        if (!DumpExplicitInst)
382
18
          break;
383
18
        
LLVM_FALLTHROUGH0
;0
384
0
      case TSK_Undeclared:
385
5
      case TSK_ImplicitInstantiation:
386
5
        if (DumpRefOnly)
387
0
          NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
388
5
        else
389
5
          Visit(Redecl);
390
5
        DumpedAny = true;
391
5
        break;
392
2
      case TSK_ExplicitSpecialization:
393
2
        break;
394
25
      }
395
25
    }
396
397
    // Ensure we dump at least one decl for each specialization.
398
25
    if (!DumpedAny)
399
20
      NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
400
25
  }
void clang::JSONDumper::writeTemplateDeclSpecialization<clang::FunctionDecl>(clang::FunctionDecl const*, bool, bool)
Line
Count
Source
362
2
                                       bool DumpRefOnly) {
363
2
    bool DumpedAny = false;
364
3
    for (const auto *RedeclWithBadType : SD->redecls()) {
365
      // FIXME: The redecls() range sometimes has elements of a less-specific
366
      // type. (In particular, ClassTemplateSpecializationDecl::redecls() gives
367
      // us TagDecls, and should give CXXRecordDecls).
368
3
      const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
369
3
      if (!Redecl) {
370
        // Found the injected-class-name for a class template. This will be
371
        // dumped as part of its surrounding class so we don't need to dump it
372
        // here.
373
0
        assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
374
0
               "expected an injected-class-name");
375
0
        continue;
376
0
      }
377
378
3
      switch (Redecl->getTemplateSpecializationKind()) {
379
0
      case TSK_ExplicitInstantiationDeclaration:
380
0
      case TSK_ExplicitInstantiationDefinition:
381
0
        if (!DumpExplicitInst)
382
0
          break;
383
0
        LLVM_FALLTHROUGH;
384
0
      case TSK_Undeclared:
385
1
      case TSK_ImplicitInstantiation:
386
1
        if (DumpRefOnly)
387
0
          NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
388
1
        else
389
1
          Visit(Redecl);
390
1
        DumpedAny = true;
391
1
        break;
392
2
      case TSK_ExplicitSpecialization:
393
2
        break;
394
3
      }
395
3
    }
396
397
    // Ensure we dump at least one decl for each specialization.
398
2
    if (!DumpedAny)
399
1
      NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
400
2
  }
Unexecuted instantiation: void clang::JSONDumper::writeTemplateDeclSpecialization<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl const*, bool, bool)
401
402
  template <typename TemplateDecl>
403
48
  void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {
404
    // FIXME: it would be nice to dump template parameters and specializations
405
    // to their own named arrays rather than shoving them into the "inner"
406
    // array. However, template declarations are currently being handled at the
407
    // wrong "level" of the traversal hierarchy and so it is difficult to
408
    // achieve without losing information elsewhere.
409
410
48
    dumpTemplateParameters(TD->getTemplateParameters());
411
412
48
    Visit(TD->getTemplatedDecl());
413
414
48
    for (const auto *Child : TD->specializations())
415
27
      writeTemplateDeclSpecialization(Child, DumpExplicitInst,
416
27
                                      !TD->isCanonicalDecl());
417
48
  }
void clang::JSONDumper::writeTemplateDecl<clang::ClassTemplateDecl>(clang::ClassTemplateDecl const*, bool)
Line
Count
Source
403
20
  void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {
404
    // FIXME: it would be nice to dump template parameters and specializations
405
    // to their own named arrays rather than shoving them into the "inner"
406
    // array. However, template declarations are currently being handled at the
407
    // wrong "level" of the traversal hierarchy and so it is difficult to
408
    // achieve without losing information elsewhere.
409
410
20
    dumpTemplateParameters(TD->getTemplateParameters());
411
412
20
    Visit(TD->getTemplatedDecl());
413
414
20
    for (const auto *Child : TD->specializations())
415
25
      writeTemplateDeclSpecialization(Child, DumpExplicitInst,
416
25
                                      !TD->isCanonicalDecl());
417
20
  }
void clang::JSONDumper::writeTemplateDecl<clang::FunctionTemplateDecl>(clang::FunctionTemplateDecl const*, bool)
Line
Count
Source
403
26
  void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {
404
    // FIXME: it would be nice to dump template parameters and specializations
405
    // to their own named arrays rather than shoving them into the "inner"
406
    // array. However, template declarations are currently being handled at the
407
    // wrong "level" of the traversal hierarchy and so it is difficult to
408
    // achieve without losing information elsewhere.
409
410
26
    dumpTemplateParameters(TD->getTemplateParameters());
411
412
26
    Visit(TD->getTemplatedDecl());
413
414
26
    for (const auto *Child : TD->specializations())
415
2
      writeTemplateDeclSpecialization(Child, DumpExplicitInst,
416
2
                                      !TD->isCanonicalDecl());
417
26
  }
void clang::JSONDumper::writeTemplateDecl<clang::VarTemplateDecl>(clang::VarTemplateDecl const*, bool)
Line
Count
Source
403
2
  void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {
404
    // FIXME: it would be nice to dump template parameters and specializations
405
    // to their own named arrays rather than shoving them into the "inner"
406
    // array. However, template declarations are currently being handled at the
407
    // wrong "level" of the traversal hierarchy and so it is difficult to
408
    // achieve without losing information elsewhere.
409
410
2
    dumpTemplateParameters(TD->getTemplateParameters());
411
412
2
    Visit(TD->getTemplatedDecl());
413
414
2
    for (const auto *Child : TD->specializations())
415
0
      writeTemplateDeclSpecialization(Child, DumpExplicitInst,
416
0
                                      !TD->isCanonicalDecl());
417
2
  }
418
419
public:
420
  JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
421
             const PrintingPolicy &PrintPolicy,
422
             const comments::CommandTraits *Traits)
423
167
      : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}
424
425
11.1k
  JSONNodeDumper &doGetNodeDelegate() { return NodeDumper; }
426
427
26
  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *FTD) {
428
26
    writeTemplateDecl(FTD, true);
429
26
  }
430
20
  void VisitClassTemplateDecl(const ClassTemplateDecl *CTD) {
431
20
    writeTemplateDecl(CTD, false);
432
20
  }
433
2
  void VisitVarTemplateDecl(const VarTemplateDecl *VTD) {
434
2
    writeTemplateDecl(VTD, false);
435
2
  }
436
};
437
438
} // namespace clang
439
440
#endif // LLVM_CLANG_AST_JSONNODEDUMPER_H