Skip to content

Commit

Permalink
Analyze C++ UsingType
Browse files Browse the repository at this point in the history
C++ have `UsingType` which is not traversed by TraverseType, so do it in
the Visitor.

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Aug 27, 2024
1 parent 4c858e7 commit 7d63231
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 27 additions & 2 deletions libcextract/Closure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ bool ClosureSet::Add_Decl_And_Prevs(Decl *decl)
return inserted;
}

/** Add a single decl to the set. */
bool ClosureSet::Add_Single_Decl(Decl *decl)
{
/* Do not insert builtin decls. */
if (Is_Builtin_Decl(decl)) {
return false;
}

Dependencies.insert(decl);
return true;
}

void DeclClosureVisitor::Compute_Closure_Of_Symbols(const std::vector<std::string> &names,
std::unordered_set<std::string> *matched_names)
{
Expand All @@ -61,7 +73,7 @@ void DeclClosureVisitor::Compute_Closure_Of_Symbols(const std::vector<std::strin
continue;
}

const std::string &decl_name = decl->getName().str();
const std::string &decl_name = decl->getNameAsString();
/* If the symbol name is in the set... */
if (setof_names.find(decl_name) != setof_names.end()) {
/* Mark that name as matched. */
Expand Down Expand Up @@ -292,7 +304,7 @@ bool DeclClosureVisitor::VisitEnumConstantDecl(EnumConstantDecl *decl)
bool DeclClosureVisitor::VisitTypedefNameDecl(TypedefNameDecl *decl)
{
// FIXME: Do we need to analyze the previous decls?
TRY_TO(TraverseType(decl->getUnderlyingType()));
TRY_TO(TraverseTypeLoc(decl->getTypeSourceInfo()->getTypeLoc()));
Closure.Add_Single_Decl(decl);

TRY_TO(AnalyzeDeclsWithSameBeginlocHelper(decl));
Expand Down Expand Up @@ -472,6 +484,19 @@ bool DeclClosureVisitor::VisitDeducedTemplateSpecializationType(
return TraverseDecl(template_name.getAsTemplateDecl());
}

bool DeclClosureVisitor::VisitUsingType(const UsingType *type)
{
UsingShadowDecl *decl = type->getFoundDecl();

// FIXME: Do we need a custom UsingShadowDeclVisitor?
TRY_TO(TraverseDecl(decl));

// Analyze underlying type.
TRY_TO(TraverseType(type->getUnderlyingType()));

return VISITOR_CONTINUE;
}

/* ----------- Other C++ stuff ----------- */

bool DeclClosureVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *nns)
Expand Down
13 changes: 3 additions & 10 deletions libcextract/Closure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ class ClosureSet
bool Add_Decl_And_Prevs(Decl *decl);

/** Add a single decl to the set. */
bool Add_Single_Decl(Decl *decl)
{
/* Do not insert builtin decls. */
if (Is_Builtin_Decl(decl)) {
return false;
}

Dependencies.insert(decl);
return true;
}
bool Add_Single_Decl(Decl *decl);

inline std::unordered_set<Decl *> &Get_Set(void)
{
Expand Down Expand Up @@ -236,6 +227,8 @@ class DeclClosureVisitor : public RecursiveASTVisitor<DeclClosureVisitor>
bool VisitDeducedTemplateSpecializationType(
const DeducedTemplateSpecializationType *type);

bool VisitUsingType(const UsingType *type);

/* ----------- Other C++ stuff ----------- */
bool TraverseNestedNameSpecifier(NestedNameSpecifier *nns);

Expand Down

0 comments on commit 7d63231

Please sign in to comment.