Skip to content

Commit edb8222

Browse files
committed
Swift: update comments to the mangler
1 parent 70ff401 commit edb8222

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

swift/extractor/mangler/SwiftMangler.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@ class SwiftDispatcher;
1818

1919
// This class is tasked with assigning unique names to entities that need it (non-local
2020
// 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
21+
// This uses the Template Method design pattern (or Non-Virtual Interface). The actual behavior
22+
// when the identity depends on some other entity (like the parent of a declaration, or the
23+
// declaration introducing a user type) depends on a private virtual fetch method. See below for
24+
// the specific implementations.
2825
//
2926
// * 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
27+
// * declarations usually use a fetch of their declaration context as first element, followed
3128
// 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
29+
// * user defined types have a name that is a simple wrapper around a fetch of their declaration
3330
class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
3431
private swift::DeclVisitor<SwiftMangler, SwiftMangledName> {
3532
using TypeVisitor = swift::TypeVisitor<SwiftMangler, SwiftMangledName>;
@@ -117,6 +114,12 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
117114
SwiftMangledName visitTypeDiscriminatedValueDecl(const swift::ValueDecl* decl);
118115
};
119116

117+
// This implementation is indented for use in defining trap keys. In this case fetching gives
118+
// a [trap id-ref][1] is used, using the dispatcher to give us a label reference to that entity.
119+
// Because that entity will also generally have a mangled name, it is important that this does not
120+
// lead to any recursive loop (which is checked at runtime within the dispatcher).
121+
//
122+
// [1]: https://github.com/github/codeql-core/blob/main/wiki/extractors/trap.md#ids
120123
class SwiftTrapMangler : public SwiftMangler {
121124
public:
122125
explicit SwiftTrapMangler(SwiftDispatcher& dispatcher) : dispatcher(dispatcher) {}
@@ -128,6 +131,8 @@ class SwiftTrapMangler : public SwiftMangler {
128131
SwiftDispatcher& dispatcher;
129132
};
130133

134+
// In this implementation, fetching gives a hash of the mangled name itself, leading to a direct
135+
// recursion. This is intended for use in trap file names.
131136
class SwiftRecursiveMangler : public SwiftMangler {
132137
SwiftMangledName fetch(const swift::Decl* decl) override;
133138
SwiftMangledName fetch(const swift::TypeBase* type) override;

0 commit comments

Comments
 (0)