@@ -9046,6 +9046,8 @@ class SwiftifyInfoPrinter {
9046
9046
clang::ASTContext &ctx;
9047
9047
llvm::raw_ostream &out;
9048
9048
bool firstParam = true ;
9049
+ llvm::StringMap<std::string> typeMapping;
9050
+
9049
9051
SwiftifyInfoPrinter (clang::ASTContext &ctx, llvm::raw_ostream &out)
9050
9052
: ctx(ctx), out(out) {
9051
9053
out << " @_SwiftifyImport(" ;
@@ -9091,14 +9093,24 @@ class SwiftifyInfoPrinter {
9091
9093
out << " )" ;
9092
9094
}
9093
9095
9094
- void printTypeMapping (const llvm::StringMap<std::string> &mapping) {
9096
+ bool registerStdSpanTypeMapping (Type swiftType, const clang::QualType clangType) {
9097
+ const auto *decl = clangType->getAsTagDecl ();
9098
+ if (decl && decl->isInStdNamespace () && decl->getName () == " span" ) {
9099
+ typeMapping.insert (std::make_pair (
9100
+ swiftType->getString (), swiftType->getDesugaredType ()->getString ()));
9101
+ return true ;
9102
+ }
9103
+ return false ;
9104
+ }
9105
+
9106
+ void printTypeMapping () {
9095
9107
printSeparator ();
9096
9108
out << " typeMappings: [" ;
9097
- if (mapping .empty ()) {
9109
+ if (typeMapping .empty ()) {
9098
9110
out << " :]" ;
9099
9111
return ;
9100
9112
}
9101
- llvm::interleaveComma (mapping , out, [&](const auto &entry) {
9113
+ llvm::interleaveComma (typeMapping , out, [&](const auto &entry) {
9102
9114
out << ' "' << entry.getKey () << " \" : \" " << entry.getValue () << ' "' ;
9103
9115
});
9104
9116
out << " ]" ;
@@ -9140,21 +9152,9 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
9140
9152
bool attachMacro = false ;
9141
9153
{
9142
9154
llvm::raw_svector_ostream out (MacroString);
9143
- llvm::StringMap<std::string> typeMapping;
9144
-
9145
- auto registerStdSpanTypeMapping =
9146
- [&typeMapping](Type swiftType, const clang::QualType clangType) {
9147
- const auto *decl = clangType->getAsTagDecl ();
9148
- if (decl && decl->isInStdNamespace () && decl->getName () == " span" ) {
9149
- typeMapping.insert (
9150
- std::make_pair (swiftType->getString (),
9151
- swiftType->getDesugaredType ()->getString ()));
9152
- return true ;
9153
- }
9154
- return false ;
9155
- };
9155
+
9156
9156
SwiftifyInfoPrinter printer (getClangASTContext (), out);
9157
- bool returnIsStdSpan = registerStdSpanTypeMapping (
9157
+ bool returnIsStdSpan = printer. registerStdSpanTypeMapping (
9158
9158
MappedDecl->getResultInterfaceType (), ClangDecl->getReturnType ());
9159
9159
if (auto CAT =
9160
9160
ClangDecl->getReturnType ()->getAs <clang::CountAttributedType>()) {
@@ -9176,7 +9176,7 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
9176
9176
printer.printCountedBy (CAT, index);
9177
9177
attachMacro = paramHasBoundsInfo = true ;
9178
9178
}
9179
- bool paramIsStdSpan = registerStdSpanTypeMapping (
9179
+ bool paramIsStdSpan = printer. registerStdSpanTypeMapping (
9180
9180
swiftParam->getInterfaceType (), clangParamTy);
9181
9181
paramHasBoundsInfo |= paramIsStdSpan;
9182
9182
@@ -9197,7 +9197,7 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
9197
9197
}
9198
9198
if (returnIsStdSpan && returnHasLifetimeInfo)
9199
9199
attachMacro = true ;
9200
- printer.printTypeMapping (typeMapping );
9200
+ printer.printTypeMapping ();
9201
9201
}
9202
9202
9203
9203
if (attachMacro)
0 commit comments