Skip to content

Commit d821280

Browse files
committed
cleanup
1 parent 50dc807 commit d821280

File tree

13 files changed

+59
-204
lines changed

13 files changed

+59
-204
lines changed

include/mrdox/Metadata/Function.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
#include <mrdox/Metadata/Symbol.hpp>
2222
#include <mrdox/Metadata/Symbols.hpp>
2323
#include <mrdox/Metadata/Template.hpp>
24-
#include <clang/Basic/Specifiers.h>
25-
#include <llvm/ADT/SmallString.h>
26-
#include <llvm/ADT/SmallVector.h>
2724
#include <clang/AST/Attr.h>
2825
#include <memory>
29-
#include <optional>
3026
#include <string>
3127
#include <vector>
3228

include/mrdox/Metadata/Record.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <clang/AST/Type.h>
2525
#include <llvm/ADT/SmallVector.h>
2626
#include <memory>
27-
#include <optional>
2827
#include <string>
2928
#include <string_view>
3029
#include <vector>
@@ -105,7 +104,7 @@ struct RecordInfo
105104

106105
/** List of friend functions.
107106
*/
108-
llvm::SmallVector<SymbolID, 4> Friends;
107+
std::vector<SymbolID> Friends;
109108

110109
/** Record members
111110
*/

include/mrdox/Metadata/Reference.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct Reference
5353
{
5454
}
5555

56-
#if 1
56+
#if 0
5757
// VFALCO What was this for?
5858
bool
5959
operator==(

include/mrdox/Metadata/Symbol.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <mrdox/Platform.hpp>
1717
#include <mrdox/Metadata/Info.hpp>
1818
#include <mrdox/Metadata/Location.hpp>
19-
#include <llvm/ADT/SmallVector.h>
2019
#include <optional>
2120

2221
namespace clang {

include/mrdox/Metadata/Template.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ namespace mrdox {
2525

2626
enum class TParamKind : int
2727
{
28-
None = 0, // for bitstream
28+
// empty state, only used when constructing TParams
29+
None,
2930
// template type parameter, e.g. "typename T" or "class T"
3031
Type,
3132
// template non-type parameter, e.g. "int N" or "auto N"
3233
NonType,
3334
// template template parameter, e.g. "template<typename> typename T"
34-
Template,
35+
Template
3536
};
3637

3738
struct TParam;
@@ -194,8 +195,7 @@ struct TArg
194195

195196
// ----------------------------------------------------------------
196197

197-
/** Stores information pertaining to an explicit specialization of a
198-
member of an implicitly instantiated class template specialization.
198+
/** Information pertaining to member specializations.
199199
200200
This structure is stored in the `TemplateInfo` corresponding to the
201201
outermost specialized template. If the explicitly specialized
@@ -234,12 +234,11 @@ enum class TemplateSpecKind
234234
Partial
235235
};
236236

237-
/** Stores information pertaining to primary template and
238-
partial/explicit specialization declarations
237+
/** Information pertaining to templates and specializations thereof.
239238
*/
240239
struct TemplateInfo
241240
{
242-
/** For primary templates:
241+
/* For primary templates:
243242
- Params will be non-empty
244243
- Args will be empty
245244
For explicit specializations:
@@ -252,15 +251,16 @@ struct TemplateInfo
252251
std::vector<TParam> Params;
253252
std::vector<TArg> Args;
254253

255-
/** Stores the ID of the corresponding primary template
256-
for partial and explicit specializations
254+
/** Primary template ID for partial and explicit specializations.
257255
*/
258256
OptionalSymbolID Primary;
259257

258+
#if 0
260259
/** Stores information for explicit specializations of members
261260
of implicitly instantiated class template specializations
262261
*/
263262
std::vector<SpecializationInfo> Specializations;
263+
#endif
264264

265265
// KRYSTIAN NOTE: using the presence of args/params
266266
// to determine the specialization kind *should* work.

include/mrdox/Metadata/Var.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define MRDOX_METADATA_VARIABLE_HPP
1414

1515
#include <mrdox/Platform.hpp>
16-
#include <mrdox/Metadata/Field.hpp>
16+
#include <mrdox/ADT/BitField.hpp>
1717
#include <mrdox/Metadata/Symbol.hpp>
1818
#include <mrdox/Metadata/Template.hpp>
1919
#include <mrdox/Metadata/Type.hpp>

source/AST/ASTVisitor.cpp

Lines changed: 13 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <clang/AST/Decl.h>
2424
#include <clang/AST/DeclCXX.h>
2525
#include <clang/AST/DeclFriend.h>
26+
#include <clang/Frontend/CompilerInstance.h>
2627
#include <clang/Index/USRGeneration.h>
2728
#include <clang/Lex/Lexer.h>
2829
#include <llvm/ADT/Hashing.h>
@@ -33,98 +34,10 @@
3334
#include <cassert>
3435
#include <ranges>
3536

36-
#include <clang/Frontend/CompilerInstance.h>
37-
// #include <clang/Sema/Sema.h>
38-
// #include <clang/Sema/Template.h>
3937

4038
namespace clang {
4139
namespace mrdox {
4240

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-
12841
//------------------------------------------------
12942
//
13043
// ASTVisitor
@@ -267,7 +180,7 @@ getParentNamespaces(
267180
N->getNameAsString(),
268181
InfoType::IT_enum);
269182
}
270-
else if(const auto* N = dyn_cast<TranslationUnitDecl>(DC))
183+
else if(isa<TranslationUnitDecl>(DC))
271184
{
272185
Namespaces.emplace_back(
273186
SymbolID::zero,
@@ -1098,7 +1011,8 @@ buildFriend(
10981011
#else
10991012
const DeclContext* DC = D->getDeclContext();
11001013
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);
11021016
RecordInfo P;
11031017
extractSymbolID(RD, P.id);
11041018

@@ -1563,14 +1477,15 @@ Traverse(
15631477
if(! shouldExtract(D))
15641478
return true;
15651479

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+
*/
15741489
auto Template = std::make_unique<TemplateInfo>();
15751490
parseTemplateArgs(*Template, D);
15761491

@@ -1613,48 +1528,8 @@ TraverseDecl(
16131528
Args&&... args)
16141529
{
16151530
Assert(D);
1616-
1617-
#if 1
16181531
if(D->isImplicit())
16191532
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
16581533

16591534
switch(D->getKind())
16601535
{
@@ -1790,10 +1665,8 @@ TraverseContext(
17901665
DeclContext* D)
17911666
{
17921667
Assert(D);
1793-
++context_depth_;
17941668
for(auto* C : D->decls())
17951669
TraverseDecl(C);
1796-
--context_depth_;
17971670
return true;
17981671
}
17991672

@@ -1822,7 +1695,6 @@ HandleTranslationUnit(
18221695
if(! config_.shouldVisitTU(File))
18231696
return;
18241697

1825-
context_depth_ = 0;
18261698
sema_ = &compiler_.getSema();
18271699

18281700
TranslationUnitDecl* TU =

0 commit comments

Comments
 (0)