Skip to content

Commit 850a90d

Browse files
committed
Swift: Change the declaration names generated by the extractor to match the output of the Swift compiler.
1 parent fc7e0ec commit 850a90d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

swift/extractor/visitors/DeclVisitor.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ class DeclVisitor : public AstVisitorBase<DeclVisitor> {
258258
void emitAbstractFunctionDecl(swift::AbstractFunctionDecl* decl,
259259
TrapLabel<AbstractFunctionDeclTag> label) {
260260
assert(decl->hasParameterList() && "Expect functions to have a parameter list");
261-
auto name = !decl->hasName() || decl->getName().isSpecial() ? "(unnamed function decl)"
262-
: decl->getNameStr().str();
261+
auto name = !decl->hasName() ? "(unnamed function decl)" : constructName(decl->getName());
263262
dispatcher_.emit(AbstractFunctionDeclsTrap{label, name});
264263
if (auto body = decl->getBody()) {
265264
dispatcher_.emit(AbstractFunctionDeclBodiesTrap{label, dispatcher_.fetchLabel(body)});
@@ -355,6 +354,22 @@ class DeclVisitor : public AstVisitorBase<DeclVisitor> {
355354
emitValueDecl(decl, label);
356355
}
357356

357+
// Constructs a `std::string` of the form `f(x:y:)` for a declaration
358+
// like `func f(x first: Int, y second: Int) { }`
359+
std::string constructName(swift::DeclName declName) {
360+
std::string name = declName.getBaseName().userFacingName().str();
361+
name += "(";
362+
for (auto argName : declName.getArgumentNames()) {
363+
if (argName.empty()) {
364+
name += "_:";
365+
} else {
366+
name += argName.str().str() + ":";
367+
}
368+
}
369+
name += ")";
370+
return name;
371+
}
372+
358373
private:
359374
swift::Mangle::ASTMangler mangler;
360375
};

0 commit comments

Comments
 (0)