@@ -9023,16 +9023,25 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
9023
9023
}
9024
9024
9025
9025
namespace {
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
+
9026
9034
class SwiftifyInfoPrinter {
9027
9035
public:
9028
9036
static const ssize_t SELF_PARAM_INDEX = -2 ;
9029
9037
static const ssize_t RETURN_VALUE_INDEX = -1 ;
9030
9038
clang::ASTContext &ctx;
9031
9039
ASTContext &SwiftContext;
9032
9040
llvm::raw_ostream &out;
9041
+ MacroDecl &SwiftifyImportDecl;
9033
9042
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) {
9036
9045
out << " @_SwiftifyImport(" ;
9037
9046
}
9038
9047
~SwiftifyInfoPrinter () { out << " )" ; }
@@ -9090,22 +9099,23 @@ class SwiftifyInfoPrinter {
9090
9099
}
9091
9100
9092
9101
void printAvailability () {
9102
+ if (!hasMacroParameter (" spanAvailability" ))
9103
+ return ;
9093
9104
printSeparator ();
9094
9105
out << " spanAvailability: " ;
9095
9106
printAvailabilityOfType (" Span" );
9096
9107
}
9097
9108
9098
9109
private:
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 ;
9105
9115
}
9106
9116
9107
9117
void printAvailabilityOfType (StringRef Name) {
9108
- ValueDecl *D = getDecl ( Name);
9118
+ ValueDecl *D = getKnownSingleDecl (SwiftContext, Name);
9109
9119
out << " \" " ;
9110
9120
llvm::SaveAndRestore<bool > hasAvailbilitySeparatorRestore (firstParam, true );
9111
9121
for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ true )) {
@@ -9269,6 +9279,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9269
9279
if (ClangDecl->getNumParams () != MappedDecl->getParameters ()->size ())
9270
9280
return ;
9271
9281
9282
+ MacroDecl *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(getKnownSingleDecl (SwiftContext, " _SwiftifyImport" ));
9283
+ if (!SwiftifyImportDecl)
9284
+ return ;
9285
+
9272
9286
{
9273
9287
UnaliasedInstantiationVisitor visitor;
9274
9288
visitor.TraverseType (ClangDecl->getType ());
@@ -9297,7 +9311,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9297
9311
}
9298
9312
return false ;
9299
9313
};
9300
- SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out);
9314
+ SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out, *SwiftifyImportDecl );
9301
9315
Type swiftReturnTy;
9302
9316
if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
9303
9317
swiftReturnTy = funcDecl->getResultInterfaceType ();
0 commit comments