@@ -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 ();
@@ -2264,6 +2273,27 @@ FuncDecl *SwiftDeclSynthesizer::makeVirtualMethod(
2264
2273
return result;
2265
2274
}
2266
2275
2276
+ // MARK: C++ operators
2277
+
2278
+ FuncDecl *SwiftDeclSynthesizer::makeInstanceToStaticOperatorCallMethod (
2279
+ const clang::CXXMethodDecl *clangMethodDecl) {
2280
+ auto clangDC = clangMethodDecl->getParent ();
2281
+ auto &ctx = ImporterImpl.SwiftContext ;
2282
+
2283
+ assert (clangMethodDecl->isStatic () && " Expected a static operator" );
2284
+
2285
+ auto newMethod = synthesizeCXXForwardingMethod (
2286
+ clangDC, clangDC, clangMethodDecl, ForwardingMethodKind::Base,
2287
+ ReferenceReturnTypeBehaviorForBaseMethodSynthesis::KeepReference,
2288
+ /* forceConstQualifier*/ true );
2289
+ newMethod->addAttr (clang::SwiftNameAttr::CreateImplicit (
2290
+ clangMethodDecl->getASTContext (), " callAsFunction" ));
2291
+
2292
+ auto result = dyn_cast_or_null<FuncDecl>(
2293
+ ctx.getClangModuleLoader ()->importDeclDirectly (newMethod));
2294
+ return result;
2295
+ }
2296
+
2267
2297
// MARK: C++ properties
2268
2298
2269
2299
static std::pair<BraceStmt *, bool >
0 commit comments