|
23 | 23 | #include <clang/AST/Decl.h>
|
24 | 24 | #include <clang/AST/DeclCXX.h>
|
25 | 25 | #include <clang/AST/DeclFriend.h>
|
| 26 | +#include <clang/Frontend/CompilerInstance.h> |
26 | 27 | #include <clang/Index/USRGeneration.h>
|
27 | 28 | #include <clang/Lex/Lexer.h>
|
28 | 29 | #include <llvm/ADT/Hashing.h>
|
|
33 | 34 | #include <cassert>
|
34 | 35 | #include <ranges>
|
35 | 36 |
|
36 |
| -#include <clang/Frontend/CompilerInstance.h> |
37 |
| -// #include <clang/Sema/Sema.h> |
38 |
| -// #include <clang/Sema/Template.h> |
39 | 37 |
|
40 | 38 | namespace clang {
|
41 | 39 | namespace mrdox {
|
42 | 40 |
|
43 |
| -namespace { |
44 |
| - |
45 |
| -std::string getDeclName(const Decl* D) |
46 |
| -{ |
47 |
| - if(const auto* N = dyn_cast<NamedDecl>(D)) |
48 |
| - return N->getQualifiedNameAsString(); |
49 |
| - return "<unnamed>"; |
50 |
| -} |
51 |
| - |
52 |
| -std::optional<std::size_t> getNumSpecializations(Decl* D) |
53 |
| -{ |
54 |
| - std::optional<std::size_t> r; |
55 |
| - if(auto* T = dyn_cast<ClassTemplateDecl>(D)) |
56 |
| - { |
57 |
| - r.emplace(); |
58 |
| - if(T->specializations().empty()) |
59 |
| - return r; |
60 |
| - for([[maybe_unused]] auto&& S : T->specializations()) |
61 |
| - { |
62 |
| -#if 0 |
63 |
| - print_debug(" "); |
64 |
| - DeclContext* DC = S->getDeclContext(); |
65 |
| - do |
66 |
| - { |
67 |
| - Decl* ID = dyn_cast<Decl>(DC); |
68 |
| - print_debug("{} ({}) | ", getDeclName(ID), ID->getDeclKindName()); |
69 |
| - } |
70 |
| - while(DC = DC->getParent()); |
71 |
| - print_debug("\n"); |
72 |
| -#endif |
73 |
| - ++r.value(); |
74 |
| - } |
75 |
| - } |
76 |
| - else if(auto* T = dyn_cast<FunctionTemplateDecl>(D)) |
77 |
| - { |
78 |
| - r.emplace(); |
79 |
| - for([[maybe_unused]] auto&& S : T->specializations()) |
80 |
| - ++r.value(); |
81 |
| - } |
82 |
| - else if(auto* T = dyn_cast<VarTemplateDecl>(D)) |
83 |
| - { |
84 |
| - r.emplace(); |
85 |
| - for([[maybe_unused]] auto&& S : T->specializations()) |
86 |
| - ++r.value(); |
87 |
| - } |
88 |
| - return r; |
89 |
| -} |
90 |
| - |
91 |
| -std::string indent( |
92 |
| - std::size_t depth, |
93 |
| - std::size_t indent_size = 4) |
94 |
| -{ |
95 |
| - return std::string(depth * indent_size, ' '); |
96 |
| -} |
97 |
| - |
98 |
| -const CXXRecordDecl* |
99 |
| -getInstantiatedFromRecord( |
100 |
| - const ClassTemplatePartialSpecializationDecl* CTPSD) |
101 |
| -{ |
102 |
| - if(auto* MT = CTPSD->getInstantiatedFromMember()) |
103 |
| - return MT; |
104 |
| - return CTPSD; |
105 |
| -} |
106 |
| - |
107 |
| -const CXXRecordDecl* |
108 |
| -getInstantiatedFromRecord( |
109 |
| - const ClassTemplateSpecializationDecl* CTSD) |
110 |
| -{ |
111 |
| - auto parent = CTSD->getSpecializedTemplateOrPartial(); |
112 |
| - // an explicitly specialized member of a partial specialization |
113 |
| - // is not a member of the primary template; treat it as such. |
114 |
| - if(auto* CTPSD = parent.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) |
115 |
| - return getInstantiatedFromRecord(CTPSD); |
116 |
| - |
117 |
| - ClassTemplateDecl* CTD = CTSD->getSpecializedTemplate(); |
118 |
| - Assert(CTD); |
119 |
| - // for implicit specializations of a primary member template, |
120 |
| - // consider the parent context to be the primary template |
121 |
| - if(ClassTemplateDecl* MT = CTD->getInstantiatedFromMemberTemplate()) |
122 |
| - return MT->getTemplatedDecl(); |
123 |
| - return CTD->getTemplatedDecl(); |
124 |
| -} |
125 |
| - |
126 |
| -} // anon |
127 |
| - |
128 | 41 | //------------------------------------------------
|
129 | 42 | //
|
130 | 43 | // ASTVisitor
|
@@ -267,7 +180,7 @@ getParentNamespaces(
|
267 | 180 | N->getNameAsString(),
|
268 | 181 | InfoType::IT_enum);
|
269 | 182 | }
|
270 |
| - else if(const auto* N = dyn_cast<TranslationUnitDecl>(DC)) |
| 183 | + else if(isa<TranslationUnitDecl>(DC)) |
271 | 184 | {
|
272 | 185 | Namespaces.emplace_back(
|
273 | 186 | SymbolID::zero,
|
@@ -1098,7 +1011,8 @@ buildFriend(
|
1098 | 1011 | #else
|
1099 | 1012 | const DeclContext* DC = D->getDeclContext();
|
1100 | 1013 | const auto* RD = dyn_cast<CXXRecordDecl>(DC);
|
1101 |
| - Assert(RD && "the semantic DeclContext of a FriendDecl must be a class"); |
| 1014 | + // the semantic DeclContext of a FriendDecl must be a class |
| 1015 | + Assert(RD); |
1102 | 1016 | RecordInfo P;
|
1103 | 1017 | extractSymbolID(RD, P.id);
|
1104 | 1018 |
|
@@ -1563,14 +1477,15 @@ Traverse(
|
1563 | 1477 | if(! shouldExtract(D))
|
1564 | 1478 | return true;
|
1565 | 1479 |
|
1566 |
| - // for class scope explicit specializations of member function templates which |
1567 |
| - // are members of class templates, it is impossible to know what the |
1568 |
| - // primary template is until the enclosing class template is instantiated. |
1569 |
| - // while such declarations are valid C++ (see CWG 727 and [temp.expl.spec] p3), |
1570 |
| - // GCC does not consider them to be valid. consequently, we do not extract the SymbolID |
1571 |
| - // of the primary template. in the future, we could take a best-effort approach to find |
1572 |
| - // the primary template, but this is only possible when none of the candidates are dependent |
1573 |
| - // upon a template parameter of the enclosing class template. |
| 1480 | + /* For class scope explicit specializations of member function templates which |
| 1481 | + are members of class templates, it is impossible to know what the |
| 1482 | + primary template is until the enclosing class template is instantiated. |
| 1483 | + while such declarations are valid C++ (see CWG 727 and [temp.expl.spec] p3), |
| 1484 | + GCC does not consider them to be valid. Consequently, we do not extract the SymbolID |
| 1485 | + of the primary template. In the future, we could take a best-effort approach to find |
| 1486 | + the primary template, but this is only possible when none of the candidates are dependent |
| 1487 | + upon a template parameter of the enclosing class template. |
| 1488 | + */ |
1574 | 1489 | auto Template = std::make_unique<TemplateInfo>();
|
1575 | 1490 | parseTemplateArgs(*Template, D);
|
1576 | 1491 |
|
@@ -1613,48 +1528,8 @@ TraverseDecl(
|
1613 | 1528 | Args&&... args)
|
1614 | 1529 | {
|
1615 | 1530 | Assert(D);
|
1616 |
| - |
1617 |
| -#if 1 |
1618 | 1531 | if(D->isImplicit())
|
1619 | 1532 | return true;
|
1620 |
| -#elif 1 |
1621 |
| - { |
1622 |
| - |
1623 |
| - if(D->isImplicit()) |
1624 |
| - { |
1625 |
| - if(! encountered_explicit_) |
1626 |
| - return true; |
1627 |
| - print_debug("{:<64}{:<32} ID = {}\n", std::format( |
1628 |
| - "{}(implicit) {}", indent(context_depth_), D->getDeclKindName()), |
1629 |
| - getDeclName(D), extractSymbolID(D)); |
1630 |
| - return true; |
1631 |
| - } |
1632 |
| - encountered_explicit_ = true; |
1633 |
| - |
1634 |
| - print_debug("{:<64}{:<32} ID = {}\n", std::format( |
1635 |
| - "{}{}", indent(context_depth_), D->getDeclKindName()), |
1636 |
| - getDeclName(D), extractSymbolID(D)); |
1637 |
| - print_debug("{} {}\n", indent(context_depth_), usr_.c_str()); |
1638 |
| - } |
1639 |
| -#elif 1 |
1640 |
| - { |
1641 |
| - auto specs = getNumSpecializations(D); |
1642 |
| - std::string specs_str = specs.has_value() ? |
1643 |
| - std::format("specializations = {}", *specs) : ""; |
1644 |
| - if(D->isImplicit()) |
1645 |
| - { |
1646 |
| - print_debug("{:<64}{:<32}{}\n", std::format( |
1647 |
| - "{}(implicit) {}", indent(context_depth_), D->getDeclKindName()), |
1648 |
| - getDeclName(D), specs_str); |
1649 |
| - if(auto* DC = dyn_cast<DeclContext>(D)) |
1650 |
| - TraverseContext(DC); |
1651 |
| - return true; |
1652 |
| - } |
1653 |
| - print_debug("{:<64}{:<32}{}\n", std::format( |
1654 |
| - "{}{}", indent(context_depth_), D->getDeclKindName()), |
1655 |
| - getDeclName(D), specs_str); |
1656 |
| - } |
1657 |
| -#endif |
1658 | 1533 |
|
1659 | 1534 | switch(D->getKind())
|
1660 | 1535 | {
|
@@ -1790,10 +1665,8 @@ TraverseContext(
|
1790 | 1665 | DeclContext* D)
|
1791 | 1666 | {
|
1792 | 1667 | Assert(D);
|
1793 |
| - ++context_depth_; |
1794 | 1668 | for(auto* C : D->decls())
|
1795 | 1669 | TraverseDecl(C);
|
1796 |
| - --context_depth_; |
1797 | 1670 | return true;
|
1798 | 1671 | }
|
1799 | 1672 |
|
@@ -1822,7 +1695,6 @@ HandleTranslationUnit(
|
1822 | 1695 | if(! config_.shouldVisitTU(File))
|
1823 | 1696 | return;
|
1824 | 1697 |
|
1825 |
| - context_depth_ = 0; |
1826 | 1698 | sema_ = &compiler_.getSema();
|
1827 | 1699 |
|
1828 | 1700 | TranslationUnitDecl* TU =
|
|
0 commit comments