@@ -9147,6 +9147,7 @@ class SwiftifyInfoPrinter {
91479147 llvm::raw_ostream &out;
91489148 MacroDecl &SwiftifyImportDecl;
91499149 bool firstParam = true ;
9150+ llvm::StringMap<std::string> typeMapping;
91509151 SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out, MacroDecl &SwiftifyImportDecl)
91519152 : ctx(ctx), SwiftContext(SwiftContext), out(out), SwiftifyImportDecl(SwiftifyImportDecl) {
91529153 out << " @_SwiftifyImport(" ;
@@ -9192,14 +9193,24 @@ class SwiftifyInfoPrinter {
91929193 out << " )" ;
91939194 }
91949195
9195- void printTypeMapping (const llvm::StringMap<std::string> &mapping) {
9196+ bool registerStdSpanTypeMapping (Type swiftType, const clang::QualType clangType) {
9197+ const auto *decl = clangType->getAsTagDecl ();
9198+ if (decl && decl->isInStdNamespace () && decl->getName () == " span" ) {
9199+ typeMapping.insert (std::make_pair (
9200+ swiftType->getString (), swiftType->getDesugaredType ()->getString ()));
9201+ return true ;
9202+ }
9203+ return false ;
9204+ }
9205+
9206+ void printTypeMapping () {
91969207 printSeparator ();
91979208 out << " typeMappings: [" ;
9198- if (mapping .empty ()) {
9209+ if (typeMapping .empty ()) {
91999210 out << " :]" ;
92009211 return ;
92019212 }
9202- llvm::interleaveComma (mapping , out, [&](const auto &entry) {
9213+ llvm::interleaveComma (typeMapping , out, [&](const auto &entry) {
92039214 out << ' "' << entry.getKey () << " \" : \" " << entry.getValue () << ' "' ;
92049215 });
92059216 out << " ]" ;
@@ -9517,19 +9528,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95179528 bool attachMacro = false ;
95189529 {
95199530 llvm::raw_svector_ostream out (MacroString);
9520- llvm::StringMap<std::string> typeMapping;
9521-
9522- auto registerStdSpanTypeMapping =
9523- [&typeMapping](Type swiftType, const clang::QualType clangType) {
9524- const auto *decl = clangType->getAsTagDecl ();
9525- if (decl && decl->isInStdNamespace () && decl->getName () == " span" ) {
9526- typeMapping.insert (
9527- std::make_pair (swiftType->getString (),
9528- swiftType->getDesugaredType ()->getString ()));
9529- return true ;
9530- }
9531- return false ;
9532- };
9531+
95339532 SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out, *SwiftifyImportDecl);
95349533 Type swiftReturnTy;
95359534 if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
@@ -9538,7 +9537,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95389537 swiftReturnTy = ctorDecl->getResultInterfaceType ();
95399538 else
95409539 ABORT (" Unexpected AbstractFunctionDecl subclass." );
9541- bool returnIsStdSpan = registerStdSpanTypeMapping (
9540+ bool returnIsStdSpan = printer. registerStdSpanTypeMapping (
95429541 swiftReturnTy, ClangDecl->getReturnType ());
95439542 auto *CAT = ClangDecl->getReturnType ()->getAs <clang::CountAttributedType>();
95449543 if (SwiftifiableCAT (getClangASTContext (), CAT, swiftReturnTy)) {
@@ -9596,8 +9595,8 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95969595 << " ' on parameter '" << *clangParam << " '\n " );
95979596 attachMacro = paramHasBoundsInfo = true ;
95989597 }
9599- bool paramIsStdSpan = registerStdSpanTypeMapping (
9600- swiftParamTy, clangParamTy);
9598+ bool paramIsStdSpan =
9599+ printer. registerStdSpanTypeMapping ( swiftParamTy, clangParamTy);
96019600 paramHasBoundsInfo |= paramIsStdSpan;
96029601
96039602 bool paramHasLifetimeInfo = false ;
@@ -9629,7 +9628,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
96299628 attachMacro = true ;
96309629 }
96319630 printer.printAvailability ();
9632- printer.printTypeMapping (typeMapping );
9631+ printer.printTypeMapping ();
96339632 }
96349633
96359634 if (attachMacro) {
0 commit comments