@@ -9023,16 +9023,25 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
90239023}
90249024
90259025namespace {
9026+ ValueDecl *getKnownSingleDecl (ASTContext &SwiftContext, StringRef DeclName) {
9027+ SmallVector<ValueDecl *, 1 > decls;
9028+ SwiftContext.lookupInSwiftModule (DeclName, decls);
9029+ assert (decls.size () < 2 );
9030+ if (decls.size () != 1 ) return nullptr ;
9031+ return decls[0 ];
9032+ }
9033+
90269034class SwiftifyInfoPrinter {
90279035public:
90289036 static const ssize_t SELF_PARAM_INDEX = -2 ;
90299037 static const ssize_t RETURN_VALUE_INDEX = -1 ;
90309038 clang::ASTContext &ctx;
90319039 ASTContext &SwiftContext;
90329040 llvm::raw_ostream &out;
9041+ MacroDecl &SwiftifyImportDecl;
90339042 bool firstParam = true ;
9034- SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out)
9035- : ctx(ctx), SwiftContext(SwiftContext), out(out) {
9043+ SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out, MacroDecl &SwiftifyImportDecl )
9044+ : ctx(ctx), SwiftContext(SwiftContext), out(out), SwiftifyImportDecl(SwiftifyImportDecl) {
90369045 out << " @_SwiftifyImport(" ;
90379046 }
90389047 ~SwiftifyInfoPrinter () { out << " )" ; }
@@ -9090,22 +9099,23 @@ class SwiftifyInfoPrinter {
90909099 }
90919100
90929101 void printAvailability () {
9102+ if (!hasMacroParameter (" spanAvailability" ))
9103+ return ;
90939104 printSeparator ();
90949105 out << " spanAvailability: " ;
90959106 printAvailabilityOfType (" Span" );
90969107 }
90979108
90989109private:
9099- ValueDecl *getDecl (StringRef DeclName) {
9100- SmallVector<ValueDecl *, 1 > decls;
9101- SwiftContext.lookupInSwiftModule (DeclName, decls);
9102- assert (decls.size () == 1 );
9103- if (decls.size () != 1 ) return nullptr ;
9104- return decls[0 ];
9110+ bool hasMacroParameter (StringRef ParamName) {
9111+ for (auto *Param : *SwiftifyImportDecl.parameterList )
9112+ if (Param->getArgumentName ().str () == ParamName)
9113+ return true ;
9114+ return false ;
91059115 }
91069116
91079117 void printAvailabilityOfType (StringRef Name) {
9108- ValueDecl *D = getDecl ( Name);
9118+ ValueDecl *D = getKnownSingleDecl (SwiftContext, Name);
91099119 out << " \" " ;
91109120 llvm::SaveAndRestore<bool > hasAvailbilitySeparatorRestore (firstParam, true );
91119121 for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ true )) {
@@ -9269,6 +9279,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
92699279 if (ClangDecl->getNumParams () != MappedDecl->getParameters ()->size ())
92709280 return ;
92719281
9282+ MacroDecl *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(getKnownSingleDecl (SwiftContext, " _SwiftifyImport" ));
9283+ if (!SwiftifyImportDecl)
9284+ return ;
9285+
92729286 {
92739287 UnaliasedInstantiationVisitor visitor;
92749288 visitor.TraverseType (ClangDecl->getType ());
@@ -9297,7 +9311,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
92979311 }
92989312 return false ;
92999313 };
9300- SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out);
9314+ SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out, *SwiftifyImportDecl );
93019315 Type swiftReturnTy;
93029316 if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
93039317 swiftReturnTy = funcDecl->getResultInterfaceType ();
0 commit comments