@@ -2021,9 +2021,12 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
2021
2021
2022
2022
auto &clangCtx = ImporterImpl.getClangASTContext ();
2023
2023
auto &clangSema = ImporterImpl.getClangSema ();
2024
+ assert (!method->isStatic () ||
2025
+ method->getNameInfo ().getName ().getCXXOverloadedOperator () ==
2026
+ clang::OO_Call);
2024
2027
// When emitting symbolic decls, the method might not have a concrete
2025
2028
// record type as this type.
2026
- if (ImporterImpl.importSymbolicCXXDecls &&
2029
+ if (ImporterImpl.importSymbolicCXXDecls && !method-> isStatic () &&
2027
2030
!method->getThisType ()->getPointeeCXXRecordDecl ())
2028
2031
return nullptr ;
2029
2032
@@ -2051,6 +2054,11 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
2051
2054
(forwardingMethodKind == ForwardingMethodKind::Virtual
2052
2055
? " __synthesizedVirtualCall_operatorStar"
2053
2056
: " __synthesizedBaseCall_operatorStar" )));
2057
+ } else if (name.getCXXOverloadedOperator () == clang::OO_Call) {
2058
+ assert (forwardingMethodKind != ForwardingMethodKind::Virtual);
2059
+ name = clang::DeclarationName (
2060
+ &ImporterImpl.getClangPreprocessor ().getIdentifierTable ().get (
2061
+ " __synthesizedBaseCall_operatorCall" ));
2054
2062
}
2055
2063
auto methodType = method->getType ();
2056
2064
// Check if we need to drop the reference from the return type
@@ -2093,7 +2101,8 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
2093
2101
clangCtx, const_cast <clang::CXXRecordDecl *>(derivedClass),
2094
2102
method->getSourceRange ().getBegin (),
2095
2103
clang::DeclarationNameInfo (name, clang::SourceLocation ()), methodType,
2096
- method->getTypeSourceInfo (), method->getStorageClass (),
2104
+ method->getTypeSourceInfo (),
2105
+ method->isStatic () ? clang::SC_None : method->getStorageClass (),
2097
2106
method->UsesFPIntrin (), /* isInline=*/ true , method->getConstexprKind (),
2098
2107
method->getSourceRange ().getEnd ());
2099
2108
newMethod->setImplicit ();
@@ -2140,14 +2149,19 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
2140
2149
thisExpr = conv.get ();
2141
2150
}
2142
2151
2152
+ auto memberExprTy =
2153
+ (method->isStatic () && method->getOverloadedOperator () ==
2154
+ clang::OverloadedOperatorKind::OO_Call)
2155
+ ? method->getType ()
2156
+ : clangCtx.BoundMemberTy ;
2143
2157
auto memberExpr = clangSema.BuildMemberExpr (
2144
2158
thisExpr, /* isArrow=*/ true , clang::SourceLocation (),
2145
2159
clang::NestedNameSpecifierLoc (), clang::SourceLocation (),
2146
2160
const_cast <clang::CXXMethodDecl *>(method),
2147
2161
clang::DeclAccessPair::make (const_cast <clang::CXXMethodDecl *>(method),
2148
2162
clang::AS_public),
2149
2163
/* HadMultipleCandidates=*/ false , method->getNameInfo (),
2150
- clangCtx. BoundMemberTy , clang::VK_PRValue, clang::OK_Ordinary);
2164
+ memberExprTy , clang::VK_PRValue, clang::OK_Ordinary);
2151
2165
llvm::SmallVector<clang::Expr *, 4 > args;
2152
2166
for (size_t i = 0 ; i < newMethod->getNumParams (); ++i) {
2153
2167
auto *param = newMethod->getParamDecl (i);
@@ -2158,7 +2172,7 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
2158
2172
clangCtx, param, false , type, clang::ExprValueKind::VK_LValue,
2159
2173
clang::SourceLocation ()));
2160
2174
}
2161
- auto memberCall = clangSema.BuildCallToMemberFunction (
2175
+ auto memberCall = clangSema.BuildCallExpr (
2162
2176
nullptr , memberExpr, clang::SourceLocation (), args,
2163
2177
clang::SourceLocation ());
2164
2178
if (!memberCall.isUsable ())
@@ -2264,6 +2278,27 @@ FuncDecl *SwiftDeclSynthesizer::makeVirtualMethod(
2264
2278
return result;
2265
2279
}
2266
2280
2281
+ // MARK: C++ operators
2282
+
2283
+ FuncDecl *SwiftDeclSynthesizer::makeInstanceToStaticOperatorCallMethod (
2284
+ const clang::CXXMethodDecl *clangMethodDecl) {
2285
+ auto clangDC = clangMethodDecl->getParent ();
2286
+ auto &ctx = ImporterImpl.SwiftContext ;
2287
+
2288
+ assert (clangMethodDecl->isStatic () && " Expected a static operator" );
2289
+
2290
+ auto newMethod = synthesizeCXXForwardingMethod (
2291
+ clangDC, clangDC, clangMethodDecl, ForwardingMethodKind::Base,
2292
+ ReferenceReturnTypeBehaviorForBaseMethodSynthesis::KeepReference,
2293
+ /* forceConstQualifier*/ true );
2294
+ newMethod->addAttr (clang::SwiftNameAttr::CreateImplicit (
2295
+ clangMethodDecl->getASTContext (), " callAsFunction" ));
2296
+
2297
+ auto result = dyn_cast_or_null<FuncDecl>(
2298
+ ctx.getClangModuleLoader ()->importDeclDirectly (newMethod));
2299
+ return result;
2300
+ }
2301
+
2267
2302
// MARK: C++ properties
2268
2303
2269
2304
static std::pair<BraceStmt *, bool >
0 commit comments