Skip to content

Commit 5ed6c8f

Browse files
committed
refactor XML
1 parent ebea6bd commit 5ed6c8f

File tree

5 files changed

+507
-180
lines changed

5 files changed

+507
-180
lines changed

source/lib/BasicVisitor.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ mapDecl(T const* D)
5454
bool IsFileInRootDir;
5555
llvm::SmallString<128> File =
5656
getFile(D, D->getASTContext(), cfg_.SourceRoot, IsFileInRootDir);
57-
auto I = serialize::emitInfo(D, getComment(D, D->getASTContext()),
58-
getLine(D, D->getASTContext()), File,
59-
IsFileInRootDir, cfg_.PublicOnly);
57+
auto I = serialize::emitInfo(
58+
D,
59+
getComment(D, D->getASTContext()),
60+
getLine(D, D->getASTContext()),
61+
File,
62+
IsFileInRootDir,
63+
cfg_.PublicOnly);
6064

6165
// A null in place of I indicates that the serializer is skipping this decl
6266
// for some reason (e.g. we're only reporting public decls).
@@ -115,10 +119,24 @@ VisitFunctionDecl(
115119
return mapDecl(D);
116120
}
117121

122+
// https://github.com/llvm/llvm-project/blob/466d554dcab39c3d42fe0c5b588b795e0e4b9d0d/clang/include/clang/AST/Type.h#L1566
123+
118124
bool
119125
BasicVisitor::
120126
VisitTypedefDecl(TypedefDecl const* D)
121127
{
128+
#if 0
129+
TypeDecl const* td = D;
130+
Type const* ty = td->getTypeForDecl();
131+
ty->getAsCXXRecordDecl();
132+
133+
/*
134+
for(auto const& t : D->redecls())
135+
{
136+
llvm::outs() << "\n";
137+
}
138+
*/
139+
#endif
122140
return mapDecl(D);
123141
}
124142

source/lib/Serialize.cpp

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,58 @@ TypeInfo getTypeInfoForType(const QualType& T) {
142142
T.getAsString(), getInfoRelativePath(TD)));
143143
}
144144

145-
static bool isPublic(const clang::AccessSpecifier AS,
146-
const clang::Linkage Link) {
145+
static
146+
bool
147+
isPublic(
148+
clang::AccessSpecifier const AS,
149+
clang::Linkage const Link)
150+
{
147151
if (AS == clang::AccessSpecifier::AS_private)
148152
return false;
149-
else if ((Link == clang::Linkage::ModuleLinkage) ||
150-
(Link == clang::Linkage::ExternalLinkage))
153+
if (Link == clang::Linkage::ModuleLinkage ||
154+
Link == clang::Linkage::ExternalLinkage)
151155
return true;
152-
return false; // otherwise, linkage is some form of internal linkage
156+
// some form of internal linkage
157+
return false;
153158
}
154159

155-
static bool shouldSerializeInfo(bool PublicOnly, bool IsInAnonymousNamespace,
156-
const NamedDecl* D) {
160+
static
161+
bool
162+
shouldSerializeInfo(
163+
bool PublicOnly,
164+
bool IsInAnonymousNamespace,
165+
NamedDecl const* D)
166+
{
157167
bool IsAnonymousNamespace = false;
158-
if (const auto* N = dyn_cast<NamespaceDecl>(D))
168+
if(auto const* N = dyn_cast<NamespaceDecl>(D))
159169
IsAnonymousNamespace = N->isAnonymousNamespace();
160170
return !PublicOnly ||
161171
(!IsInAnonymousNamespace && !IsAnonymousNamespace &&
162172
isPublic(D->getAccessUnsafe(), D->getLinkageInternal()));
163173
}
164174

175+
// handles TypedefDecl and TypeAliasDecl
176+
static
177+
bool
178+
shouldSerializeInfo(
179+
bool PublicOnly,
180+
bool IsInAnonymousNamespace,
181+
TypedefNameDecl const* D)
182+
{
183+
if(! PublicOnly)
184+
return true;
185+
if(IsInAnonymousNamespace)
186+
return false;
187+
if(auto const* N = dyn_cast<NamespaceDecl>(D))
188+
{
189+
if(N->isAnonymousNamespace())
190+
return false;
191+
}
192+
if(D->getAccessUnsafe() == AccessSpecifier::AS_private)
193+
return false;
194+
return true;
195+
}
196+
165197
// The InsertChild functions insert the given info into the given scope using
166198
// the method appropriate for that type. Some types are moved into the
167199
// appropriate vector, while other types have Reference objects generated to
@@ -611,9 +643,17 @@ emitInfo(const RecordDecl* D, const FullComment* FC, int LineNumber,
611643
return { std::move(I), std::move(Parent) };
612644
}
613645

614-
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
615-
emitInfo(const FunctionDecl* D, const FullComment* FC, int LineNumber,
616-
llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
646+
std::pair<
647+
std::unique_ptr<Info>,
648+
std::unique_ptr<Info>>
649+
emitInfo(
650+
FunctionDecl const* D,
651+
FullComment const* FC,
652+
int LineNumber,
653+
llvm::StringRef File,
654+
bool IsFileInRootDir,
655+
bool PublicOnly)
656+
{
617657
FunctionInfo Func;
618658
bool IsInAnonymousNamespace = false;
619659
populateFunctionInfo(Func, D, FC, LineNumber, File, IsFileInRootDir,
@@ -655,9 +695,17 @@ emitInfo(const CXXMethodDecl* D, const FullComment* FC, int LineNumber,
655695
return { nullptr, MakeAndInsertIntoParent<FunctionInfo&&>(std::move(Func)) };
656696
}
657697

658-
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
659-
emitInfo(const TypedefDecl* D, const FullComment* FC, int LineNumber,
660-
StringRef File, bool IsFileInRootDir, bool PublicOnly) {
698+
std::pair<
699+
std::unique_ptr<Info>,
700+
std::unique_ptr<Info>>
701+
emitInfo(
702+
const TypedefDecl* D,
703+
const FullComment* FC,
704+
int LineNumber,
705+
StringRef File,
706+
bool IsFileInRootDir,
707+
bool PublicOnly)
708+
{
661709
TypedefInfo Info;
662710

663711
bool IsInAnonymousNamespace = false;
@@ -681,9 +729,17 @@ emitInfo(const TypedefDecl* D, const FullComment* FC, int LineNumber,
681729

682730
// A type alias is a C++ "using" declaration for a type. It gets mapped to a
683731
// TypedefInfo with the IsUsing flag set.
684-
std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
685-
emitInfo(const TypeAliasDecl* D, const FullComment* FC, int LineNumber,
686-
StringRef File, bool IsFileInRootDir, bool PublicOnly) {
732+
std::pair<
733+
std::unique_ptr<Info>,
734+
std::unique_ptr<Info>>
735+
emitInfo(
736+
const TypeAliasDecl* D,
737+
const FullComment* FC,
738+
int LineNumber,
739+
StringRef File,
740+
bool IsFileInRootDir,
741+
bool PublicOnly)
742+
{
687743
TypedefInfo Info;
688744

689745
bool IsInAnonymousNamespace = false;

0 commit comments

Comments
 (0)