Skip to content

Commit a3efeca

Browse files
committed
[NFC] Improve lookup flag printing facilities
1 parent b1e3da1 commit a3efeca

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ enum class UnqualifiedLookupFlags {
253253
/// This lookup should include members that would otherwise be filtered out
254254
/// because they come from a module that has not been imported.
255255
IgnoreMissingImports = 1 << 10,
256+
257+
// Reminder: If you add a flag, make sure you update simple_display() below
256258
};
257259

258260
using UnqualifiedLookupOptions = OptionSet<UnqualifiedLookupFlags>;

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ void swift::simple_display(llvm::raw_ostream &out,
118118
{UnqualifiedLookupFlags::TypeLookup, "TypeLookup"},
119119
{UnqualifiedLookupFlags::MacroLookup, "MacroLookup"},
120120
{UnqualifiedLookupFlags::ModuleLookup, "ModuleLookup"},
121+
{UnqualifiedLookupFlags::DisregardSelfBounds, "DisregardSelfBounds"},
122+
{UnqualifiedLookupFlags::IgnoreMissingImports, "IgnoreMissingImports"},
121123
};
122124

123125
auto flagsToPrint = llvm::make_filter_range(

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@
3232

3333
using namespace swift;
3434

35+
void swift::simple_display(llvm::raw_ostream &out, NameLookupOptions options) {
36+
using Flag = std::pair<NameLookupFlags, StringRef>;
37+
Flag possibleFlags[] = {
38+
{NameLookupFlags::IgnoreAccessControl, "IgnoreAccessControl"},
39+
{NameLookupFlags::IncludeOuterResults, "IncludeOuterResults"},
40+
{NameLookupFlags::IncludeUsableFromInline, "IncludeUsableFromInline"},
41+
{NameLookupFlags::ExcludeMacroExpansions, "ExcludeMacroExpansions"},
42+
{NameLookupFlags::IgnoreMissingImports, "IgnoreMissingImports"},
43+
};
44+
45+
auto flagsToPrint = llvm::make_filter_range(
46+
possibleFlags, [&](Flag flag) { return options.contains(flag.first); });
47+
48+
out << "{ ";
49+
interleave(
50+
flagsToPrint, [&](Flag flag) { out << flag.second; },
51+
[&] { out << ", "; });
52+
out << " }";
53+
}
54+
3555
namespace {
3656
/// Builder that helps construct a lookup result from the raw lookup
3757
/// data.

lib/Sema/TypeChecker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@ enum class NameLookupFlags {
161161
/// Whether to include members that would otherwise be filtered out because
162162
/// they come from a module that has not been imported.
163163
IgnoreMissingImports = 1 << 4,
164+
165+
// Reminder: If you add a flag, make sure you update simple_display() below
164166
};
165167

166168
/// A set of options that control name lookup.
167169
using NameLookupOptions = OptionSet<NameLookupFlags>;
168170

171+
void simple_display(llvm::raw_ostream &out, NameLookupOptions opts);
172+
169173
inline NameLookupOptions operator|(NameLookupFlags flag1,
170174
NameLookupFlags flag2) {
171175
return NameLookupOptions(flag1) | flag2;

0 commit comments

Comments
 (0)