[flang-commits] [flang] c7e09e9 - [nfc][flang] Eliminate the dependency on cctype by using characters.h
Shao-Ce SUN via flang-commits
flang-commits at lists.llvm.org
Wed Apr 12 08:56:49 PDT 2023
Author: Shao-Ce SUN
Date: 2023-04-12T23:56:39+08:00
New Revision: c7e09e99abde05a6c2585b30e7b2787a17b2aa9d
URL: https://github.com/llvm/llvm-project/commit/c7e09e99abde05a6c2585b30e7b2787a17b2aa9d
DIFF: https://github.com/llvm/llvm-project/commit/c7e09e99abde05a6c2585b30e7b2787a17b2aa9d.diff
LOG: [nfc][flang] Eliminate the dependency on cctype by using characters.h
Reviewed By: klausler
Differential Revision: https://reviews.llvm.org/D148076
Added:
Modified:
flang/include/flang/Parser/characters.h
flang/lib/Parser/token-parsers.h
flang/lib/Semantics/resolve-labels.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/characters.h b/flang/include/flang/Parser/characters.h
index 239be8d4bf4aa..b3b82a4f0b9f7 100644
--- a/flang/include/flang/Parser/characters.h
+++ b/flang/include/flang/Parser/characters.h
@@ -58,6 +58,13 @@ inline constexpr bool IsLegalInIdentifier(char ch) {
return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch);
}
+inline constexpr bool IsPrintable(char ch) { return ch >= ' ' && ch <= '~'; }
+
+inline constexpr bool IsWhiteSpace(char ch) {
+ return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\v' || ch == '\f' ||
+ ch == '\r';
+}
+
inline constexpr char ToLowerCaseLetter(char ch) {
return IsUpperCaseLetter(ch) ? ch - 'A' + 'a' : ch;
}
diff --git a/flang/lib/Parser/token-parsers.h b/flang/lib/Parser/token-parsers.h
index ff1ba334e73b4..2495017d19649 100644
--- a/flang/lib/Parser/token-parsers.h
+++ b/flang/lib/Parser/token-parsers.h
@@ -19,7 +19,6 @@
#include "flang/Parser/characters.h"
#include "flang/Parser/instrumented-parser.h"
#include "flang/Parser/provenance.h"
-#include <cctype>
#include <cstddef>
#include <cstring>
#include <functional>
@@ -526,7 +525,7 @@ struct HollerithLiteral {
int chBytes{UTF_8CharacterBytes(state.GetLocation())};
for (int bytes{chBytes}; bytes > 0; --bytes) {
if (std::optional<const char *> at{nextCh.Parse(state)}) {
- if (chBytes == 1 && !std::isprint(**at)) {
+ if (chBytes == 1 && !IsPrintable(**at)) {
state.Say(start, "Bad character in Hollerith"_err_en_US);
return std::nullopt;
}
diff --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp
index b53d2c3823583..3a2dd61cab058 100644
--- a/flang/lib/Semantics/resolve-labels.cpp
+++ b/flang/lib/Semantics/resolve-labels.cpp
@@ -11,7 +11,6 @@
#include "flang/Common/template.h"
#include "flang/Parser/parse-tree-visitor.h"
#include "flang/Semantics/semantics.h"
-#include <cctype>
#include <cstdarg>
#include <type_traits>
@@ -926,7 +925,7 @@ parser::CharBlock SkipLabel(const parser::CharBlock &position) {
std::size_t i{1l};
for (; (i < maxPosition) && parser::IsDecimalDigit(position[i]); ++i) {
}
- for (; (i < maxPosition) && std::isspace(position[i]); ++i) {
+ for (; (i < maxPosition) && parser::IsWhiteSpace(position[i]); ++i) {
}
return parser::CharBlock{position.begin() + i, position.end()};
}
More information about the flang-commits
mailing list