Skip to content

Commit 8f44e70

Browse files
committed
Stop passing around these flags as an unsigned.
1 parent cc8351c commit 8f44e70

File tree

8 files changed

+124
-82
lines changed

8 files changed

+124
-82
lines changed

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define SWIFT_DECLCONTEXT_H
2121

2222
#include "swift/AST/Identifier.h"
23+
#include "swift/AST/LookupKinds.h"
2324
#include "swift/AST/ResilienceExpansion.h"
2425
#include "swift/AST/TypeAlignments.h"
2526
#include "swift/Basic/LLVM.h"
@@ -413,7 +414,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
413414
/// lookup.
414415
///
415416
/// \returns true if anything was found.
416-
bool lookupQualified(Type type, DeclName member, unsigned options,
417+
bool lookupQualified(Type type, DeclName member, NLOptions options,
417418
LazyResolver *typeResolver,
418419
SmallVectorImpl<ValueDecl *> &decls) const;
419420

include/swift/AST/LookupKinds.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//===--- LookupKinds.h - Swift name-lookup enums ----------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines enums relating to name lookup.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_LOOKUPKINDS_H
18+
#define SWIFT_LOOKUPKINDS_H
19+
20+
namespace swift {
21+
22+
/// NLKind - This is a specifier for the kind of name lookup being performed
23+
/// by various query methods.
24+
enum class NLKind {
25+
UnqualifiedLookup,
26+
QualifiedLookup
27+
};
28+
29+
/// Constants used to customize name lookup.
30+
enum NLOptions : unsigned {
31+
/// Visit supertypes (such as superclasses or inherited protocols)
32+
/// and their extensions as well as the current extension.
33+
NL_VisitSupertypes = 0x01,
34+
35+
/// Consider declarations within protocols to which the context type conforms.
36+
NL_ProtocolMembers = 0x02,
37+
38+
/// Remove non-visible declarations from the set of results.
39+
NL_RemoveNonVisible = 0x04,
40+
41+
/// Remove overridden declarations from the set of results.
42+
NL_RemoveOverridden = 0x08,
43+
44+
/// For existentials involving the special \c AnyObject protocol,
45+
/// allow lookups to find members of all classes.
46+
NL_DynamicLookup = 0x10,
47+
48+
/// Don't check accessibility when doing lookup into a type.
49+
///
50+
/// This option is not valid when performing lookup into a module.
51+
NL_IgnoreAccessibility = 0x20,
52+
53+
/// This lookup is known to be a non-cascading dependency, i.e. one that does
54+
/// not affect downstream files.
55+
///
56+
/// \see NL_KnownDependencyMask
57+
NL_KnownNonCascadingDependency = 0x40,
58+
59+
/// This lookup is known to be a cascading dependency, i.e. one that can
60+
/// affect downstream files.
61+
///
62+
/// \see NL_KnownDependencyMask
63+
NL_KnownCascadingDependency = 0x80,
64+
65+
/// This lookup is known to not add any additional dependencies to the
66+
/// primary source file.
67+
///
68+
/// \see NL_KnownDependencyMask
69+
NL_KnownNoDependency =
70+
NL_KnownNonCascadingDependency|NL_KnownCascadingDependency,
71+
72+
/// A mask of all options controlling how a lookup should be recorded as a
73+
/// dependency.
74+
///
75+
/// This offers three possible options: NL_KnownNonCascadingDependency,
76+
/// NL_KnownCascadingDependency, NL_KnownNoDependency, as well as a default
77+
/// "unspecified" value (0). If the dependency kind is unspecified, the
78+
/// lookup function will attempt to infer whether it is a cascading or
79+
/// non-cascading dependency from the decl context.
80+
NL_KnownDependencyMask = NL_KnownNoDependency,
81+
82+
/// The default set of options used for qualified name lookup.
83+
///
84+
/// FIXME: Eventually, add NL_ProtocolMembers to this, once all of the
85+
/// callers can handle it.
86+
NL_QualifiedDefault = NL_VisitSupertypes | NL_RemoveNonVisible |
87+
NL_RemoveOverridden,
88+
89+
/// The default set of options used for unqualified name lookup.
90+
NL_UnqualifiedDefault = NL_VisitSupertypes |
91+
NL_RemoveNonVisible | NL_RemoveOverridden
92+
};
93+
94+
static inline NLOptions operator|(NLOptions lhs, NLOptions rhs) {
95+
return NLOptions(unsigned(lhs) | unsigned(rhs));
96+
}
97+
static inline NLOptions &operator|=(NLOptions &lhs, NLOptions rhs) {
98+
return (lhs = lhs | rhs);
99+
}
100+
static inline NLOptions operator&(NLOptions lhs, NLOptions rhs) {
101+
return NLOptions(unsigned(lhs) & unsigned(rhs));
102+
}
103+
static inline NLOptions &operator&=(NLOptions &lhs, NLOptions rhs) {
104+
return (lhs = lhs & rhs);
105+
}
106+
static inline NLOptions operator~(NLOptions value) {
107+
return NLOptions(~(unsigned)value);
108+
}
109+
110+
} // end namespace swift
111+
112+
#endif

include/swift/AST/Module.h

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/Decl.h"
2121
#include "swift/AST/DeclContext.h"
2222
#include "swift/AST/Identifier.h"
23+
#include "swift/AST/LookupKinds.h"
2324
#include "swift/AST/RawComment.h"
2425
#include "swift/AST/Type.h"
2526
#include "swift/Basic/OptionSet.h"
@@ -76,78 +77,6 @@ namespace swift {
7677
class VarDecl;
7778
class VisibleDeclConsumer;
7879

79-
/// NLKind - This is a specifier for the kind of name lookup being performed
80-
/// by various query methods.
81-
enum class NLKind {
82-
UnqualifiedLookup,
83-
QualifiedLookup
84-
};
85-
86-
/// Constants used to customize name lookup.
87-
enum ASTNameLookupFlags {
88-
/// Visit supertypes (such as superclasses or inherited protocols)
89-
/// and their extensions as well as the current extension.
90-
NL_VisitSupertypes = 0x01,
91-
92-
/// Consider declarations within protocols to which the context type conforms.
93-
NL_ProtocolMembers = 0x02,
94-
95-
/// Remove non-visible declarations from the set of results.
96-
NL_RemoveNonVisible = 0x04,
97-
98-
/// Remove overridden declarations from the set of results.
99-
NL_RemoveOverridden = 0x08,
100-
101-
/// For existentials involving the special \c AnyObject protocol,
102-
/// allow lookups to find members of all classes.
103-
NL_DynamicLookup = 0x10,
104-
105-
/// Don't check accessibility when doing lookup into a type.
106-
///
107-
/// This option is not valid when performing lookup into a module.
108-
NL_IgnoreAccessibility = 0x20,
109-
110-
/// This lookup is known to be a non-cascading dependency, i.e. one that does
111-
/// not affect downstream files.
112-
///
113-
/// \see NL_KnownDependencyMask
114-
NL_KnownNonCascadingDependency = 0x40,
115-
116-
/// This lookup is known to be a cascading dependency, i.e. one that can
117-
/// affect downstream files.
118-
///
119-
/// \see NL_KnownDependencyMask
120-
NL_KnownCascadingDependency = 0x80,
121-
122-
/// This lookup is known to not add any additional dependencies to the
123-
/// primary source file.
124-
///
125-
/// \see NL_KnownDependencyMask
126-
NL_KnownNoDependency =
127-
NL_KnownNonCascadingDependency|NL_KnownCascadingDependency,
128-
129-
/// A mask of all options controlling how a lookup should be recorded as a
130-
/// dependency.
131-
///
132-
/// This offers three possible options: NL_KnownNonCascadingDependency,
133-
/// NL_KnownCascadingDependency, NL_KnownNoDependency, as well as a default
134-
/// "unspecified" value (0). If the dependency kind is unspecified, the
135-
/// lookup function will attempt to infer whether it is a cascading or
136-
/// non-cascading dependency from the decl context.
137-
NL_KnownDependencyMask = NL_KnownNoDependency,
138-
139-
/// The default set of options used for qualified name lookup.
140-
///
141-
/// FIXME: Eventually, add NL_ProtocolMembers to this, once all of the
142-
/// callers can handle it.
143-
NL_QualifiedDefault = NL_VisitSupertypes | NL_RemoveNonVisible |
144-
NL_RemoveOverridden,
145-
146-
/// The default set of options used for unqualified name lookup.
147-
NL_UnqualifiedDefault = NL_VisitSupertypes |
148-
NL_RemoveNonVisible | NL_RemoveOverridden
149-
};
150-
15180
/// Discriminator for file-units.
15281
enum class FileUnitKind {
15382
/// For a .swift source file.

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
520520
if (TypeResolver)
521521
TypeResolver->resolveDeclSignature(BaseDecl);
522522

523-
unsigned options = NL_UnqualifiedDefault;
523+
NLOptions options = NL_UnqualifiedDefault;
524524
if (isCascadingUse.getValue())
525525
options |= NL_KnownCascadingDependency;
526526
else
@@ -1024,7 +1024,7 @@ bool AbstractStorageDecl::isSetterAccessibleFrom(const DeclContext *DC) const {
10241024

10251025
bool DeclContext::lookupQualified(Type type,
10261026
DeclName member,
1027-
unsigned options,
1027+
NLOptions options,
10281028
LazyResolver *typeResolver,
10291029
SmallVectorImpl<ValueDecl *> &decls) const {
10301030
using namespace namelookup;

lib/IDE/ReconstructType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DeclsLookupSource {
151151
decltype(m_decls)::const_iterator end() { return m_decls.end(); }
152152
};
153153

154-
bool lookupQualified(ModuleDecl *entry, Identifier name, unsigned options,
154+
bool lookupQualified(ModuleDecl *entry, Identifier name, NLOptions options,
155155
LazyResolver *typeResolver, ValueDecls &decls) {
156156
if (!entry)
157157
return false;
@@ -209,7 +209,7 @@ class DeclsLookupSource {
209209
return DeclsLookupSource(source._module, decl);
210210
}
211211

212-
void lookupQualified(Identifier name, unsigned options,
212+
void lookupQualified(Identifier name, NLOptions options,
213213
LazyResolver *typeResolver, ValueDecls &result) {
214214
if (_type == LookupKind::Crawler) {
215215
ASTContext *ast_ctx = _crawler._ast;
@@ -576,7 +576,7 @@ static bool FindFirstNamedDeclWithKind(
576576
name_ident, ast->getIdentifier(priv_decl_id.getValue().c_str()),
577577
decls);
578578
else
579-
result._module.lookupQualified(name_ident, 0, NULL, decls);
579+
result._module.lookupQualified(name_ident, NLOptions(), NULL, decls);
580580
if (!decls.empty()) {
581581
bool check_type_aliases = false;
582582
// Look for an exact match first

lib/Parse/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static ValueDecl *lookupMember(Parser &P, Type Ty, Identifier Name,
769769
SourceLoc Loc,
770770
SmallVectorImpl<ValueDecl *> &Lookup,
771771
bool ExpectMultipleResults) {
772-
unsigned options = NL_QualifiedDefault;
772+
NLOptions options = NL_QualifiedDefault;
773773
// FIXME: a bit of a hack.
774774
if (Name == P.Context.Id_deinit || Name == P.Context.Id_init)
775775
options = options & ~NL_VisitSupertypes;

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc,
237237
Type type, DeclName name,
238238
NameLookupOptions options) {
239239
LookupResult result;
240-
unsigned subOptions = NL_QualifiedDefault;
240+
NLOptions subOptions = NL_QualifiedDefault;
241241
if (options.contains(NameLookupFlags::KnownPrivate))
242242
subOptions |= NL_KnownNonCascadingDependency;
243243
if (options.contains(NameLookupFlags::DynamicLookup))
@@ -326,7 +326,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
326326

327327
// Look for members with the given name.
328328
SmallVector<ValueDecl *, 4> decls;
329-
unsigned subOptions = NL_QualifiedDefault;
329+
NLOptions subOptions = NL_QualifiedDefault;
330330
if (options.contains(NameLookupFlags::KnownPrivate))
331331
subOptions |= NL_KnownNonCascadingDependency;
332332
if (options.contains(NameLookupFlags::ProtocolMembers))

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
15751575
continue;
15761576
VarDecl *prop = nullptr;
15771577
SmallVector<ValueDecl *, 4> members;
1578-
unsigned lookupOptions =
1578+
NLOptions lookupOptions =
15791579
NL_QualifiedDefault | NL_KnownNonCascadingDependency;
15801580
if (!dc->lookupQualified(type, elt.getPropertyName(),
15811581
lookupOptions, this, members)) {

0 commit comments

Comments
 (0)