@@ -8966,16 +8966,25 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8966
8966
}
8967
8967
8968
8968
namespace {
8969
+ ValueDecl *getKnownSingleDecl (ASTContext &SwiftContext, StringRef DeclName) {
8970
+ SmallVector<ValueDecl *, 1 > decls;
8971
+ SwiftContext.lookupInSwiftModule (DeclName, decls);
8972
+ assert (decls.size () < 2 );
8973
+ if (decls.size () != 1 ) return nullptr ;
8974
+ return decls[0 ];
8975
+ }
8976
+
8969
8977
class SwiftifyInfoPrinter {
8970
8978
public:
8971
8979
static const ssize_t SELF_PARAM_INDEX = -2 ;
8972
8980
static const ssize_t RETURN_VALUE_INDEX = -1 ;
8973
8981
clang::ASTContext &ctx;
8974
8982
ASTContext &SwiftContext;
8975
8983
llvm::raw_ostream &out;
8984
+ MacroDecl &SwiftifyImportDecl;
8976
8985
bool firstParam = true ;
8977
- SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out)
8978
- : ctx(ctx), SwiftContext(SwiftContext), out(out) {
8986
+ SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out, MacroDecl &SwiftifyImportDecl )
8987
+ : ctx(ctx), SwiftContext(SwiftContext), out(out), SwiftifyImportDecl(SwiftifyImportDecl) {
8979
8988
out << " @_SwiftifyImport(" ;
8980
8989
}
8981
8990
~SwiftifyInfoPrinter () { out << " )" ; }
@@ -9033,22 +9042,23 @@ class SwiftifyInfoPrinter {
9033
9042
}
9034
9043
9035
9044
void printAvailability () {
9045
+ if (!hasMacroParameter (" spanAvailability" ))
9046
+ return ;
9036
9047
printSeparator ();
9037
9048
out << " spanAvailability: " ;
9038
9049
printAvailabilityOfType (" Span" );
9039
9050
}
9040
9051
9041
9052
private:
9042
- ValueDecl *getDecl (StringRef DeclName) {
9043
- SmallVector<ValueDecl *, 1 > decls;
9044
- SwiftContext.lookupInSwiftModule (DeclName, decls);
9045
- assert (decls.size () == 1 );
9046
- if (decls.size () != 1 ) return nullptr ;
9047
- return decls[0 ];
9053
+ bool hasMacroParameter (StringRef ParamName) {
9054
+ for (auto *Param : *SwiftifyImportDecl.parameterList )
9055
+ if (Param->getArgumentName ().str () == ParamName)
9056
+ return true ;
9057
+ return false ;
9048
9058
}
9049
9059
9050
9060
void printAvailabilityOfType (StringRef Name) {
9051
- ValueDecl *D = getDecl ( Name);
9061
+ ValueDecl *D = getKnownSingleDecl (SwiftContext, Name);
9052
9062
out << " \" " ;
9053
9063
llvm::SaveAndRestore<bool > hasAvailbilitySeparatorRestore (firstParam, true );
9054
9064
for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ true )) {
@@ -9213,6 +9223,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9213
9223
if (ClangDecl->getNumParams () != MappedDecl->getParameters ()->size ())
9214
9224
return ;
9215
9225
9226
+ MacroDecl *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(getKnownSingleDecl (SwiftContext, " _SwiftifyImport" ));
9227
+ if (!SwiftifyImportDecl)
9228
+ return ;
9229
+
9216
9230
{
9217
9231
UnaliasedInstantiationVisitor visitor;
9218
9232
visitor.TraverseType (ClangDecl->getType ());
@@ -9241,7 +9255,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9241
9255
}
9242
9256
return false ;
9243
9257
};
9244
- SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out);
9258
+ SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out, *SwiftifyImportDecl );
9245
9259
Type swiftReturnTy;
9246
9260
if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
9247
9261
swiftReturnTy = funcDecl->getResultInterfaceType ();
0 commit comments