@@ -18,18 +18,15 @@ class SwiftDispatcher;
18
18
19
19
// This class is tasked with assigning unique names to entities that need it (non-local
20
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
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.
28
25
//
29
26
// * 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
31
28
// 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
33
30
class SwiftMangler : private swift ::TypeVisitor<SwiftMangler, SwiftMangledName>,
34
31
private swift::DeclVisitor<SwiftMangler, SwiftMangledName> {
35
32
using TypeVisitor = swift::TypeVisitor<SwiftMangler, SwiftMangledName>;
@@ -117,6 +114,12 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,
117
114
SwiftMangledName visitTypeDiscriminatedValueDecl (const swift::ValueDecl* decl);
118
115
};
119
116
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
120
123
class SwiftTrapMangler : public SwiftMangler {
121
124
public:
122
125
explicit SwiftTrapMangler (SwiftDispatcher& dispatcher) : dispatcher(dispatcher) {}
@@ -128,6 +131,8 @@ class SwiftTrapMangler : public SwiftMangler {
128
131
SwiftDispatcher& dispatcher;
129
132
};
130
133
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.
131
136
class SwiftRecursiveMangler : public SwiftMangler {
132
137
SwiftMangledName fetch (const swift::Decl* decl) override ;
133
138
SwiftMangledName fetch (const swift::TypeBase* type) override ;
0 commit comments