7575#include " llvm/Support/YAMLTraits.h"
7676#include " llvm/Support/VirtualFileSystem.h"
7777#include < algorithm>
78+ #include < string>
7879#include < memory>
7980
8081using namespace swift ;
@@ -86,6 +87,17 @@ using clang::CompilerInvocation;
8687
8788#pragma mark Internal data structures
8889
90+ namespace {
91+ static std::string getOperatorNameForToken (std::string OperatorToken) {
92+ #define OVERLOADED_OPERATOR (Name,Spelling,Token,Unary,Binary,MemberOnly ) \
93+ if (OperatorToken == Spelling) { \
94+ return #Name; \
95+ };
96+ #include " clang/Basic/OperatorKinds.def"
97+ return " None" ;
98+ }
99+ }
100+
89101namespace {
90102 class HeaderImportCallbacks : public clang ::PPCallbacks {
91103 ClangImporter::Implementation &Impl;
@@ -4104,25 +4116,47 @@ bool ClangImporter::Implementation::forEachLookupTable(
41044116bool ClangImporter::Implementation::lookupValue (SwiftLookupTable &table,
41054117 DeclName name,
41064118 VisibleDeclConsumer &consumer) {
4119+
41074120 auto &clangCtx = getClangASTContext ();
41084121 auto clangTU = clangCtx.getTranslationUnitDecl ();
41094122
41104123 bool declFound = false ;
4111-
41124124 // For operators we have to look up static member functions in addition to the
41134125 // top-level function lookup below.
4126+ auto declBaseName = (SwiftContext.LangOpts .EnableCXXInterop && name.isOperator ())
4127+ ? DeclBaseName (SwiftContext.getIdentifier (" __operator" + getOperatorNameForToken (std::string{name.getBaseName ().getIdentifier ()})))
4128+ : name.getBaseName ();
4129+
41144130 if (name.isOperator ()) {
4115- auto declBaseName = SwiftContext.LangOpts .EnableCXXInterop
4116- ? name.getBaseName ()
4117- : DeclBaseName (SwiftContext.getIdentifier (" __operatorMinus" ));
4118- for (auto entry : table.lookupMemberOperators ( declBaseName)) {
4119- if (isVisibleClangEntry (entry)) {
4120- if (auto decl = dyn_cast_or_null<ValueDecl>(
4121- importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4122- consumer.foundDecl (decl, DeclVisibilityKind::VisibleAtTopLevel);
4123- declFound = true ;
4131+ for (auto entry : table.lookupMemberOperators (declBaseName)) {
4132+ if (isVisibleClangEntry (entry)) {
4133+ if (auto decl = dyn_cast_or_null<ValueDecl>(
4134+ importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4135+ consumer.foundDecl (decl, DeclVisibilityKind::VisibleAtTopLevel);
4136+ declFound = true ;
4137+ for (auto alternate: getAlternateDecls (decl)) {
4138+ if (alternate->getName ().matchesRef (name)) {
4139+ consumer.foundDecl (alternate, DeclVisibilityKind::DynamicLookup,
4140+ DynamicLookupInfo::AnyObject);
4141+ }
4142+ }
4143+ }
41244144 }
4125- }
4145+ }
4146+ for (auto entry : table.lookupMemberOperators (name.getBaseName ())) {
4147+ if (isVisibleClangEntry (entry)) {
4148+ if (auto decl = dyn_cast_or_null<ValueDecl>(
4149+ importDeclReal (entry->getMostRecentDecl (), CurrentVersion))) {
4150+ consumer.foundDecl (decl, DeclVisibilityKind::VisibleAtTopLevel);
4151+ declFound = true ;
4152+ for (auto alternate : getAlternateDecls (decl)) {
4153+ if (alternate->getName ().matchesRef (name)) {
4154+ consumer.foundDecl (alternate, DeclVisibilityKind::DynamicLookup,
4155+ DynamicLookupInfo::AnyObject);
4156+ }
4157+ }
4158+ }
4159+ }
41264160 }
41274161 }
41284162
0 commit comments