Skip to content

Commit b32fa17

Browse files
committed
Keep stable name for external symbols
1 parent 205a1e8 commit b32fa17

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

cpp2rust/converter/converter_lib.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,19 +324,24 @@ unsigned GetAnonIndex(const clang::NamedDecl *decl) {
324324
return 0;
325325
}
326326

327-
std::string GetID(const clang::Decl *decl) {
328-
assert(decl);
329-
const auto file_name = GetFileName(decl);
330-
const auto line_num = GetLineNumber(decl);
331-
const auto column_num = GetColumnNumber(decl);
327+
static std::string GetLocationID(const clang::Decl *decl) {
328+
return GetFileName(decl) + std::to_string(GetLineNumber(decl)) +
329+
std::to_string(GetColumnNumber(decl));
330+
}
331+
332+
static std::string GetParamSignature(const clang::Decl *decl) {
332333
std::string args;
333334
if (auto fdecl = clang::dyn_cast<clang::FunctionDecl>(decl)) {
334335
for (unsigned i = 0; i < fdecl->getNumParams(); ++i) {
335336
args += fdecl->getParamDecl(i)->getType().getAsString();
336337
}
337338
}
338-
return file_name + std::to_string(line_num) + std::to_string(column_num) +
339-
args;
339+
return args;
340+
}
341+
342+
std::string GetID(const clang::Decl *decl) {
343+
assert(decl);
344+
return GetLocationID(decl) + GetParamSignature(decl);
340345
}
341346

342347
static std::unordered_map<std::string, size_t> type_mapping;
@@ -360,7 +365,10 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) {
360365
if (!clang::isa<clang::CXXMethodDecl>(fn)) {
361366
auto mangled =
362367
clang::ASTNameGenerator(decl->getASTContext()).getName(decl) +
363-
GetID(decl);
368+
GetParamSignature(decl);
369+
if (fn->getFormalLinkage() == clang::Linkage::Internal) {
370+
mangled += GetLocationID(decl);
371+
}
364372
auto id =
365373
type_mapping.try_emplace(mangled, type_mapping.size()).first->second;
366374
name += '_';

0 commit comments

Comments
 (0)