Skip to content

Commit

Permalink
Eliminate duplication of code for adding empty argument names.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehme authored and zoecarver committed Oct 9, 2020
1 parent 3066e16 commit 5644137
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/ClangImporter/ImportName.cpp
Expand Up @@ -1366,6 +1366,16 @@ static bool suppressFactoryMethodAsInit(const clang::ObjCMethodDecl *method,
initKind == CtorInitializerKind::ConvenienceFactory);
}

static void
addEmptyArgNamesForCxxFunc(const clang::FunctionDecl *funcDecl,
SmallVectorImpl<StringRef> &argumentNames) {
for (size_t i = 0; i < funcDecl->param_size(); ++i) {
argumentNames.push_back(StringRef());
}
if (funcDecl->isVariadic())
argumentNames.push_back(StringRef());
}

ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
ImportNameVersion version,
clang::DeclarationName givenName) {
Expand Down Expand Up @@ -1604,13 +1614,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
isFunction = true;
result.info.initKind = CtorInitializerKind::Designated;
baseName = "init";
// Add empty argument names.
if (auto ctor = dyn_cast<clang::CXXConstructorDecl>(D)) {
for (size_t i = 0; i < ctor->param_size(); ++i) {
argumentNames.push_back(StringRef());
}
if (ctor->isVariadic())
argumentNames.push_back(StringRef());
addEmptyArgNamesForCxxFunc(ctor, argumentNames);
}
break;

Expand Down Expand Up @@ -1684,16 +1689,9 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
}
}

// For C functions, create empty argument names.
if (auto function = dyn_cast<clang::FunctionDecl>(D)) {
isFunction = true;
params = {function->param_begin(), function->param_end()};
for (auto param : params) {
(void)param;
argumentNames.push_back(StringRef());
}
if (function->isVariadic())
argumentNames.push_back(StringRef());
addEmptyArgNamesForCxxFunc(function, argumentNames);
}
break;

Expand Down

0 comments on commit 5644137

Please sign in to comment.