Skip to content

Commit 7664582

Browse files
authored
Merge pull request swiftlang#76901 from rintaro/astbridging-files-tweak
[ASTBridging] Move some code to MiscBridging.cpp
2 parents 565c97a + bd8ee9e commit 7664582

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -459,44 +459,3 @@ BridgedSILGenNameAttr BridgedSILGenNameAttr_createParsed(
459459
cRange.unbridged(), /*Implicit=*/false);
460460
}
461461

462-
static bool declMetatypesInitialized = false;
463-
464-
// Filled in by class registration in initializeSwiftModules().
465-
static SwiftMetatype declMetatypes[(unsigned)DeclKind::Last_Decl + 1];
466-
467-
// Does return null if initializeSwiftModules() is never called.
468-
SwiftMetatype Decl::getDeclMetatype(DeclKind kind) {
469-
SwiftMetatype metatype = declMetatypes[(unsigned)kind];
470-
if (declMetatypesInitialized && !metatype) {
471-
llvm::errs() << "Decl " << getKindName(kind) << " not registered\n";
472-
abort();
473-
}
474-
return metatype;
475-
}
476-
477-
/// Registers the metatype of a Decl class.
478-
/// Called by initializeSwiftModules().
479-
void registerBridgedDecl(BridgedStringRef bridgedClassName,
480-
SwiftMetatype metatype) {
481-
declMetatypesInitialized = true;
482-
483-
auto declKind = llvm::StringSwitch<std::optional<swift::DeclKind>>(
484-
bridgedClassName.unbridged())
485-
#define DECL(Id, Parent) .Case(#Id "Decl", swift::DeclKind::Id)
486-
#include "swift/AST/DeclNodes.def"
487-
.Default(std::nullopt);
488-
489-
if (!declKind) {
490-
llvm::errs() << "Unknown Decl class " << bridgedClassName.unbridged()
491-
<< "\n";
492-
abort();
493-
}
494-
declMetatypes[(unsigned)declKind.value()] = metatype;
495-
}
496-
497-
BridgedOwnedString BridgedDeclObj::getDebugDescription() const {
498-
std::string str;
499-
llvm::raw_string_ostream os(str);
500-
unbridged()->print(os);
501-
return str;
502-
}

lib/AST/Bridging/MiscBridging.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)