Skip to content

Commit c7e09e9

Browse files
author
Shao-Ce SUN
committed
[nfc][flang] Eliminate the dependency on cctype by using characters.h
Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D148076
1 parent 88b7e8e commit c7e09e9

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

flang/include/flang/Parser/characters.h

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ inline constexpr bool IsLegalInIdentifier(char ch) {
5858
return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch);
5959
}
6060

61+
inline constexpr bool IsPrintable(char ch) { return ch >= ' ' && ch <= '~'; }
62+
63+
inline constexpr bool IsWhiteSpace(char ch) {
64+
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\v' || ch == '\f' ||
65+
ch == '\r';
66+
}
67+
6168
inline constexpr char ToLowerCaseLetter(char ch) {
6269
return IsUpperCaseLetter(ch) ? ch - 'A' + 'a' : ch;
6370
}

flang/lib/Parser/token-parsers.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "flang/Parser/characters.h"
2020
#include "flang/Parser/instrumented-parser.h"
2121
#include "flang/Parser/provenance.h"
22-
#include <cctype>
2322
#include <cstddef>
2423
#include <cstring>
2524
#include <functional>
@@ -526,7 +525,7 @@ struct HollerithLiteral {
526525
int chBytes{UTF_8CharacterBytes(state.GetLocation())};
527526
for (int bytes{chBytes}; bytes > 0; --bytes) {
528527
if (std::optional<const char *> at{nextCh.Parse(state)}) {
529-
if (chBytes == 1 && !std::isprint(**at)) {
528+
if (chBytes == 1 && !IsPrintable(**at)) {
530529
state.Say(start, "Bad character in Hollerith"_err_en_US);
531530
return std::nullopt;
532531
}

flang/lib/Semantics/resolve-labels.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "flang/Common/template.h"
1212
#include "flang/Parser/parse-tree-visitor.h"
1313
#include "flang/Semantics/semantics.h"
14-
#include <cctype>
1514
#include <cstdarg>
1615
#include <type_traits>
1716

@@ -926,7 +925,7 @@ parser::CharBlock SkipLabel(const parser::CharBlock &position) {
926925
std::size_t i{1l};
927926
for (; (i < maxPosition) && parser::IsDecimalDigit(position[i]); ++i) {
928927
}
929-
for (; (i < maxPosition) && std::isspace(position[i]); ++i) {
928+
for (; (i < maxPosition) && parser::IsWhiteSpace(position[i]); ++i) {
930929
}
931930
return parser::CharBlock{position.begin() + i, position.end()};
932931
}

0 commit comments

Comments
 (0)