[flang] Address review comments.
authorpeter klausler <pklausler@nvidia.com>
Thu, 19 Apr 2018 20:51:25 +0000 (13:51 -0700)
committerpeter klausler <pklausler@nvidia.com>
Thu, 19 Apr 2018 20:51:25 +0000 (13:51 -0700)
Original-commit: flang-compiler/f18@dbeba373223f97e627063fed17b3f72e2b5c508e
Reviewed-on: https://github.com/flang-compiler/f18/pull/61

flang/lib/parser/char-set.h
flang/lib/parser/characters.h
flang/lib/parser/message.cc
flang/lib/parser/message.h
flang/lib/parser/token-parsers.h

index 10dc57b..7048160 100644 (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 = '?';
index ed0da5c..5511416 100644 (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'};
index 500fbda..64ac585 100644 (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
index da1b97b..7df0048 100644 (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);
     }
   }
index c4c7cd7..ad0a64b 100644 (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_;
 };