@@ -63,9 +63,10 @@ swift::ide::makeCodeCompletionMemoryBuffer(const llvm::MemoryBuffer *origBuf,
63
63
}
64
64
65
65
namespace {
66
- // / Returns index number of \p D in \p Decls . If it's not found, returns ~0.
66
+ // / Returns index number of \p D in \p Decls . If it's not found, returns
67
+ // / \c nullopt.
67
68
template <typename Range>
68
- unsigned findIndexInRange (Decl *D, const Range &Decls) {
69
+ std::optional< unsigned > findIndexInRange (Decl *D, const Range &Decls) {
69
70
unsigned N = 0 ;
70
71
for (auto I = Decls.begin (), E = Decls.end (); I != E; ++I) {
71
72
if ((*I)->isImplicit ())
@@ -74,7 +75,7 @@ unsigned findIndexInRange(Decl *D, const Range &Decls) {
74
75
return N;
75
76
++N;
76
77
}
77
- return ~ 0U ;
78
+ return std::nullopt ;
78
79
}
79
80
80
81
// / Return the element at \p N in \p Decls .
@@ -106,7 +107,7 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
106
107
if (!D)
107
108
return nullptr ;
108
109
auto *parentDC = newDC->getParent ();
109
- unsigned N = ~ 0U ;
110
+ std::optional< unsigned > N ;
110
111
111
112
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
112
113
// The AST for accessors is like:
@@ -117,7 +118,9 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
117
118
if (!storage)
118
119
return nullptr ;
119
120
auto accessorN = findIndexInRange (accessor, storage->getAllAccessors ());
120
- IndexStack.push_back (accessorN);
121
+ if (!accessorN)
122
+ return nullptr ;
123
+ IndexStack.push_back (*accessorN);
121
124
D = storage;
122
125
}
123
126
@@ -134,11 +137,10 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
134
137
}
135
138
136
139
// Not found in the decl context tree.
137
- if (N == ~ 0U ) {
140
+ if (!N)
138
141
return nullptr ;
139
- }
140
142
141
- IndexStack.push_back (N);
143
+ IndexStack.push_back (* N);
142
144
newDC = parentDC;
143
145
} while (!newDC->isModuleScopeContext ());
144
146
0 commit comments