[flang-commits] [flang] [flang][cli] Add diagnostic flags to the CLI (PR #142022)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Sun Jun 8 10:54:19 PDT 2025
================
@@ -94,57 +154,41 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnLanguage_.set(LanguageFeature::NullActualForAllocatable);
}
-// Ignore case and any inserted punctuation (like '-'/'_')
-static std::optional<char> GetWarningChar(char ch) {
- if (ch >= 'a' && ch <= 'z') {
- return ch;
- } else if (ch >= 'A' && ch <= 'Z') {
- return ch - 'A' + 'a';
- } else if (ch >= '0' && ch <= '9') {
- return ch;
- } else {
- return std::nullopt;
+// Take a string from the Cli and apply it to the LanguageFeatureControl.
+// Return true if the option was applied recognized.
+bool LanguageFeatureControl::ApplyCliOption(std::string input) {
+ bool negated{false};
+ if (input.size() > 3 && input.substr(0, 3) == "no-") {
+ negated = true;
+ input = input.substr(3);
}
-}
-
-static bool WarningNameMatch(const char *a, const char *b) {
- while (true) {
- auto ach{GetWarningChar(*a)};
- while (!ach && *a) {
- ach = GetWarningChar(*++a);
- }
- auto bch{GetWarningChar(*b)};
- while (!bch && *b) {
- bch = GetWarningChar(*++b);
- }
- if (!ach && !bch) {
+ if (auto it{cliOptions_.find(input)}; it != cliOptions_.end()) {
+ if (std::holds_alternative<LanguageFeature>(it->second)) {
+ EnableWarning(std::get<LanguageFeature>(it->second), !negated);
return true;
- } else if (!ach || !bch || *ach != *bch) {
- return false;
}
- ++a, ++b;
- }
-}
-
-template <typename ENUM, std::size_t N>
-std::optional<ENUM> ScanEnum(const char *name) {
- if (name) {
- for (std::size_t j{0}; j < N; ++j) {
- auto feature{static_cast<ENUM>(j)};
- if (WarningNameMatch(name, EnumToString(feature).data())) {
- return feature;
- }
+ if (std::holds_alternative<UsageWarning>(it->second)) {
+ EnableWarning(std::get<UsageWarning>(it->second), !negated);
+ return true;
}
}
- return std::nullopt;
+ return false;
}
-std::optional<LanguageFeature> FindLanguageFeature(const char *name) {
- return ScanEnum<LanguageFeature, LanguageFeature_enumSize>(name);
+void LanguageFeatureControl::ReplaceCliCanonicalSpelling(
+ LanguageFeature f, std::string input) {
+ std::string_view old{languageFeatureCliCanonicalSpelling_[EnumToInt(f)]};
+ cliOptions_.erase(std::string{old});
----------------
eugeneepshteyn wrote:
Since end up creating `std::string` from `old` anyway, maybe just make `old` to be `std::string` in the first place? This way may avoid creating an extra object.
https://github.com/llvm/llvm-project/pull/142022
More information about the flang-commits
mailing list