Skip to content

Commit

Permalink
Merge pull request #7 from giulianobelinassi/single-func-decl-in-header
Browse files Browse the repository at this point in the history
Avoid issuing multiple declarations of same function
  • Loading branch information
giulianobelinassi authored Mar 28, 2024
2 parents 336386d + 03f03d3 commit 56087bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libcextract/HeaderGenerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@ static bool Contains(const std::vector<ExternalizerLogEntry> &v, const std::stri
bool HeaderGeneration::Run_Analysis(const std::vector<ExternalizerLogEntry> &set)
{
ASTUnit::top_level_iterator it;
std::unordered_set<std::string> nameset;

for (it = AST->top_level_begin(); it != AST->top_level_end(); ++it) {
Decl *decl = *it;

if (FunctionDecl *fdecl = dyn_cast<FunctionDecl>(decl)) {
if (Contains(set, fdecl->getNameAsString())) {
const std::string &fname = fdecl->getNameAsString();
/* If the function was already issued, then do not issue it again. */
if (Contains(set, fname) && nameset.find(fname) == nameset.end()) {
if (fdecl->doesThisDeclarationHaveABody() && fdecl->hasBody()) {
Stmt *body = fdecl->getBody();
fdecl->setRangeEnd(body->getBeginLoc().getLocWithOffset(-1));
fdecl->setBody(nullptr);
}
Closure.Add_Single_Decl(fdecl);
nameset.insert(fname);
}
}
}
Expand Down

0 comments on commit 56087bf

Please sign in to comment.