10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
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"
15
17
16
18
#include " llvm/ADT/StringRef.h"
17
19
#include < optional>
@@ -21,53 +23,72 @@ namespace swift {
21
23
class LangOptions ;
22
24
23
25
// / Enumeration describing all of the named features.
24
- enum class Feature : uint16_t {
26
+ struct Feature {
27
+ enum class InnerKind : uint16_t {
25
28
#define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) FeatureName,
26
29
#include " swift/Basic/Features.def"
27
- };
30
+ };
31
+
32
+ InnerKind kind;
28
33
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 {
31
43
#define LANGUAGE_FEATURE (FeatureName, SENumber, Description ) FeatureName,
32
44
#include " swift/Basic/Features.def"
33
- NumFeatures
34
- };
35
- return NumFeatures;
36
- }
45
+ NumFeatures
46
+ };
47
+ return NumFeatures;
48
+ }
37
49
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"
40
53
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 ;
43
56
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 ;
52
59
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 adoption mode .
61
+ bool isAdoptable () const ;
55
62
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 ;
59
66
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
+ }
63
75
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 );
66
78
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 );
70
82
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"
71
92
}
72
93
73
94
#endif // SWIFT_BASIC_FEATURES_H
0 commit comments