Skip to content

Commit 3f7c4de

Browse files
committed
Swift: add a header comment to SwiftMangler
1 parent d81dc27 commit 3f7c4de

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

swift/extractor/mangler/SwiftMangler.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ namespace codeql {
1616

1717
class SwiftDispatcher;
1818

19+
// This class is tasked with assigning unique names to entities that need it (non-local
20+
// declarations and types), to be used as trap keys.
21+
// When the identity depends on some other entity (like the parent of a declaration, or the
22+
// declaration introducing a user type) a [trap id-ref][1] is used, using the dispatcher to give us
23+
// a label reference to that entity. Because that entity will also generally have a mangled name,
24+
// it is important that this does not lead to any recursive loop (which is checked at runtime
25+
// within the dispatcher).
26+
//
27+
// [1]: https://github.com/github/codeql-core/blob/main/wiki/extractors/trap.md#ids
28+
//
29+
// * all names are prefixed with the name of the entity class (for example `ParamDecl_`)
30+
// * declarations usually use a reference to their declaration context as first element, followed
31+
// by whatever distinguishes them within that context (the name, or the signature for function)
32+
// * user defined types have a name that is a simple wrapper around a reference to their declaration
1933
class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
2034
private swift::DeclVisitor<SwiftMangler, SwiftMangledName> {
2135
using TypeVisitor = swift::TypeVisitor<SwiftMangler, SwiftMangledName>;
@@ -26,7 +40,6 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
2640

2741
static SwiftMangledName mangleModuleName(std::string_view name);
2842

29-
// TODO actual visit
3043
SwiftMangledName mangleDecl(const swift::Decl& decl) {
3144
return DeclVisitor::visit(const_cast<swift::Decl*>(&decl));
3245
}

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <swift/AST/ParameterList.h>
55
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
66
#include <swift/AST/PropertyWrappers.h>
7-
#include <swift/AST/ASTMangler.h>
87

98
namespace codeql {
109
namespace {

0 commit comments

Comments
 (0)