@@ -16,6 +16,20 @@ namespace codeql {
1616
1717class 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
1933class 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 }
0 commit comments