|
| 1 | +//===--- Feature.cpp --------------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "swift/Basic/Feature.h" |
| 14 | +#include "llvm/ADT/StringSwitch.h" |
| 15 | +#include "llvm/Support/ErrorHandling.h" |
| 16 | + |
| 17 | +using namespace swift; |
| 18 | + |
| 19 | +bool swift::isFeatureAvailableInProduction(Feature feature) { |
| 20 | + switch (feature) { |
| 21 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \ |
| 22 | + case Feature::FeatureName: \ |
| 23 | + return true; |
| 24 | +#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \ |
| 25 | + case Feature::FeatureName: \ |
| 26 | + return AvailableInProd; |
| 27 | +#include "swift/Basic/Features.def" |
| 28 | + } |
| 29 | + llvm_unreachable("covered switch"); |
| 30 | +} |
| 31 | + |
| 32 | +llvm::StringRef swift::getFeatureName(Feature feature) { |
| 33 | + switch (feature) { |
| 34 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \ |
| 35 | + case Feature::FeatureName: \ |
| 36 | + return #FeatureName; |
| 37 | +#include "swift/Basic/Features.def" |
| 38 | + } |
| 39 | + llvm_unreachable("covered switch"); |
| 40 | +} |
| 41 | + |
| 42 | +std::optional<Feature> swift::getUpcomingFeature(llvm::StringRef name) { |
| 43 | + return llvm::StringSwitch<std::optional<Feature>>(name) |
| 44 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) |
| 45 | +#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \ |
| 46 | + .Case(#FeatureName, Feature::FeatureName) |
| 47 | +#include "swift/Basic/Features.def" |
| 48 | + .Default(std::nullopt); |
| 49 | +} |
| 50 | + |
| 51 | +std::optional<Feature> swift::getExperimentalFeature(llvm::StringRef name) { |
| 52 | + return llvm::StringSwitch<std::optional<Feature>>(name) |
| 53 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) |
| 54 | +#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) \ |
| 55 | + .Case(#FeatureName, Feature::FeatureName) |
| 56 | +#include "swift/Basic/Features.def" |
| 57 | + .Default(std::nullopt); |
| 58 | +} |
| 59 | + |
| 60 | +std::optional<unsigned> swift::getFeatureLanguageVersion(Feature feature) { |
| 61 | + switch (feature) { |
| 62 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) |
| 63 | +#define UPCOMING_FEATURE(FeatureName, SENumber, Version) \ |
| 64 | + case Feature::FeatureName: \ |
| 65 | + return Version; |
| 66 | +#include "swift/Basic/Features.def" |
| 67 | + default: |
| 68 | + return std::nullopt; |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +bool swift::includeInModuleInterface(Feature feature) { |
| 73 | + switch (feature) { |
| 74 | +#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) \ |
| 75 | + case Feature::FeatureName: \ |
| 76 | + return true; |
| 77 | +#define EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(FeatureName, \ |
| 78 | + AvailableInProd) \ |
| 79 | + case Feature::FeatureName: \ |
| 80 | + return false; |
| 81 | +#include "swift/Basic/Features.def" |
| 82 | + } |
| 83 | + llvm_unreachable("covered switch"); |
| 84 | +} |
0 commit comments