15
15
// ===----------------------------------------------------------------------===//
16
16
17
17
#include " swift/AST/Module.h"
18
- #include " swift/AST/AccessScope.h"
19
18
#include " swift/AST/ASTContext.h"
20
19
#include " swift/AST/ASTMangler.h"
21
20
#include " swift/AST/ASTPrinter.h"
22
21
#include " swift/AST/ASTWalker.h"
22
+ #include " swift/AST/AccessScope.h"
23
23
#include " swift/AST/Builtins.h"
24
24
#include " swift/AST/ClangModuleLoader.h"
25
25
#include " swift/AST/DiagnosticsSema.h"
31
31
#include " swift/AST/LinkLibrary.h"
32
32
#include " swift/AST/ModuleLoader.h"
33
33
#include " swift/AST/NameLookup.h"
34
- #include " swift/AST/ReferencedNameTracker .h"
34
+ #include " swift/AST/NameLookupRequests .h"
35
35
#include " swift/AST/ParseRequests.h"
36
36
#include " swift/AST/PrettyStackTrace.h"
37
37
#include " swift/AST/PrintOptions.h"
38
38
#include " swift/AST/ProtocolConformance.h"
39
+ #include " swift/AST/ReferencedNameTracker.h"
39
40
#include " swift/AST/SourceFile.h"
40
41
#include " swift/AST/TypeCheckRequests.h"
41
42
#include " swift/Basic/Compiler.h"
48
49
#include " clang/Basic/Module.h"
49
50
#include " llvm/ADT/DenseMap.h"
50
51
#include " llvm/ADT/DenseSet.h"
51
- #include " llvm/ADT/TinyPtrVector .h"
52
+ #include " llvm/ADT/STLExtras .h"
52
53
#include " llvm/ADT/SmallPtrSet.h"
53
54
#include " llvm/ADT/StringExtras.h"
54
- #include " llvm/ADT/STLExtras .h"
55
+ #include " llvm/ADT/TinyPtrVector .h"
55
56
#include " llvm/Support/MD5.h"
56
57
#include " llvm/Support/MemoryBuffer.h"
57
58
#include " llvm/Support/Path.h"
58
- #include " llvm/Support/raw_ostream.h"
59
59
#include " llvm/Support/SaveAndRestore.h"
60
+ #include " llvm/Support/raw_ostream.h"
60
61
61
62
using namespace swift ;
62
63
@@ -943,6 +944,7 @@ namespace {
943
944
944
945
template <>
945
946
struct OperatorLookup <PrefixOperatorDecl> {
947
+ constexpr static auto map_ptr = &SourceFile::PrefixOperators;
946
948
template <typename T>
947
949
static PrefixOperatorDecl *lookup (T &container, Identifier name) {
948
950
return cast_or_null<PrefixOperatorDecl>(
@@ -952,6 +954,7 @@ namespace {
952
954
953
955
template <>
954
956
struct OperatorLookup <InfixOperatorDecl> {
957
+ constexpr static auto map_ptr = &SourceFile::InfixOperators;
955
958
template <typename T>
956
959
static InfixOperatorDecl *lookup (T &container, Identifier name) {
957
960
return cast_or_null<InfixOperatorDecl>(
@@ -961,6 +964,7 @@ namespace {
961
964
962
965
template <>
963
966
struct OperatorLookup <PostfixOperatorDecl> {
967
+ constexpr static auto map_ptr = &SourceFile::PostfixOperators;
964
968
template <typename T>
965
969
static PostfixOperatorDecl *lookup (T &container, Identifier name) {
966
970
return cast_or_null<PostfixOperatorDecl>(
@@ -970,6 +974,7 @@ namespace {
970
974
971
975
template <>
972
976
struct OperatorLookup <PrecedenceGroupDecl> {
977
+ constexpr static auto map_ptr = &SourceFile::PrecedenceGroups;
973
978
template <typename T>
974
979
static PrecedenceGroupDecl *lookup (T &container, Identifier name) {
975
980
return container.lookupPrecedenceGroup (name);
@@ -1058,12 +1063,11 @@ checkOperatorConflicts(const SourceFile &SF, SourceLoc loc,
1058
1063
1059
1064
// Returns None on error, Optional(nullptr) if no operator decl found, or
1060
1065
// Optional(decl) if decl was found.
1061
- template <typename OP_DECL>
1066
+ template <typename OP_DECL>
1062
1067
static Optional<OP_DECL *>
1063
- lookupOperatorDeclForName (const FileUnit &File, SourceLoc Loc, Identifier Name,
1064
- bool includePrivate,
1065
- OperatorMap<OP_DECL *> SourceFile::*OP_MAP)
1066
- {
1068
+ lookupOperatorDeclForName (const FileUnit &File, SourceLoc Loc,
1069
+ Identifier Name, bool includePrivate,
1070
+ OperatorMap<OP_DECL *> SourceFile::*OP_MAP) {
1067
1071
switch (File.getKind ()) {
1068
1072
case FileUnitKind::Builtin:
1069
1073
// The Builtin module declares no operators.
@@ -1152,31 +1156,45 @@ lookupOperatorDeclForName(ModuleDecl *M, SourceLoc Loc, Identifier Name,
1152
1156
return result;
1153
1157
}
1154
1158
1155
- #define LOOKUP_OPERATOR (Kind ) \
1156
- Kind##Decl * \
1157
- ModuleDecl::lookup##Kind(Identifier name, SourceLoc loc) { \
1158
- auto result = lookupOperatorDeclForName (this , loc, name, \
1159
- &SourceFile::Kind##s); \
1160
- return result ? *result : nullptr ; \
1161
- } \
1162
- Kind##Decl * \
1163
- SourceFile::lookup##Kind(Identifier name, bool isCascading, SourceLoc loc) { \
1164
- auto result = lookupOperatorDeclForName (*this , loc, name, true , \
1165
- &SourceFile::Kind##s); \
1166
- if (!result.hasValue ()) \
1167
- return nullptr ; \
1168
- if (ReferencedNames) {\
1169
- if (!result.getValue () || \
1170
- result.getValue ()->getDeclContext ()->getModuleScopeContext () != this ) {\
1171
- ReferencedNames->addTopLevelName (name, isCascading); \
1172
- } \
1173
- } \
1174
- if (!result.getValue ()) { \
1175
- result = lookupOperatorDeclForName (getParentModule (), loc, name, \
1176
- &SourceFile::Kind##s); \
1177
- } \
1178
- return result.hasValue () ? result.getValue () : nullptr ; \
1179
- }
1159
+ template <typename OperatorType>
1160
+ llvm::Expected<OperatorType *> LookupOperatorRequest<OperatorType>::evaluate(
1161
+ Evaluator &evaluator, OperatorLookupDescriptor desc) const {
1162
+ auto result = lookupOperatorDeclForName (*desc.SF , desc.diagLoc , desc.name ,
1163
+ /* includePrivate*/ true ,
1164
+ OperatorLookup<OperatorType>::map_ptr);
1165
+ if (!result.hasValue ())
1166
+ return nullptr ;
1167
+ if (auto *tracker = desc.SF ->getReferencedNameTracker ()) {
1168
+ if (!result.getValue () ||
1169
+ result.getValue ()->getDeclContext ()->getModuleScopeContext () !=
1170
+ desc.SF ) {
1171
+ tracker->addTopLevelName (desc.name , desc.isCascading );
1172
+ }
1173
+ }
1174
+ if (!result.getValue ()) {
1175
+ result = lookupOperatorDeclForName (desc.SF ->getParentModule (), desc.diagLoc ,
1176
+ desc.name ,
1177
+ OperatorLookup<OperatorType>::map_ptr);
1178
+ }
1179
+ return result.hasValue () ? result.getValue () : nullptr ;
1180
+ }
1181
+
1182
+
1183
+ #define LOOKUP_OPERATOR (Kind ) \
1184
+ Kind##Decl *ModuleDecl::lookup##Kind(Identifier name, SourceLoc loc) { \
1185
+ auto result = \
1186
+ lookupOperatorDeclForName (this , loc, name, &SourceFile::Kind##s); \
1187
+ return result ? *result : nullptr ; \
1188
+ } \
1189
+ Kind##Decl *SourceFile::lookup##Kind(Identifier name, bool cascades, \
1190
+ SourceLoc loc) { \
1191
+ return evaluateOrDefault ( \
1192
+ getASTContext ().evaluator , \
1193
+ Lookup##Kind##Request{{this , name, cascades, loc}}, nullptr ); \
1194
+ } \
1195
+ template llvm::Expected<Kind##Decl *> \
1196
+ LookupOperatorRequest<Kind##Decl>::evaluate(Evaluator &e, \
1197
+ OperatorLookupDescriptor d) const ;
1180
1198
1181
1199
LOOKUP_OPERATOR (PrefixOperator)
1182
1200
LOOKUP_OPERATOR(InfixOperator)
0 commit comments