Skip to content

Commit

Permalink
[nfc][flang] Eliminate the dependency on cctype by using characters.h
Browse files Browse the repository at this point in the history
Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D148076
  • Loading branch information
Shao-Ce SUN committed Apr 12, 2023
1 parent 88b7e8e commit c7e09e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 7 additions & 0 deletions flang/include/flang/Parser/characters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Parser/token-parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Semantics/resolve-labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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()};
}
Expand Down

0 comments on commit c7e09e9

Please sign in to comment.