@@ -51,6 +51,52 @@ void BridgedTypeRepr_dump(void *type) { static_cast<TypeRepr *>(type)->dump(); }
5151
5252#pragma clang diagnostic pop
5353
54+ // ===----------------------------------------------------------------------===//
55+ // MARK: Metatype registration
56+ // ===----------------------------------------------------------------------===//
57+
58+ static bool declMetatypesInitialized = false ;
59+
60+ // Filled in by class registration in initializeSwiftModules().
61+ static SwiftMetatype declMetatypes[(unsigned )DeclKind::Last_Decl + 1 ];
62+
63+ // Does return null if initializeSwiftModules() is never called.
64+ SwiftMetatype Decl::getDeclMetatype (DeclKind kind) {
65+ SwiftMetatype metatype = declMetatypes[(unsigned )kind];
66+ if (declMetatypesInitialized && !metatype) {
67+ llvm::errs () << " Decl " << getKindName (kind) << " not registered\n " ;
68+ abort ();
69+ }
70+ return metatype;
71+ }
72+
73+ // / Registers the metatype of a Decl class.
74+ // / Called by initializeSwiftModules().
75+ void registerBridgedDecl (BridgedStringRef bridgedClassName,
76+ SwiftMetatype metatype) {
77+ declMetatypesInitialized = true ;
78+
79+ auto declKind = llvm::StringSwitch<std::optional<swift::DeclKind>>(
80+ bridgedClassName.unbridged ())
81+ #define DECL (Id, Parent ) .Case(#Id " Decl" , swift::DeclKind::Id)
82+ #include " swift/AST/DeclNodes.def"
83+ .Default (std::nullopt );
84+
85+ if (!declKind) {
86+ llvm::errs () << " Unknown Decl class " << bridgedClassName.unbridged ()
87+ << " \n " ;
88+ abort ();
89+ }
90+ declMetatypes[(unsigned )declKind.value ()] = metatype;
91+ }
92+
93+ BridgedOwnedString BridgedDeclObj::getDebugDescription () const {
94+ std::string str;
95+ llvm::raw_string_ostream os (str);
96+ unbridged ()->print (os);
97+ return str;
98+ }
99+
54100// ===----------------------------------------------------------------------===//
55101// MARK: Conformance
56102// ===----------------------------------------------------------------------===//
0 commit comments