mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema now type-checks the alternate ABI-providing decls inside of @abi attributes. Making this work—particularly, making redeclaration checking work—required making name lookup aware of ABI decls. Name lookup now evaluates both API-providing and ABI-providing declarations. In most cases, it will filter ABI-only decls out unless a specific flag is passed, in which case it will filter API-only decls out instead. Calls that simply retrieve a list of declarations, like `IterableDeclContext::getMembers()` and friends, typically only return API-providing decls; you have to access the ABI-providing ones through those. As part of that work, I have also added some basic compiler interfaces for working with the API-providing and ABI-providing variants. `ABIRole` encodes whether a declaration provides only API, only ABI, or both, and `ABIRoleInfo` combines that with a pointer to the counterpart providing the other role (for a declaration that provides both, that’ll just be a pointer to `this`). Decl checking of behavior specific to @abi will come in a future commit. Note that this probably doesn’t properly exercise some of the new code (ASTScope::lookupEnclosingABIAttributeScope(), for instance); I expect that to happen only once we can rename types using an @abi attribute, since that will create distinguishable behavior differences when resolving TypeReprs in other @abi attributes.
112 lines
3.6 KiB
C++
112 lines
3.6 KiB
C++
//===--- LookupKinds.h - Swift name-lookup enums ----------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines enums relating to name lookup.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_LOOKUPKINDS_H
|
|
#define SWIFT_LOOKUPKINDS_H
|
|
|
|
namespace swift {
|
|
|
|
/// NLKind - This is a specifier for the kind of name lookup being performed
|
|
/// by various query methods.
|
|
enum class NLKind {
|
|
UnqualifiedLookup,
|
|
QualifiedLookup
|
|
};
|
|
|
|
void simple_display(llvm::raw_ostream &out, NLKind kind);
|
|
|
|
/// Constants used to customize name lookup.
|
|
enum NLOptions : unsigned {
|
|
/// Consider declarations within protocols to which the context type conforms.
|
|
NL_ProtocolMembers = 1 << 0,
|
|
|
|
/// Remove non-visible declarations from the set of results.
|
|
NL_RemoveNonVisible = 1 << 1,
|
|
|
|
/// Remove overridden declarations from the set of results.
|
|
NL_RemoveOverridden = 1 << 2,
|
|
|
|
/// Don't check access when doing lookup into a type.
|
|
///
|
|
/// When performing lookup into a module, this option only applies to
|
|
/// declarations in the same module the lookup is coming from.
|
|
NL_IgnoreAccessControl = 1 << 3,
|
|
|
|
/// This lookup should only return type declarations.
|
|
NL_OnlyTypes = 1 << 4,
|
|
|
|
/// Include synonyms declared with @_implements()
|
|
NL_IncludeAttributeImplements = 1 << 5,
|
|
|
|
// Include @usableFromInline and @inlinable
|
|
NL_IncludeUsableFromInline = 1 << 6,
|
|
|
|
/// Exclude names introduced by macro expansions in the top-level module.
|
|
NL_ExcludeMacroExpansions = 1 << 7,
|
|
|
|
/// This lookup should only return macro declarations.
|
|
NL_OnlyMacros = 1 << 8,
|
|
|
|
/// Include members that would otherwise be filtered out because they come
|
|
/// from a module that has not been imported.
|
|
NL_IgnoreMissingImports = 1 << 9,
|
|
|
|
/// If @abi attributes are present, return the decls representing the ABI,
|
|
/// not the API.
|
|
NL_ABIProviding = 1 << 10,
|
|
|
|
/// The default set of options used for qualified name lookup.
|
|
///
|
|
/// FIXME: Eventually, add NL_ProtocolMembers to this, once all of the
|
|
/// callers can handle it.
|
|
NL_QualifiedDefault = NL_RemoveNonVisible | NL_RemoveOverridden,
|
|
|
|
/// The default set of options used for unqualified name lookup.
|
|
NL_UnqualifiedDefault = NL_RemoveNonVisible | NL_RemoveOverridden
|
|
};
|
|
|
|
static inline NLOptions operator|(NLOptions lhs, NLOptions rhs) {
|
|
return NLOptions(unsigned(lhs) | unsigned(rhs));
|
|
}
|
|
static inline NLOptions &operator|=(NLOptions &lhs, NLOptions rhs) {
|
|
return (lhs = lhs | rhs);
|
|
}
|
|
static inline NLOptions operator&(NLOptions lhs, NLOptions rhs) {
|
|
return NLOptions(unsigned(lhs) & unsigned(rhs));
|
|
}
|
|
static inline NLOptions &operator&=(NLOptions &lhs, NLOptions rhs) {
|
|
return (lhs = lhs & rhs);
|
|
}
|
|
static inline NLOptions operator~(NLOptions value) {
|
|
return NLOptions(~(unsigned)value);
|
|
}
|
|
|
|
void simple_display(llvm::raw_ostream &out, NLOptions options);
|
|
|
|
|
|
/// Flags affecting module-level lookup.
|
|
enum class ModuleLookupFlags : unsigned {
|
|
/// Exclude names introduced by macro expansions in the top-level module.
|
|
ExcludeMacroExpansions = 1 << 0,
|
|
/// If @abi attributes are present, return the decls representing the ABI,
|
|
/// not the API.
|
|
ABIProviding = 1 << 1,
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif
|