@@ -8988,16 +8988,25 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8988
8988
}
8989
8989
8990
8990
namespace {
8991
+ ValueDecl *getKnownSingleDecl (ASTContext &SwiftContext, StringRef DeclName) {
8992
+ SmallVector<ValueDecl *, 1 > decls;
8993
+ SwiftContext.lookupInSwiftModule (DeclName, decls);
8994
+ assert (decls.size () < 2 );
8995
+ if (decls.size () != 1 ) return nullptr ;
8996
+ return decls[0 ];
8997
+ }
8998
+
8991
8999
class SwiftifyInfoPrinter {
8992
9000
public:
8993
9001
static const ssize_t SELF_PARAM_INDEX = -2 ;
8994
9002
static const ssize_t RETURN_VALUE_INDEX = -1 ;
8995
9003
clang::ASTContext &ctx;
8996
9004
ASTContext &SwiftContext;
8997
9005
llvm::raw_ostream &out;
9006
+ MacroDecl &SwiftifyImportDecl;
8998
9007
bool firstParam = true ;
8999
- SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out)
9000
- : ctx(ctx), SwiftContext(SwiftContext), out(out) {
9008
+ SwiftifyInfoPrinter (clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out, MacroDecl &SwiftifyImportDecl )
9009
+ : ctx(ctx), SwiftContext(SwiftContext), out(out), SwiftifyImportDecl(SwiftifyImportDecl) {
9001
9010
out << " @_SwiftifyImport(" ;
9002
9011
}
9003
9012
~SwiftifyInfoPrinter () { out << " )" ; }
@@ -9064,27 +9073,14 @@ class SwiftifyInfoPrinter {
9064
9073
9065
9074
private:
9066
9075
bool hasMacroParameter (StringRef ParamName) {
9067
- ValueDecl *D = getDecl (" _SwiftifyImport" );
9068
- auto *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(D);
9069
- assert (SwiftifyImportDecl);
9070
- if (!SwiftifyImportDecl)
9071
- return false ;
9072
- for (auto *Param : *SwiftifyImportDecl->parameterList )
9076
+ for (auto *Param : *SwiftifyImportDecl.parameterList )
9073
9077
if (Param->getArgumentName ().str () == ParamName)
9074
9078
return true ;
9075
9079
return false ;
9076
9080
}
9077
9081
9078
- ValueDecl *getDecl (StringRef DeclName) {
9079
- SmallVector<ValueDecl *, 1 > decls;
9080
- SwiftContext.lookupInSwiftModule (DeclName, decls);
9081
- assert (decls.size () == 1 );
9082
- if (decls.size () != 1 ) return nullptr ;
9083
- return decls[0 ];
9084
- }
9085
-
9086
9082
void printAvailabilityOfType (StringRef Name) {
9087
- ValueDecl *D = getDecl ( Name);
9083
+ ValueDecl *D = getKnownSingleDecl (SwiftContext, Name);
9088
9084
out << " \" " ;
9089
9085
llvm::SaveAndRestore<bool > hasAvailbilitySeparatorRestore (firstParam, true );
9090
9086
for (auto attr : D->getSemanticAvailableAttrs (/* includingInactive=*/ true )) {
@@ -9248,6 +9244,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9248
9244
if (ClangDecl->getNumParams () != MappedDecl->getParameters ()->size ())
9249
9245
return ;
9250
9246
9247
+ MacroDecl *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(getKnownSingleDecl (SwiftContext, " _SwiftifyImport" ));
9248
+ if (!SwiftifyImportDecl)
9249
+ return ;
9250
+
9251
9251
{
9252
9252
UnaliasedInstantiationVisitor visitor;
9253
9253
visitor.TraverseType (ClangDecl->getType ());
@@ -9276,7 +9276,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9276
9276
}
9277
9277
return false ;
9278
9278
};
9279
- SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out);
9279
+ SwiftifyInfoPrinter printer (getClangASTContext (), SwiftContext, out, *SwiftifyImportDecl );
9280
9280
Type swiftReturnTy;
9281
9281
if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
9282
9282
swiftReturnTy = funcDecl->getResultInterfaceType ();
0 commit comments