Skip to content

Commit 04ef0da

Browse files
committed
Add ExpUnqualifiedLookup, cross-check
1 parent 4ee879e commit 04ef0da

File tree

2 files changed

+706
-0
lines changed

2 files changed

+706
-0
lines changed

include/swift/AST/NameLookup.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class UnqualifiedLookup {
108108
///
109109
/// If the current DeclContext is nested in a function body, the SourceLoc
110110
/// is used to determine which declarations in that body are visible.
111+
UnqualifiedLookup(const char* dummy, DeclName Name, DeclContext *DC, LazyResolver *TypeResolver,
112+
SourceLoc Loc = SourceLoc(), Options options = Options());
111113
UnqualifiedLookup(DeclName Name, DeclContext *DC, LazyResolver *TypeResolver,
112114
SourceLoc Loc = SourceLoc(), Options options = Options());
113115

@@ -131,6 +133,56 @@ inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
131133
UnqualifiedLookup::Flags flag2) {
132134
return UnqualifiedLookup::Options(flag1) | flag2;
133135
}
136+
137+
138+
/// This class implements and represents the result of performing
139+
/// unqualified lookup (i.e. lookup for a plain identifier).
140+
class ExpUnqualifiedLookup {
141+
public:
142+
using Flags = UnqualifiedLookup::Flags;
143+
144+
using Options = UnqualifiedLookup::Options;
145+
146+
/// Lookup an unqualified identifier \p Name in the context.
147+
///
148+
/// If the current DeclContext is nested in a function body, the SourceLoc
149+
/// is used to determine which declarations in that body are visible.
150+
ExpUnqualifiedLookup(DeclName Name, DeclContext *DC, LazyResolver *TypeResolver,
151+
SourceLoc Loc = SourceLoc(), Options options = Options());
152+
153+
SmallVector<LookupResultEntry, 4> Results;
154+
/// The index of the first result that isn't from the innermost scope
155+
/// with results.
156+
///
157+
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
158+
/// will be Results from the innermost scope that had results, and the
159+
/// remaining elements of Results will be from parent scopes of this one.
160+
size_t IndexOfFirstOuterResult;
161+
162+
/// Return true if anything was found by the name lookup.
163+
bool isSuccess() const { return !Results.empty(); }
164+
165+
/// Get the result as a single type, or a null type if that fails.
166+
TypeDecl *getSingleTypeResult();
167+
168+
bool operator==(const UnqualifiedLookup &other) const {
169+
if (Results.size() != other.Results.size())
170+
return false;
171+
for (size_t i: indices(Results)) {
172+
const auto &e = Results[i];
173+
const auto &oe = other.Results[i];
174+
if (e.getValueDecl() != oe.getValueDecl())
175+
return false;
176+
if (e.getDeclContext() != oe.getDeclContext())
177+
return false;
178+
if (e.getBaseDecl() != oe.getBaseDecl())
179+
return false;
180+
}
181+
return IndexOfFirstOuterResult == other.IndexOfFirstOuterResult;
182+
}
183+
184+
bool verifyEqual(const UnqualifiedLookup &) const;
185+
};
134186

135187
/// Describes the reason why a certain declaration is visible.
136188
enum class DeclVisibilityKind {

0 commit comments

Comments
 (0)