1010//
1111// ===----------------------------------------------------------------------===//
1212
13- #ifndef SWIFT_BASIC_FEATURES_H
14- #define SWIFT_BASIC_FEATURES_H
13+ #ifndef SWIFT_BASIC_FEATURE_H
14+ #define SWIFT_BASIC_FEATURE_H
15+
16+ #include " swift/Basic/LLVM.h"
1517
1618#include " llvm/ADT/StringRef.h"
1719#include < optional>
@@ -21,53 +23,72 @@ namespace swift {
2123class LangOptions ;
2224
2325// / Enumeration describing all of the named features.
24- enum class Feature : uint16_t {
26+ struct Feature {
27+ enum class InnerKind : uint16_t {
2528#define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) FeatureName,
2629#include " swift/Basic/Features.def"
27- };
30+ };
31+
32+ InnerKind kind;
2833
29- constexpr unsigned numFeatures () {
30- enum Features {
34+ constexpr Feature (InnerKind kind) : kind(kind) {}
35+ constexpr Feature (unsigned inputKind) : kind(InnerKind(inputKind)) {}
36+
37+ constexpr operator InnerKind () const { return kind; }
38+ constexpr explicit operator unsigned () const { return unsigned (kind); }
39+ constexpr explicit operator size_t () const { return size_t (kind); }
40+
41+ static constexpr unsigned getNumFeatures () {
42+ enum Features {
3143#define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) FeatureName,
3244#include " swift/Basic/Features.def"
33- NumFeatures
34- };
35- return NumFeatures;
36- }
45+ NumFeatures
46+ };
47+ return NumFeatures;
48+ }
3749
38- // / Check whether the given feature is available in production compilers.
39- bool isFeatureAvailableInProduction (Feature feature);
50+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
51+ static const Feature FeatureName;
52+ #include " swift/Basic/Features.def"
4053
41- // / Determine the in-source name of the given feature .
42- llvm::StringRef getFeatureName (Feature feature) ;
54+ // / Check whether the given feature is available in production compilers .
55+ bool isAvailableInProduction () const ;
4356
44- // / Determine whether the first feature is more recent (and thus implies
45- // / the existence of) the second feature. Only meaningful for suppressible
46- // / features.
47- inline bool featureImpliesFeature (Feature feature, Feature implied) {
48- // Suppressible features are expected to be listed in order of
49- // addition in Features.def.
50- return (unsigned ) feature < (unsigned ) implied;
51- }
57+ // / Determine the in-source name of the given feature.
58+ llvm::StringRef getName () const ;
5259
53- // / Get the feature corresponding to this "future" feature, if there is one .
54- std::optional<Feature> getUpcomingFeature (llvm::StringRef name) ;
60+ // / Determine whether the given feature supports migration mode .
61+ bool isMigratable () const ;
5562
56- // / Get the feature corresponding to this "experimental" feature, if there is
57- // / one.
58- std::optional<Feature> getExperimentalFeature (llvm::StringRef name) ;
63+ // / Determine whether this feature should be included in the
64+ // / module interface
65+ bool includeInModuleInterface () const ;
5966
60- // / Get the major language version in which this feature was introduced, or
61- // / \c None if it does not have such a version.
62- std::optional<unsigned > getFeatureLanguageVersion (Feature feature);
67+ // / Determine whether the first feature is more recent (and thus implies
68+ // / the existence of) the second feature. Only meaningful for suppressible
69+ // / features.
70+ constexpr bool featureImpliesFeature (Feature implied) const {
71+ // Suppressible features are expected to be listed in order of
72+ // addition in Features.def.
73+ return (unsigned )kind < (unsigned )implied.kind ;
74+ }
6375
64- // / Determine whether the given feature supports adoption mode .
65- bool isFeatureAdoptable ( Feature feature );
76+ // / Get the feature corresponding to this "future" feature, if there is one .
77+ static std::optional< Feature> getUpcomingFeature (StringRef name );
6678
67- // / Determine whether this feature should be included in the
68- // / module interface
69- bool includeInModuleInterface ( Feature feature );
79+ // / Get the feature corresponding to this "experimental" feature, if there is
80+ // / one.
81+ static std::optional< Feature> getExperimentalFeature (StringRef name );
7082
83+ // / Get the major language version in which this feature was introduced, or
84+ // / \c None if it does not have such a version.
85+ std::optional<unsigned > getLanguageVersion () const ;
86+ };
87+
88+ #define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) \
89+ constexpr inline Feature Feature::FeatureName = \
90+ Feature::InnerKind::FeatureName;
91+ #include " swift/Basic/Features.def"
7192}
7293
7394#endif // SWIFT_BASIC_FEATURES_H
0 commit comments