[flang] Address review comments.

Original-commit: flang-compiler/f18@dbeba37322
Reviewed-on: https://github.com/flang-compiler/f18/pull/61
This commit is contained in:
peter klausler 2018-04-19 13:51:25 -07:00
parent 0acda77554
commit 086a7f3596
5 changed files with 12 additions and 25 deletions

View file

@ -23,6 +23,7 @@ struct SetOfChars {
// character literals. We repurpose '?' and '^' for newline and unknown
// characters (resp.), leaving the others alone in case this code might
// be useful in preprocssing.
// TODO: EBCDIC?
if (c == '\n') {
// map newline to '?'
c = '?';

View file

@ -4,6 +4,7 @@
// Define some character classification predicates and
// conversions here to avoid dependences upon <cctype> and
// also to accomodate Fortran tokenization.
// TODO: EBCDIC?
#include <cstddef>
#include <optional>
@ -15,26 +16,11 @@ namespace parser {
enum class Encoding { UTF8, EUC_JP };
inline constexpr bool IsUpperCaseLetter(char ch) {
if constexpr ('A' == static_cast<char>(0xc1)) {
// EBCDIC
// TODO: Handle EBCDIC in a more generalized character set
// encoding framework; don't just assume that the native
// C++ character set is the same as that of the Fortran source.
return (ch >= 'A' && ch <= 'I') || (ch >= 'J' && ch <= 'R') ||
(ch >= 'S' && ch <= 'Z');
} else {
return ch >= 'A' && ch <= 'Z';
}
return ch >= 'A' && ch <= 'Z';
}
inline constexpr bool IsLowerCaseLetter(char ch) {
if constexpr ('a' == static_cast<char>(0x81)) {
// EBCDIC
return (ch >= 'a' && ch <= 'i') || (ch >= 'j' && ch <= 'r') ||
(ch >= 's' && ch <= 'z');
} else {
return ch >= 'a' && ch <= 'z';
}
return ch >= 'a' && ch <= 'z';
}
inline constexpr bool IsLetter(char ch) {
@ -82,7 +68,7 @@ inline constexpr char ToUpperCaseLetter(char &&ch) {
return IsLowerCaseLetter(ch) ? ch - 'a' + 'A' : ch;
}
static inline std::string ToUpperCaseLetters(const std::string &str) {
inline std::string ToUpperCaseLetters(const std::string &str) {
std::string raised{str};
for (char &ch : raised) {
ch = ToUpperCaseLetter(ch);
@ -102,7 +88,7 @@ inline constexpr char HexadecimalDigitValue(char ch) {
: IsLowerCaseLetter(ch) ? ch - 'a' + 10 : DecimalDigitValue(ch);
}
constexpr std::optional<char> BackslashEscapeValue(char ch) {
inline constexpr std::optional<char> BackslashEscapeValue(char ch) {
switch (ch) {
// case 'a': return {'\a'}; pgf90 doesn't know about \a
case 'b': return {'\b'};
@ -118,7 +104,7 @@ constexpr std::optional<char> BackslashEscapeValue(char ch) {
}
}
constexpr std::optional<char> BackslashEscapeChar(char ch) {
inline constexpr std::optional<char> BackslashEscapeChar(char ch) {
switch (ch) {
// case '\a': return {'a'}; pgf90 doesn't know about \a
case '\b': return {'b'};

View file

@ -4,6 +4,7 @@
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <string>
namespace Fortran {
namespace parser {
@ -49,8 +50,7 @@ std::string Message::ToString() const {
bool isExpected{isExpected_};
if (string_.empty()) {
if (fixedText_ != nullptr) {
if (fixedBytes_ > 0 &&
fixedBytes_ < std::numeric_limits<std::size_t>::max()) {
if (fixedBytes_ > 0 && fixedBytes_ < std::string::npos) {
s = std::string(fixedText_, fixedBytes_);
} else {
s = std::string{fixedText_}; // NUL-terminated

View file

@ -72,7 +72,7 @@ private:
class MessageExpectedText {
public:
MessageExpectedText(const char *s, std::size_t n) : str_{s}, bytes_{n} {
if (n == std::numeric_limits<std::size_t>::max()) {
if (n == std::string::npos) {
bytes_ = std::strlen(s);
}
}

View file

@ -67,7 +67,7 @@ constexpr struct Space {
// Skips a space that in free form requires a warning if it precedes a
// character that could begin an identifier or keyword. Always succeeds.
static inline void MissingSpace(ParseState *state) {
inline void MissingSpace(ParseState *state) {
if (!state->inFixedForm()) {
state->set_anyConformanceViolation();
if (state->warnOnNonstandardUsage()) {
@ -156,7 +156,7 @@ public:
private:
const char *const str_;
const std::size_t bytes_{std::numeric_limits<std::size_t>::max()};
const std::size_t bytes_{std::string::npos};
const bool mandatoryFreeFormSpace_;
};